xref: /openbsd-src/usr.sbin/unbound/daemon/stats.h (revision 8b7325af55f9372784d083aa385d31c4cebf9890)
1933707f3Ssthen /*
2933707f3Ssthen  * daemon/stats.h - collect runtime performance indicators.
3933707f3Ssthen  *
4933707f3Ssthen  * Copyright (c) 2007, NLnet Labs. All rights reserved.
5933707f3Ssthen  *
6933707f3Ssthen  * This software is open source.
7933707f3Ssthen  *
8933707f3Ssthen  * Redistribution and use in source and binary forms, with or without
9933707f3Ssthen  * modification, are permitted provided that the following conditions
10933707f3Ssthen  * are met:
11933707f3Ssthen  *
12933707f3Ssthen  * Redistributions of source code must retain the above copyright notice,
13933707f3Ssthen  * this list of conditions and the following disclaimer.
14933707f3Ssthen  *
15933707f3Ssthen  * Redistributions in binary form must reproduce the above copyright notice,
16933707f3Ssthen  * this list of conditions and the following disclaimer in the documentation
17933707f3Ssthen  * and/or other materials provided with the distribution.
18933707f3Ssthen  *
19933707f3Ssthen  * Neither the name of the NLNET LABS nor the names of its contributors may
20933707f3Ssthen  * be used to endorse or promote products derived from this software without
21933707f3Ssthen  * specific prior written permission.
22933707f3Ssthen  *
23933707f3Ssthen  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
245d76a658Ssthen  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
255d76a658Ssthen  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
265d76a658Ssthen  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
275d76a658Ssthen  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
285d76a658Ssthen  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
295d76a658Ssthen  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
305d76a658Ssthen  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
315d76a658Ssthen  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
325d76a658Ssthen  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
335d76a658Ssthen  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34933707f3Ssthen  */
35933707f3Ssthen 
36933707f3Ssthen /**
37933707f3Ssthen  * \file
38933707f3Ssthen  *
39933707f3Ssthen  * This file describes the data structure used to collect runtime performance
40933707f3Ssthen  * numbers. These 'statistics' may be of interest to the operator.
41933707f3Ssthen  */
42933707f3Ssthen 
43933707f3Ssthen #ifndef DAEMON_STATS_H
44933707f3Ssthen #define DAEMON_STATS_H
45933707f3Ssthen #include "util/timehist.h"
46933707f3Ssthen struct worker;
47933707f3Ssthen struct config_file;
48933707f3Ssthen struct comm_point;
49933707f3Ssthen struct comm_reply;
50933707f3Ssthen struct edns_data;
515d76a658Ssthen struct sldns_buffer;
52933707f3Ssthen 
532be9e038Ssthen /* stats struct */
542be9e038Ssthen #include "libunbound/unbound.h"
55933707f3Ssthen 
56933707f3Ssthen /**
57933707f3Ssthen  * Initialize server stats to 0.
58933707f3Ssthen  * @param stats: what to init (this is alloced by the caller).
59933707f3Ssthen  * @param cfg: with extended statistics option.
60933707f3Ssthen  */
612be9e038Ssthen void server_stats_init(struct ub_server_stats* stats, struct config_file* cfg);
62933707f3Ssthen 
63933707f3Ssthen /** add query if it missed the cache */
642be9e038Ssthen void server_stats_querymiss(struct ub_server_stats* stats, struct worker* worker);
65933707f3Ssthen 
66933707f3Ssthen /** add query if was cached and also resulted in a prefetch */
672be9e038Ssthen void server_stats_prefetch(struct ub_server_stats* stats, struct worker* worker);
68933707f3Ssthen 
69933707f3Ssthen /** display the stats to the log */
702be9e038Ssthen void server_stats_log(struct ub_server_stats* stats, struct worker* worker,
71933707f3Ssthen 	int threadnum);
72933707f3Ssthen 
73933707f3Ssthen /**
74933707f3Ssthen  * Obtain the stats info for a given thread. Uses pipe to communicate.
75933707f3Ssthen  * @param worker: the worker that is executing (the first worker).
76933707f3Ssthen  * @param who: on who to get the statistics info.
77933707f3Ssthen  * @param s: the stats block to fill in.
78933707f3Ssthen  * @param reset: if stats can be reset.
79933707f3Ssthen  */
80933707f3Ssthen void server_stats_obtain(struct worker* worker, struct worker* who,
812be9e038Ssthen 	struct ub_stats_info* s, int reset);
82933707f3Ssthen 
83933707f3Ssthen /**
84933707f3Ssthen  * Compile stats into structure for this thread worker.
85933707f3Ssthen  * Also clears the statistics counters (if that is set by config file).
86933707f3Ssthen  * @param worker: the worker to compile stats for, also the executing worker.
87933707f3Ssthen  * @param s: stats block.
88933707f3Ssthen  * @param reset: if true, depending on config stats are reset.
89933707f3Ssthen  * 	if false, statistics are not reset.
90933707f3Ssthen  */
912be9e038Ssthen void server_stats_compile(struct worker* worker, struct ub_stats_info* s,
92933707f3Ssthen 	int reset);
93933707f3Ssthen 
94933707f3Ssthen /**
95933707f3Ssthen  * Send stats over comm tube in reply to query cmd
96933707f3Ssthen  * @param worker: this worker.
97933707f3Ssthen  * @param reset: if true, depending on config stats are reset.
98933707f3Ssthen  * 	if false, statistics are not reset.
99933707f3Ssthen  */
100933707f3Ssthen void server_stats_reply(struct worker* worker, int reset);
101933707f3Ssthen 
102933707f3Ssthen /**
103933707f3Ssthen  * Addup stat blocks.
104933707f3Ssthen  * @param total: sum of the two entries.
105933707f3Ssthen  * @param a: to add to it.
106933707f3Ssthen  */
1072be9e038Ssthen void server_stats_add(struct ub_stats_info* total, struct ub_stats_info* a);
108933707f3Ssthen 
109933707f3Ssthen /**
110933707f3Ssthen  * Add stats for this query
111933707f3Ssthen  * @param stats: the stats
112933707f3Ssthen  * @param c: commpoint with type and buffer.
113933707f3Ssthen  * @param qtype: query type
114933707f3Ssthen  * @param qclass: query class
115933707f3Ssthen  * @param edns: edns record
116933707f3Ssthen  * @param repinfo: reply info with remote address
117933707f3Ssthen  */
1182be9e038Ssthen void server_stats_insquery(struct ub_server_stats* stats, struct comm_point* c,
119933707f3Ssthen 	uint16_t qtype, uint16_t qclass, struct edns_data* edns,
120933707f3Ssthen 	struct comm_reply* repinfo);
121933707f3Ssthen 
122933707f3Ssthen /**
123933707f3Ssthen  * Add rcode for this query.
124933707f3Ssthen  * @param stats: the stats
125933707f3Ssthen  * @param buf: buffer with rcode. If buffer is length0: not counted.
126933707f3Ssthen  */
1272be9e038Ssthen void server_stats_insrcode(struct ub_server_stats* stats, struct sldns_buffer* buf);
128933707f3Ssthen 
129*8b7325afSsthen /**
130*8b7325afSsthen  * Add DNS Cookie stats for this query
131*8b7325afSsthen  * @param stats: the stats
132*8b7325afSsthen  * @param edns: edns record
133*8b7325afSsthen  */
134*8b7325afSsthen void server_stats_downstream_cookie(struct ub_server_stats* stats,
135*8b7325afSsthen 	struct edns_data* edns);
136933707f3Ssthen #endif /* DAEMON_STATS_H */
137