Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
90c2ca4
- add-prometheus-metrics, adjust configure.ac, Makefile.in and add
wcawijngaards Jan 30, 2026
ece48de
- add-prometheus-metrics, add metrics-enable, metrics-interface, metr…
wcawijngaards Jan 30, 2026
705d180
- add-prometheus-metrics, respect stat-cumulative option, print num q…
wcawijngaards Feb 3, 2026
a00cac5
- add-prometheus-metrics, testbound implementation, and if metrics ar…
wcawijngaards Feb 3, 2026
831a805
Merge branch 'master' into add-prometheus-metrics
wcawijngaards Feb 3, 2026
747ce6b
- add-prometheus-metrics, print per-thread stats and the summed totals.
wcawijngaards Feb 6, 2026
6468917
Merge branch 'master' into add-prometheus-metrics
wcawijngaards Feb 6, 2026
19751ec
- add-prometheus-metrics, fix testbound link for metrics functions.
wcawijngaards Feb 6, 2026
415a83e
- add-prometheus-metrics, print memory usage stats.
wcawijngaards Feb 27, 2026
35e3dcb
- add-prometheus-metrics, print histogram of reply time stats.
wcawijngaards Feb 27, 2026
d3902c0
Merge branch 'master' into add-prometheus-metrics
wcawijngaards Feb 27, 2026
2c5e96f
- add-prometheus-metrics, print extended statistics.
wcawijngaards Mar 3, 2026
172e4a9
Merge branch 'master' into add-prometheus-metrics
wcawijngaards Mar 3, 2026
b0b8a3f
- add-prometheus-metrics, fix by rcode text.
wcawijngaards Mar 3, 2026
efc0c1e
- add-prometheus-metrics, implement further test checks.
wcawijngaards Mar 3, 2026
0b42d5b
Merge branch 'master' into add-prometheus-metrics
wcawijngaards Mar 3, 2026
b96d80a
- add-prometheus-metrics, consolidate mem stats.
wcawijngaards Mar 4, 2026
1f6e67e
Merge branch 'master' into add-prometheus-metrics
wcawijngaards Mar 4, 2026
86d4414
- add-prometheus-metrics, allow interface names, and ip@port notation.
wcawijngaards Mar 27, 2026
08e4560
Merge branch 'master' into add-prometheus-metrics
wcawijngaards Mar 27, 2026
9a01a32
- add-prometheus-metrics, fix clang analyzer warning about allocation…
wcawijngaards Mar 27, 2026
53724c9
Merge branch 'master' into add-prometheus-metrics
wcawijngaards Mar 30, 2026
2864943
- add-prometheus-metrics, fix shm stats to also use the mem info func…
wcawijngaards Mar 30, 2026
b2590c2
- add-prometheus-metrics, set metrics to type 'counter', for number o…
wcawijngaards Apr 2, 2026
c66c86e
- add-prometheus-metrics, fix unit test.
wcawijngaards Apr 2, 2026
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: 3 additions & 2 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ unittcpreuse.lo unitdoq.lo unitinfra.lo
UNITTEST_OBJ_LINK=$(UNITTEST_OBJ) worker_cb.lo $(COMMON_OBJ) $(SLDNS_OBJ) \
$(COMPAT_OBJ)
DAEMON_SRC=daemon/acl_list.c daemon/cachedump.c daemon/daemon.c \
daemon/remote.c daemon/stats.c daemon/unbound.c daemon/worker.c @WIN_DAEMON_SRC@
daemon/remote.c daemon/stats.c daemon/metrics.c daemon/unbound.c daemon/worker.c @WIN_DAEMON_SRC@
DAEMON_OBJ=acl_list.lo cachedump.lo daemon.lo \
shm_main.lo remote.lo stats.lo unbound.lo \
shm_main.lo remote.lo stats.lo metrics.lo unbound.lo \
worker.lo @WIN_DAEMON_OBJ@
DAEMON_OBJ_LINK=$(DAEMON_OBJ) $(COMMON_OBJ_ALL_SYMBOLS) $(SLDNS_OBJ) \
$(COMPAT_OBJ) @WIN_DAEMON_OBJ_LINK@
Expand Down Expand Up @@ -721,6 +721,7 @@ depend:
ipset.lo ipset.o: $(srcdir)/ipset/ipset.c
doqclient.lo doqclient.o: $(srcdir)/testcode/doqclient.c
unitdoq.lo unitdoq.o: $(srcdir)/testcode/unitdoq.c
metrics.lo metrics.o: $(srcdir)/daemon/metrics.c

