Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prometheus metrics #429

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ chrootdir= @chrootdir@
user = @user@
DNSTAP_SRC=@DNSTAP_SRC@
DNSTAP_OBJ=@DNSTAP_OBJ@
METRICS_SRC=@METRICS_SRC@
METRICS_OBJ=@METRICS_OBJ@

# override $U variable which is used by autotools for deansification (for
# K&R C compilers), but causes problems if $U is defined in the env).
Expand Down Expand Up @@ -88,7 +90,7 @@ TARGETS=nsd nsd-checkconf nsd-checkzone nsd-control nsd.conf.sample nsd-control-
MANUALS=nsd.8 nsd-checkconf.8 nsd-checkzone.8 nsd-control.8 nsd.conf.5

COMMON_OBJ=answer.o axfr.o ixfr.o ixfrcreate.o buffer.o configlexer.o configparser.o dname.o dns.o edns.o iterated_hash.o lookup3.o namedb.o nsec3.o options.o packet.o query.o rbtree.o radtree.o rdata.o region-allocator.o rrl.o siphash.o tsig.o tsig-openssl.o udb.o util.o bitset.o popen3.o proxy_protocol.o
XFRD_OBJ=xfrd-catalog-zones.o xfrd-disk.o xfrd-notify.o xfrd-tcp.o xfrd.o remote.o $(DNSTAP_OBJ)
XFRD_OBJ=xfrd-catalog-zones.o xfrd-disk.o xfrd-notify.o xfrd-tcp.o xfrd.o remote.o $(METRICS_OBJ) $(DNSTAP_OBJ)
NSD_OBJ=$(COMMON_OBJ) $(XFRD_OBJ) difffile.o ipc.o mini_event.o netio.o nsd.o server.o dbaccess.o dbcreate.o zonec.o verify.o
ALL_OBJ=$(NSD_OBJ) nsd-checkconf.o nsd-checkzone.o nsd-control.o nsd-mem.o xfr-inspect.o
NSD_CHECKCONF_OBJ=$(COMMON_OBJ) nsd-checkconf.o
Expand Down Expand Up @@ -408,6 +410,7 @@ configparser.o: configparser.c config.h configparser.h
options.o: $(srcdir)/options.c config.h configparser.h
dns.o: $(srcdir)/dns.c config.h
zonec.o: $(srcdir)/zonec.c config.h
metrics.o: $(srcdir)/metrics.c config.h

# dnstap
dnstap.o: $(srcdir)/dnstap/dnstap.c config.h dnstap/dnstap_config.h \
Expand Down
4 changes: 4 additions & 0 deletions configlexer.lex
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ server-key-file{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_SERVER_KEY_FILE;
server-cert-file{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_SERVER_CERT_FILE;}
control-key-file{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_CONTROL_KEY_FILE;}
control-cert-file{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_CONTROL_CERT_FILE;}
metrics-enable{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_METRICS_ENABLE;}
metrics-interface{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_METRICS_INTERFACE;}
metrics-port{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_METRICS_PORT;}
metrics-path{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_METRICS_PATH;}
AXFR { LEXOUT(("v(%s) ", yytext)); return VAR_AXFR;}
UDP { LEXOUT(("v(%s) ", yytext)); return VAR_UDP;}
rrl-size{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_RRL_SIZE;}
Expand Down
38 changes: 38 additions & 0 deletions configparser.y
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ struct component {
%token VAR_DROP_UPDATES
%token VAR_XFRD_TCP_MAX
%token VAR_XFRD_TCP_PIPELINE
%token VAR_METRICS_ENABLE
%token VAR_METRICS_INTERFACE
%token VAR_METRICS_PORT
%token VAR_METRICS_PATH

/* dnstap */
%token VAR_DNSTAP
Expand Down Expand Up @@ -588,6 +592,40 @@ server_option:
}
}
}
| VAR_METRICS_ENABLE boolean
{
#ifdef USE_METRICS
cfg_parser->opt->metrics_enable = $2;
#endif /* USE_METRICS */
}
| VAR_METRICS_INTERFACE ip_address
{
#ifdef USE_METRICS
struct ip_address_option *ip = cfg_parser->opt->metrics_interface;
if(ip == NULL) {
cfg_parser->opt->metrics_interface = $2;
} else {
while(ip->next != NULL) { ip = ip->next; }
ip->next = $2;
}
#endif /* USE_METRICS */
}
| VAR_METRICS_PORT number
{
#ifdef USE_METRICS
if($2 == 0) {
yyerror("metrics port number expected");
} else {
cfg_parser->opt->metrics_port = (int)$2;
}
#endif /* USE_METRICS */
}
| VAR_METRICS_PATH STRING
{
#ifdef USE_METRICS
cfg_parser->opt->metrics_path = region_strdup(cfg_parser->opt->region, $2);
#endif /* USE_METRICS */
}
;

socket_options:
Expand Down
13 changes: 13 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,19 @@ case "$enable_packed" in
;;
esac

AC_ARG_ENABLE(prometheus-metrics, AS_HELP_STRING([--enable-prometheus-metrics],[Enable prometheus metrics support.]))
case "$enable_prometheus_metrics" in
yes)
AC_DEFINE_UNQUOTED([USE_METRICS], [], [Define this to expose NSD statistics via a prometheus metrics HTTP endpoint.])
AC_DEFINE_UNQUOTED([NSD_METRICS_PORT], [9100], [Define to the default metrics HTTP endpoint port.])
AC_SEARCH_LIBS(evhttp_free, [event], , AC_MSG_ERROR(Cannot find libevent, but is needed for prometheus metrics support.))
AC_SUBST([METRICS_SRC], ["metrics.c"])
AC_SUBST([METRICS_OBJ], ["metrics.o"])
;;
no|*)
;;
esac

# check for dnstap if requested
dt_DNSTAP([${localstatedir}/run/nsd-dnstap.sock],
[
Expand Down
Loading