1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
|
#
# Copyright (c) 2009-2011 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
use strict;
use warnings;
use PCP::PMDA;
use Time::HiRes qw ( time );
use vars qw( $pmda );
my $pdns_control = 'pdns_control';
my $rec_control = 'rec_control';
my $pdns_disable = 0;
my $rec_disable = 0;
my $cached = 0;
my %vals = ();
my %vals_rec_answers = ();
sub pdns_fetch
{
my $now = time;
if ($now - $cached > 1.0) {
# $pmda->log("pdns_fetch_callback update now:$now cached:$cached\n");
%vals = ();
%vals_rec_answers = ();
# get the authorative server stats
if ($pdns_disable == 0 && open(PIPE, "$pdns_control list |")) {
$_ = <PIPE>;
close PIPE;
$_ =~ s/-/_/g;
$_ =~ s/,$//;
for my $kv (split(/,/, $_)) {
if ("$kv" eq '') {
last;
}
my ($k, $v) = split(/=/, $kv);
$vals{$k} = $v;
}
} else {
$pdns_disable = 1;
}
# get the recursive server stats
if ($rec_disable == 0 && open(PIPE, "$rec_control get-all |")) {
while($_ = <PIPE>) {
$_ =~ s/-/_/g;
my ($k, $v) = split(/\t/, $_);
if ($k eq 'answers0_1') {
$vals_rec_answers{0} = $v;
} elsif ($k eq 'answers1_10') {
$vals_rec_answers{1} = $v;
} elsif ($k eq 'answers10_100') {
$vals_rec_answers{2} = $v;
} elsif ($k eq 'answers100_1000') {
$vals_rec_answers{3} = $v;
} elsif ($k eq 'answers_slow') {
$vals_rec_answers{4} = $v;
} else {
$vals{"recursor.$k"} = $v;
}
}
close PIPE;
} else {
$rec_disable = 1;
}
$cached = $now;
}
}
sub pdns_fetch_callback
{
my ($cluster, $item, $inst) = @_;
my $metric_name = pmda_pmid_name($cluster, $item);
# $pmda->log("pdns_fetch_callback $metric_name $cluster:$item ($inst)\n");
if (!defined($metric_name)) { return (PM_ERR_PMID, 0); }
$metric_name =~ s/^pdns\.//;
if ($metric_name eq 'recursor.answers') {
if ($inst == PM_IN_NULL) { return (PM_ERR_INST, 0); }
return ($vals_rec_answers{$inst}, 1) if (defined($vals_rec_answers{$inst}));
} else {
if ($inst != PM_IN_NULL) { return (PM_ERR_INST, 0); }
return ($vals{$metric_name}, 1) if (defined($vals{$metric_name}));
}
return (PM_ERR_APPVERSION, 0);
}
$pmda = PCP::PMDA->new('pdns', 101);
$pmda->add_metric(pmda_pmid(0,0), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.corrupt_packets", '', '');
$pmda->add_metric(pmda_pmid(0,1), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.deferred_cache_inserts", '', '');
$pmda->add_metric(pmda_pmid(0,2), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.deferred_cache_lookup", '', '');
$pmda->add_metric(pmda_pmid(0,3), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_INSTANT,
pmda_units(0,1,0,0,PM_TIME_USEC,0),
"pdns.latency", '', '');
$pmda->add_metric(pmda_pmid(0,4), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.packetcache_hit", '', '');
$pmda->add_metric(pmda_pmid(0,5), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.packetcache_miss", '', '');
$pmda->add_metric(pmda_pmid(0,6), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_INSTANT,
pmda_units(0,0,0,0,0,0),
"pdns.packetcache_size", '', '');
$pmda->add_metric(pmda_pmid(0,7), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_INSTANT,
pmda_units(0,0,0,0,0,0),
"pdns.qsize_q", '', '');
$pmda->add_metric(pmda_pmid(0,8), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.query_cache_hit", '', '');
$pmda->add_metric(pmda_pmid(0,9), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.query_cache_miss", '', '');
$pmda->add_metric(pmda_pmid(0,10), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursing_answers", '', '');
$pmda->add_metric(pmda_pmid(0,11), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursing_questions", '', '');
$pmda->add_metric(pmda_pmid(0,12), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.servfail_packets", '', '');
$pmda->add_metric(pmda_pmid(0,13), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.tcp_answers", '', '');
$pmda->add_metric(pmda_pmid(0,14), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.tcp_queries", '', '');
$pmda->add_metric(pmda_pmid(0,15), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.timedout_packets", '', '');
$pmda->add_metric(pmda_pmid(0,16), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.udp_answers", '', '');
$pmda->add_metric(pmda_pmid(0,17), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.udp_queries", '', '');
$pmda->add_metric(pmda_pmid(0,18), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.udp4_answers", '', '');
$pmda->add_metric(pmda_pmid(0,19), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.udp4_queries", '', '');
$pmda->add_metric(pmda_pmid(0,20), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.udp6_answers", '', '');
$pmda->add_metric(pmda_pmid(0,21), PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.udp6_queries", '', '');
my $recursor_answers_indom = 1;
my @recursor_answers_dom = (
0 => '0-1 ms',
1 => '1-10 ms',
2 => '10-100 ms',
3 => '100-1000 ms',
4 => '1000+ ms',
);
$pmda->add_metric(pmda_pmid(1,0),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.all_outqueries",
'counts the number of outgoing UDP queries since starting', '');
$pmda->add_metric(pmda_pmid(1,1),PM_TYPE_U64, $recursor_answers_indom,
PM_SEM_COUNTER, pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.answers",
'counts the number of queries answered within X miliseconds', '');
$pmda->add_metric(pmda_pmid(1,2),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_INSTANT,
pmda_units(0,0,0,0,0,0),
"pdns.recursor.cache_entries",
'the number of entries in the cache', '');
$pmda->add_metric(pmda_pmid(1,3),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.cache_hits",
'counts the number of cache hits since starting', '');
$pmda->add_metric(pmda_pmid(1,4),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.cache_misses",
'counts the number of cache misses since starting', '');
$pmda->add_metric(pmda_pmid(1,5),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_INSTANT,
pmda_units(0,0,0,0,0,0),
"pdns.recursor.chain_resends",
'number of queries chained to existing outstanding query', '');
$pmda->add_metric(pmda_pmid(1,6),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.client_parse_errors",
'counts number of client packets that could not be parsed', '');
$pmda->add_metric(pmda_pmid(1,7),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_INSTANT,
pmda_units(0,0,0,0,0,0),
"pdns.recursor.concurrent_queries",
'shows the number of MThreads currently running', '');
$pmda->add_metric(pmda_pmid(1,8),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.dlg_only_drops",
'number of records dropped because of delegation only setting', '');
$pmda->add_metric(pmda_pmid(1,9),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.dont_outqueries",
'number of outgoing queries dropped because of "dont-query" setting', '');
$pmda->add_metric(pmda_pmid(1,10),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.ipv6_outqueries",
'number of outgoing queries over IPv6', '');
$pmda->add_metric(pmda_pmid(1,11),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_INSTANT,
pmda_units(0,0,0,0,0,0),
"pdns.recursor.negcache_entries",
'shows the number of entries in the Negative answer cache', '');
$pmda->add_metric(pmda_pmid(1,12),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.noerror_answers",
'counts the number of times it answered NOERROR since starting', '');
$pmda->add_metric(pmda_pmid(1,13),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_INSTANT,
pmda_units(0,0,0,0,0,0),
"pdns.recursor.nsspeeds_entries",
'shows the number of entries in the NS speeds map', '');
$pmda->add_metric(pmda_pmid(1,14),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.nsset_invalidations",
'number of times an nsset was dropped because it no longer worked', '');
$pmda->add_metric(pmda_pmid(1,15),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.nxdomain_answers",
'counts the number of times it answered NXDOMAIN since starting', '');
$pmda->add_metric(pmda_pmid(1,16),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.outgoing_timeouts",
'counts the number of timeouts on outgoing UDP queries since starting', '');
$pmda->add_metric(pmda_pmid(1,17),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.over_capacity_drops",
'Questions dropped because over maximum concurrent query limit', '');
$pmda->add_metric(pmda_pmid(1,18),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_INSTANT,
pmda_units(0,0,0,0,0,0),
"pdns.recursor.packetcache_entries",
'Size of packet cache', '');
$pmda->add_metric(pmda_pmid(1,19),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.packetcache_hits",
'Packet cache hits', '');
$pmda->add_metric(pmda_pmid(1,20),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.packetcache_misses",
'Packet cache misses', '');
$pmda->add_metric(pmda_pmid(1,21),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_INSTANT,
pmda_units(0,1,0,0,PM_TIME_USEC,0),
"pdns.recursor.qa_latency",
'shows the current latency average, in microseconds', '');
$pmda->add_metric(pmda_pmid(1,22),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.questions",
'counts all End-user initiated queries with the RD bit set', '');
$pmda->add_metric(pmda_pmid(1,23),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.resource_limits",
'counts number of queries that could not be performed because of resource limits', '');
$pmda->add_metric(pmda_pmid(1,24),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.server_parse_errors",
'counts number of server replied packets that could not be parsed', '');
$pmda->add_metric(pmda_pmid(1,25),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.servfail_answers",
'counts the number of times it answered SERVFAIL since starting', '');
$pmda->add_metric(pmda_pmid(1,26),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.spoof_prevents",
'number of times PowerDNS considered itself spoofed, and dropped the data', '');
$pmda->add_metric(pmda_pmid(1,27),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,1,0,0,PM_TIME_MSEC,0),
"pdns.recursor.sys_msec",
'number of CPU milliseconds spent in "system" mode', '');
$pmda->add_metric(pmda_pmid(1,28),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.tcp_client_overflow",
'number of times an IP address was denied TCP access because it already had too many connections', '');
$pmda->add_metric(pmda_pmid(1,29),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.tcp_outqueries",
'counts the number of outgoing TCP queries since starting', '');
$pmda->add_metric(pmda_pmid(1,30),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.tcp_questions",
'counts all incoming TCP queries (since starting)', '');
$pmda->add_metric(pmda_pmid(1,31),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.throttled_out",
'counts the number of throttled outgoing UDP queries since starting', '');
$pmda->add_metric(pmda_pmid(1,32),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_INSTANT,
pmda_units(0,0,0,0,0,0),
"pdns.recursor.throttle_entries",
'shows the number of entries in the throttle map', '');
$pmda->add_metric(pmda_pmid(1,33),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.unauthorized_tcp",
'number of TCP questions denied because of allow-from restrictions', '');
$pmda->add_metric(pmda_pmid(1,34),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.unauthorized_udp",
'number of UDP questions denied because of allow-from restrictions', '');
$pmda->add_metric(pmda_pmid(1,35),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.unexpected_packets",
'number of answers from remote servers that were unexpected (might point to spoofing)', '');
$pmda->add_metric(pmda_pmid(1,36),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,0,1,0,0,PM_COUNT_ONE),
"pdns.recursor.uptime",
'number of seconds process has been running', '');
$pmda->add_metric(pmda_pmid(1,37),PM_TYPE_U64, PM_INDOM_NULL, PM_SEM_COUNTER,
pmda_units(0,1,0,0,PM_TIME_MSEC,0),
"pdns.recursor.user_msec",
'number of CPU milliseconds spent in "user" mode', '');
$pmda->add_indom($recursor_answers_indom, \@recursor_answers_dom, '', '');
$pmda->set_fetch_callback(\&pdns_fetch_callback);
$pmda->set_fetch(\&pdns_fetch);
$pmda->run;
=pod
=head1 NAME
pmdapdns - PowerDNS performance metrics domain agent (PMDA)
=head1 DESCRIPTION
B<pmdapdns> is a Performance Metrics Domain Agent (PMDA) which exports
metric values from the PowerDNS authorative daemon as well as the recursive
resolver.
=head1 INSTALLATION
If you want access to the names and values for the PowerDNS performance
metrics, do the following as root:
# cd $PCP_PMDAS_DIR/pdns
# ./Install
If you want to undo the installation, do the following as root:
# cd $PCP_PMDAS_DIR/pdns
# ./Remove
B<pmdapdns> is launched by pmcd(1) and should never be executed
directly. The Install and Remove scripts notify pmcd(1) when
the agent is installed or removed.
=head1 FILES
=over
=item $PCP_PMDAS_DIR/pdns/Install
installation script for the B<pmdapdns> agent
=item $PCP_PMDAS_DIR/pdns/Remove
undo installation script for the B<pmdapdns> agent
=item $PCP_LOG_DIR/pmcd/pdns.log
default log file for error messages from B<pmdapdns>
=back
=head1 SEE ALSO
pmcd(1), pdns_control(8), and rec_control(1).
|