1 /* 2 * metrics.h -- prometheus metrics endpoint 3 * 4 * Copyright (c) 2001-2025, NLnet Labs. All rights reserved. 5 * 6 * See LICENSE for the license. 7 * 8 */ 9 10 #ifndef DAEMON_METRICS_H 11 #define DAEMON_METRICS_H 12 13 struct xfrd_state; 14 struct nsd_options; 15 struct daemon_metrics; 16 struct evbuffer; 17 18 #ifdef BIND8_STATS 19 struct nsdst; 20 #endif /* BIND8_STATS */ 21 22 /* the metrics daemon needs little backlog */ 23 #define TCP_BACKLOG_METRICS 16 /* listen() tcp backlog */ 24 25 /** 26 * Create new metrics endpoint for the daemon. 27 * @param cfg: config. 28 * @return new state, or NULL on failure. 29 */ 30 struct daemon_metrics* daemon_metrics_create(struct nsd_options* cfg); 31 32 /** 33 * Delete metrics daemon and close HTTP listeners. 34 * @param m: daemon to delete. 35 */ 36 void daemon_metrics_delete(struct daemon_metrics* m); 37 38 /** 39 * Close metrics HTTP listener ports. 40 * Does not delete the object itself. 41 * @param m: state to close. 42 */ 43 void daemon_metrics_close(struct daemon_metrics* m); 44 45 /** 46 * Open and create HTTP listeners for metrics daemon. 47 * @param m: metrics state that contains list of accept sockets. 48 * @param cfg: config options. 49 * @return false on failure. 50 */ 51 int daemon_metrics_open_ports(struct daemon_metrics* m, 52 struct nsd_options* cfg); 53 54 /** 55 * Setup HTTP listener. 56 * @param m: state 57 * @param xfrd: the process that hosts the daemon. 58 * m's HTTP listener is attached to its event base. 59 */ 60 void daemon_metrics_attach(struct daemon_metrics* m, struct xfrd_state* xfrd); 61 62 #ifdef BIND8_STATS 63 /** 64 * Print stats as prometheus metrics to HTTP buffer 65 * @param buf: the HTTP buffer to write to 66 * @param xfrd: the process that hosts the daemon. 67 * @param now: current time 68 * @param clear: whether to reset the stats time 69 * @param st: the stats 70 * @param zonestats: the zonestats 71 * @param rc_stats_time: pointer to the remote-control stats_time member 72 * to correctly print the elapsed time since last stats reset 73 */ 74 void metrics_print_stats(struct evbuffer *buf, struct xfrd_state *xfrd, 75 struct timeval *now, int clear, struct nsdst *st, 76 struct nsdst **zonestats, 77 struct timeval *rc_stats_time); 78 79 #ifdef USE_ZONE_STATS 80 /** 81 * Print zonestat metrics for a single zonestats object 82 * @param buf: the HTTP buffer to write to 83 * @param name: the zonestats name 84 * @param zst: the stats to print 85 */ 86 void metrics_zonestat_print_one(struct evbuffer *buf, char *name, 87 struct nsdst *zst); 88 #endif /* USE_ZONE_STATS */ 89 90 #endif /*BIND8_STATS*/ 91 92 #endif /* DAEMON_METRICS_H */ 93