xref: /freebsd/contrib/unbound/daemon/stats.h (revision 5e3934b15a2741b2de6b217e77dc9d798d740804)
1 /*
2  * daemon/stats.h - collect runtime performance indicators.
3  *
4  * Copyright (c) 2007, NLnet Labs. All rights reserved.
5  *
6  * This software is open source.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * Neither the name of the NLNET LABS nor the names of its contributors may
20  * be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 /**
37  * \file
38  *
39  * This file describes the data structure used to collect runtime performance
40  * numbers. These 'statistics' may be of interest to the operator.
41  */
42 
43 #ifndef DAEMON_STATS_H
44 #define DAEMON_STATS_H
45 #include "util/timehist.h"
46 struct worker;
47 struct config_file;
48 struct comm_point;
49 struct comm_reply;
50 struct edns_data;
51 struct sldns_buffer;
52 
53 /* stats struct */
54 #include "libunbound/unbound.h"
55 
56 /**
57  * Initialize server stats to 0.
58  * @param stats: what to init (this is alloced by the caller).
59  * @param cfg: with extended statistics option.
60  */
61 void server_stats_init(struct ub_server_stats* stats, struct config_file* cfg);
62 
63 /** add query if it missed the cache */
64 void server_stats_querymiss(struct ub_server_stats* stats, struct worker* worker);
65 
66 /** add query if was cached and also resulted in a prefetch */
67 void server_stats_prefetch(struct ub_server_stats* stats, struct worker* worker);
68 
69 /** display the stats to the log */
70 void server_stats_log(struct ub_server_stats* stats, struct worker* worker,
71 	int threadnum);
72 
73 /**
74  * Obtain the stats info for a given thread. Uses pipe to communicate.
75  * @param worker: the worker that is executing (the first worker).
76  * @param who: on who to get the statistics info.
77  * @param s: the stats block to fill in.
78  * @param reset: if stats can be reset.
79  */
80 void server_stats_obtain(struct worker* worker, struct worker* who,
81 	struct ub_stats_info* s, int reset);
82 
83 /**
84  * Compile stats into structure for this thread worker.
85  * Also clears the statistics counters (if that is set by config file).
86  * @param worker: the worker to compile stats for, also the executing worker.
87  * @param s: stats block.
88  * @param reset: if true, depending on config stats are reset.
89  * 	if false, statistics are not reset.
90  */
91 void server_stats_compile(struct worker* worker, struct ub_stats_info* s,
92 	int reset);
93 
94 /**
95  * Send stats over comm tube in reply to query cmd
96  * @param worker: this worker.
97  * @param reset: if true, depending on config stats are reset.
98  * 	if false, statistics are not reset.
99  */
100 void server_stats_reply(struct worker* worker, int reset);
101 
102 /**
103  * Addup stat blocks.
104  * @param total: sum of the two entries.
105  * @param a: to add to it.
106  */
107 void server_stats_add(struct ub_stats_info* total, struct ub_stats_info* a);
108 
109 /**
110  * Add stats for this query
111  * @param stats: the stats
112  * @param c: commpoint with type and buffer.
113  * @param qtype: query type
114  * @param qclass: query class
115  * @param edns: edns record
116  * @param repinfo: reply info with remote address
117  */
118 void server_stats_insquery(struct ub_server_stats* stats, struct comm_point* c,
119 	uint16_t qtype, uint16_t qclass, struct edns_data* edns,
120 	struct comm_reply* repinfo);
121 
122 /**
123  * Add rcode for this query.
124  * @param stats: the stats
125  * @param buf: buffer with rcode. If buffer is length0: not counted.
126  */
127 void server_stats_insrcode(struct ub_server_stats* stats, struct sldns_buffer* buf);
128 
129 /**
130  * Add DNS Cookie stats for this query
131  * @param stats: the stats
132  * @param edns: edns record
133  */
134 void server_stats_downstream_cookie(struct ub_server_stats* stats,
135 	struct edns_data* edns);
136 #endif /* DAEMON_STATS_H */
137