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