1 use coarsetime::Instant;
2 use prometheus::{Histogram, IntCounter, IntGauge};
3 use std::sync::Arc;
4 
5 pub struct StartInstant(pub Instant);
6 
7 pub struct Inner {
8     pub start_instant: StartInstant,
9     pub uptime: IntGauge,
10     pub anonymized_queries: IntCounter,
11     pub anonymized_responses: IntCounter,
12     pub client_queries: IntGauge,
13     pub client_queries_udp: IntCounter,
14     pub client_queries_tcp: IntCounter,
15     pub client_queries_cached: IntCounter,
16     pub client_queries_expired: IntCounter,
17     pub client_queries_offline: IntCounter,
18     pub client_queries_errors: IntCounter,
19     pub client_queries_blocked: IntCounter,
20     pub client_queries_resolved: IntCounter,
21     pub client_queries_rcode_nxdomain: IntCounter,
22     pub inflight_udp_queries: IntGauge,
23     pub inflight_tcp_queries: IntGauge,
24     pub upstream_errors: IntCounter,
25     pub upstream_sent: IntCounter,
26     pub upstream_received: IntCounter,
27     pub upstream_response_sizes: Histogram,
28     pub upstream_rcode_nxdomain: IntCounter,
29 }
30 
31 pub type Varz = Arc<Inner>;
32 
new() -> Varz33 pub fn new() -> Varz {
34     Arc::new(Inner::new())
35 }
36 
37 impl Inner {
new() -> Inner38     pub fn new() -> Inner {
39         Inner {
40             start_instant: StartInstant::default(),
41             uptime: register_int_gauge!(opts!(
42                 "encrypted_dns_uptime",
43                 "Uptime",
44                 labels! {"handler" => "all",}
45             ))
46             .unwrap(),
47             anonymized_queries: register_int_counter!(opts!(
48                 "encrypted_dns_anonymized_queries",
49                 "Number of anonymized queries received",
50                 labels! {"handler" => "all",}
51             ))
52             .unwrap(),
53             anonymized_responses: register_int_counter!(opts!(
54                 "encrypted_dns_anonymized_responses",
55                 "Number of anonymized responses received",
56                 labels! {"handler" => "all",}
57             ))
58             .unwrap(),
59             client_queries: register_int_gauge!(opts!(
60                 "encrypted_dns_client_queries",
61                 "Number of client queries received",
62                 labels! {"handler" => "all",}
63             ))
64             .unwrap(),
65             client_queries_udp: register_int_counter!(opts!(
66                 "encrypted_dns_client_queries_udp",
67                 "Number of client queries received \
68                  using UDP",
69                 labels! {"handler" => "all",}
70             ))
71             .unwrap(),
72             client_queries_tcp: register_int_counter!(opts!(
73                 "encrypted_dns_client_queries_tcp",
74                 "Number of client queries received \
75                  using TCP",
76                 labels! {"handler" => "all",}
77             ))
78             .unwrap(),
79             client_queries_cached: register_int_counter!(opts!(
80                 "encrypted_dns_client_queries_cached",
81                 "Number of client queries sent from \
82                  the cache",
83                 labels! {"handler" => "all",}
84             ))
85             .unwrap(),
86             client_queries_expired: register_int_counter!(opts!(
87                 "encrypted_dns_client_queries_expired",
88                 "Number of expired client queries",
89                 labels! {"handler" => "all",}
90             ))
91             .unwrap(),
92             client_queries_offline: register_int_counter!(opts!(
93                 "encrypted_dns_client_queries_offline",
94                 "Number of client queries answered \
95                  while upstream resolvers are \
96                  unresponsive",
97                 labels! {"handler" => "all",}
98             ))
99             .unwrap(),
100             client_queries_errors: register_int_counter!(opts!(
101                 "encrypted_dns_client_queries_errors",
102                 "Number of bogus client queries",
103                 labels! {"handler" => "all",}
104             ))
105             .unwrap(),
106             client_queries_blocked: register_int_counter!(opts!(
107                 "encrypted_dns_client_queries_blocked",
108                 "Number of blocked client queries",
109                 labels! {"handler" => "all",}
110             ))
111             .unwrap(),
112             client_queries_resolved: register_int_counter!(opts!(
113                 "encrypted_dns_client_queries_resolved",
114                 "Number of blocked client resolved",
115                 labels! {"handler" => "all",}
116             ))
117             .unwrap(),
118             client_queries_rcode_nxdomain: register_int_counter!(opts!(
119                 "encrypted_dns_client_queries_rcode_nxdomain",
120                 "Number of responses with an NXDOMAIN error code",
121                 labels! {"handler" => "all",}
122             ))
123             .unwrap(),
124             inflight_udp_queries: register_int_gauge!(opts!(
125                 "encrypted_dns_inflight_udp_queries",
126                 "Number of UDP queries currently waiting for a response",
127                 labels! {"handler" => "all",}
128             ))
129             .unwrap(),
130             inflight_tcp_queries: register_int_gauge!(opts!(
131                 "encrypted_dns_inflight_tcp_queries",
132                 "Number of TCP queries currently waiting for a response",
133                 labels! {"handler" => "all",}
134             ))
135             .unwrap(),
136             upstream_errors: register_int_counter!(opts!(
137                 "encrypted_dns_upstream_errors",
138                 "Number of bogus upstream servers responses",
139                 labels! {"handler" => "all",}
140             ))
141             .unwrap(),
142             upstream_sent: register_int_counter!(opts!(
143                 "encrypted_dns_upstream_sent",
144                 "Number of upstream servers queries sent",
145                 labels! {"handler" => "all",}
146             ))
147             .unwrap(),
148             upstream_received: register_int_counter!(opts!(
149                 "encrypted_dns_upstream_received",
150                 "Number of upstream servers responses received",
151                 labels! {"handler" => "all",}
152             ))
153             .unwrap(),
154             upstream_response_sizes: register_histogram!(histogram_opts!(
155                 "encrypted_dns_upstream_response_sizes",
156                 "Response size in bytes",
157                 vec![64.0, 128.0, 192.0, 256.0, 512.0, 1024.0, 2048.0]
158             ))
159             .unwrap(),
160             upstream_rcode_nxdomain: register_int_counter!(opts!(
161                 "encrypted_dns_upstream_rcode_nxdomain",
162                 "Number of upstream responses with an NXDOMAIN error code",
163                 labels! {"handler" => "all",}
164             ))
165             .unwrap(),
166         }
167     }
168 }
169 
170 impl Default for Inner {
default() -> Self171     fn default() -> Self {
172         Self::new()
173     }
174 }
175 
176 impl Default for StartInstant {
default() -> StartInstant177     fn default() -> StartInstant {
178         StartInstant(Instant::now())
179     }
180 }
181