# Dependencies
dns.lo dns.o: $(srcdir)/services/cache/dns.c config.h $(srcdir)/iterator/iter_delegpt.h $(srcdir)/util/log.h \
Expand Down
10 changes: 10 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@
/* Define to 1 if you have the <event.h> header file. */
#undef HAVE_EVENT_H

/* Define to 1 if you have the `evhttp_free' function. */
#undef HAVE_EVHTTP_FREE

/* Define to 1 if you have the `EVP_aes_256_cbc' function. */
#undef HAVE_EVP_AES_256_CBC

Expand Down Expand Up @@ -986,6 +989,9 @@
/* define this to enable debug checks. */
#undef UNBOUND_DEBUG

/* Define the default metrics HTTP endpoint port. */
#undef UNBOUND_METRICS_PORT

/* Define to 1 to use cachedb support */
#undef USE_CACHEDB

Expand Down Expand Up @@ -1033,6 +1039,10 @@
distributions) the use of non-ephemeral ports. */
#undef USE_LINUX_IP_LOCAL_PORT_RANGE

/* Define this to expose Unbound statistics via a prometheus metrics HTTP
endpoint. */
#undef USE_METRICS

/* Define if you want to use internal select based events */
#undef USE_MINI_EVENT

Expand Down
27 changes: 27 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -22169,6 +22169,31 @@ else $as_nop
fi
printf "%s\n" "#define HAVE_DECL_EVSIGNAL_ASSIGN $ac_have_decl" >>confdefs.h

# prometheus metrics depend on libevent 2.0 and later, and is therefore
# only enabled when the required version is found and used

for ac_func in evhttp_free
do :
ac_fn_c_check_func "$LINENO" "evhttp_free" "ac_cv_func_evhttp_free"
if test "x$ac_cv_func_evhttp_free" = xyes
then :
printf "%s\n" "#define HAVE_EVHTTP_FREE 1" >>confdefs.h


printf "%s\n" "#define USE_METRICS /**/" >>confdefs.h


printf "%s\n" "#define UNBOUND_METRICS_PORT 9101" >>confdefs.h


else $as_nop

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: disabling prometheus metrics" >&5
printf "%s\n" "$as_me: disabling prometheus metrics" >&6;}

fi

done
PC_LIBEVENT_DEPENDENCY="libevent"

if test -n "$BAK_LDFLAGS_SET"; then
Expand All @@ -22178,6 +22203,8 @@ else

printf "%s\n" "#define USE_MINI_EVENT 1" >>confdefs.h

{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: Prometheus metrics are disabled with the builtin libevent alternative" >&5
printf "%s\n" "$as_me: Prometheus metrics are disabled with the builtin libevent alternative" >&6;}
fi

# check for libexpat
Expand Down
9 changes: 9 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1498,13 +1498,22 @@ large outgoing port ranges. ])
# include "event2/event.h"
#endif
])
# prometheus metrics depend on libevent 2.0 and later, and is therefore
# only enabled when the required version is found and used
AC_CHECK_FUNCS([evhttp_free], [
AC_DEFINE_UNQUOTED([USE_METRICS], [], [Define this to expose Unbound statistics via a prometheus metrics HTTP endpoint.])
AC_DEFINE_UNQUOTED([UNBOUND_METRICS_PORT], [9101], [Define the default metrics HTTP endpoint port.])
], [
AC_MSG_NOTICE([disabling prometheus metrics])
])
PC_LIBEVENT_DEPENDENCY="libevent"
AC_SUBST(PC_LIBEVENT_DEPENDENCY)
if test -n "$BAK_LDFLAGS_SET"; then
LDFLAGS="$BAK_LDFLAGS"
fi
else
AC_DEFINE(USE_MINI_EVENT, 1, [Define if you want to use internal select based events])
AC_MSG_NOTICE([Prometheus metrics are disabled with the builtin libevent alternative])
fi

# check for libexpat
Expand Down
16 changes: 8 additions & 8 deletions contrib/metrics.awk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# and output prometheus metrics style output.
# use these options:
# server: extended-statistics: yes
# statistics-cumulative: no
# statistics-cumulative: yes
# statistics-interval: 0
# remote-control: control-enable: yes
# Can use it like unbound-control stats | awk -f "metrics.awk"
Expand All @@ -17,7 +17,7 @@ BEGIN {
# print the output metrics
END {
print "# HELP unbound_hits_queries Unbound DNS traffic and cache hits"
print "# TYPE unbound_hits_queries gauge"
print "# TYPE unbound_hits_queries counter"
print "unbound_hits_queries{type=\"total.num.queries\"} " val["total.num.queries"];
for (x=0; x<99; x++) {
if(val["thread" $x ".num.queries"] != "") {
Expand Down Expand Up @@ -70,7 +70,7 @@ END {
print ""

print "# HELP unbound_by_type_queries Unbound DNS queries by type"
print "# TYPE unbound_by_type_queries gauge"
print "# TYPE unbound_by_type_queries counter"
for(x in val) {
if(x ~ /^num.query.type./) {
if(val[x] != "") {
Expand All @@ -82,7 +82,7 @@ END {
print ""

print "# HELP unbound_by_class_queries Unbound DNS queries by class"
print "# TYPE unbound_by_class_queries gauge"
print "# TYPE unbound_by_class_queries counter"
for(x in val) {
if(x ~ /^num.query.class./) {
if(val[x] != "") {
Expand All @@ -94,7 +94,7 @@ END {
print ""

print "# HELP unbound_by_opcode_queries Unbound DNS queries by opcode"
print "# TYPE unbound_by_opcode_queries gauge"
print "# TYPE unbound_by_opcode_queries counter"
for(x in val) {
if(x ~ /^num.query.opcode./) {
if(val[x] != "") {
Expand All @@ -106,7 +106,7 @@ END {
print ""

print "# HELP unbound_by_rcode_queries Unbound DNS answers by rcode"
print "# TYPE unbound_by_rcode_queries gauge"
print "# TYPE unbound_by_rcode_queries counter"
for(x in val) {
if(x ~ /^num.answer.rcode./) {
if(val[x] != "") {
Expand All @@ -118,7 +118,7 @@ END {
print ""

print "# HELP unbound_by_flags_queries Unbound DNS queries by flags"
print "# TYPE unbound_by_flags_queries gauge"
print "# TYPE unbound_by_flags_queries counter"
for(x in val) {
if(x ~ /^num.query.flags./) {
if(val[x] != "") {
Expand All @@ -136,7 +136,7 @@ END {
print ""

print "# HELP unbound_histogram_seconds Unbound DNS histogram of reply time"
print "# TYPE unbound_histogram_seconds gauge"
print "# TYPE unbound_histogram_seconds counter"
print "unbound_histogram_seconds{bucket=\"000000.000000.to.000000.000001\"} " val["histogram.000000.000000.to.000000.000001"];
print "unbound_histogram_seconds{bucket=\"000000.000001.to.000000.000002\"} " val["histogram.000000.000001.to.000000.000002"];
print "unbound_histogram_seconds{bucket=\"000000.000002.to.000000.000004\"} " val["histogram.000000.000002.to.000000.000004"];
Expand Down
38 changes: 38 additions & 0 deletions daemon/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#include "daemon/daemon.h"
#include "daemon/worker.h"
#include "daemon/remote.h"
#include "daemon/metrics.h"
#include "daemon/acl_list.h"
#include "util/log.h"
#include "util/config_file.h"
Expand Down Expand Up @@ -547,10 +548,25 @@ daemon_init(void)
if(gettimeofday(&daemon->time_boot, NULL) < 0)
log_err("gettimeofday: %s", strerror(errno));
daemon->time_last_stat = daemon->time_boot;
#ifdef USE_METRICS
if(!(daemon->metrics = daemon_metrics_create())) {
acl_list_delete(daemon->acl_interface);
acl_list_delete(daemon->acl);
tcl_list_delete(daemon->tcl);
edns_known_options_delete(daemon->env);
free(daemon->env);
free(daemon);
return NULL;
}
daemon->metrics_port = -1;
#endif /* USE_METRICS */
if((daemon->env->auth_zones = auth_zones_create()) == 0) {
acl_list_delete(daemon->acl_interface);
acl_list_delete(daemon->acl);
tcl_list_delete(daemon->tcl);
#ifdef USE_METRICS
daemon_metrics_delete(daemon->metrics);
#endif
edns_known_options_delete(daemon->env);
free(daemon->env);
free(daemon);
Expand All @@ -561,6 +577,9 @@ daemon_init(void)
acl_list_delete(daemon->acl_interface);
acl_list_delete(daemon->acl);
tcl_list_delete(daemon->tcl);
#ifdef USE_METRICS
daemon_metrics_delete(daemon->metrics);
#endif
edns_known_options_delete(daemon->env);
free(daemon->env);
free(daemon);
Expand Down Expand Up @@ -686,6 +705,19 @@ daemon_open_shared_ports(struct daemon* daemon)
return 0;
daemon->rc_port = daemon->cfg->control_port;
}
#ifdef USE_METRICS
if(!daemon->cfg->metrics_enable && daemon->metrics_port != -1) {
daemon_metrics_close_ports(daemon->metrics);
daemon->metrics_port = -1;
}
if(daemon->cfg->metrics_enable &&
daemon->cfg->metrics_port != daemon->metrics_port) {
daemon_metrics_close_ports(daemon->metrics);
if(!daemon_metrics_open_ports(daemon->metrics, daemon->cfg))
return 0;
daemon->metrics_port = daemon->cfg->metrics_port;
}
#endif /* USE_METRICS */
return 1;
}

Expand Down Expand Up @@ -1171,6 +1203,9 @@ daemon_cleanup(struct daemon* daemon)
auth_zones_cleanup(daemon->env->auth_zones);
/* key cache is cleared by module deinit during next daemon_fork() */
daemon_remote_clear(daemon->rc);
#ifdef USE_METRICS
daemon_metrics_detach(daemon->metrics);
#endif
if(daemon->fast_reload_thread)
fast_reload_thread_stop(daemon->fast_reload_thread);
if(daemon->fast_reload_printq_list)
Expand Down Expand Up @@ -1213,6 +1248,9 @@ daemon_delete(struct daemon* daemon)
modstack_call_destartup(&daemon->mods, daemon->env);
modstack_free(&daemon->mods);
daemon_remote_delete(daemon->rc);
#ifdef USE_METRICS
daemon_metrics_delete(daemon->metrics);
#endif
for(i = 0; i < daemon->num_ports; i++)
listening_ports_free(daemon->ports[i]);
free(daemon->ports);
Expand Down
5 changes: 5 additions & 0 deletions daemon/daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct local_zones;
struct views;
struct ub_randstate;
struct daemon_remote;
struct daemon_metrics;
struct respip_set;
struct shm_main_info;
struct doq_table;
Expand Down Expand Up @@ -99,6 +100,10 @@ struct daemon {
struct listen_port* rc_ports;
/** remote control connections management (for first worker) */
struct daemon_remote* rc;
/** port number for metrics that has ports opened. */
int metrics_port;
/** metrics endpoint connections management (for first worker) */
struct daemon_metrics* metrics;
/** ssl context for listening to dnstcp over ssl */
void* listen_dot_sslctx;
/** ssl context for connecting to dnstcp over ssl */
Expand Down
Loading
Loading