1 | <?php |
||
2 | /** |
||
3 | * powerdns-recursor.inc.php |
||
4 | * |
||
5 | * PowerDNS Recursor application polling module |
||
6 | * Capable of collecting stats from the agent or via direct connection |
||
7 | * |
||
8 | * This program is free software: you can redistribute it and/or modify |
||
9 | * it under the terms of the GNU General Public License as published by |
||
10 | * the Free Software Foundation, either version 3 of the License, or |
||
11 | * (at your option) any later version. |
||
12 | * |
||
13 | * This program is distributed in the hope that it will be useful, |
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
||
16 | * GNU General Public License for more details. |
||
17 | * |
||
18 | * You should have received a copy of the GNU General Public License |
||
19 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
20 | * |
||
21 | * @link https://www.librenms.org |
||
22 | * |
||
23 | * @copyright 2016 Tony Murray |
||
24 | * @author Tony Murray <[email protected]> |
||
25 | */ |
||
26 | |||
27 | use LibreNMS\Config; |
||
28 | use LibreNMS\RRD\RrdDefinition; |
||
29 | |||
30 | $data = ''; |
||
31 | $name = 'powerdns-recursor'; |
||
32 | $app_id = $app['app_id']; |
||
33 | |||
34 | echo ' ' . $name; |
||
35 | |||
36 | if ($agent_data['app'][$name]) { |
||
37 | $data = $agent_data['app'][$name]; |
||
38 | } elseif (Config::has('apps.powerdns-recursor.api-key')) { |
||
39 | $port = Config::get('apps.powerdns-recursor.port', 8082); |
||
40 | $scheme = Config::get('apps.powerdns-recursor.https') ? 'https://' : 'http://'; |
||
41 | |||
42 | d_echo("\nNo Agent Data. Attempting to connect directly to the powerdns-recursor server $scheme" . $device['hostname'] . ":$port\n"); |
||
43 | $context = stream_context_create(['http' => ['header' => 'X-API-Key: ' . Config::get('apps.powerdns-recursor.api-key')]]); |
||
44 | $data = file_get_contents($scheme . $device['hostname'] . ':' . $port . '/api/v1/servers/localhost/statistics', false, $context); |
||
45 | if ($data === false) { |
||
46 | $data = file_get_contents($scheme . $device['hostname'] . ':' . $port . '/servers/localhost/statistics', false, $context); |
||
47 | } |
||
48 | } else { |
||
49 | // nsExtendOutputFull."powerdns-recursor" |
||
50 | $oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.17.112.111.119.101.114.100.110.115.45.114.101.99.117.114.115.111.114'; |
||
51 | $data = stripslashes(snmp_get($device, $oid, '-Oqv')); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
52 | } |
||
53 | |||
54 | if (! empty($data)) { |
||
55 | $ds_list = [ |
||
56 | 'all-outqueries' => 'DERIVE', |
||
57 | 'answers-slow' => 'DERIVE', |
||
58 | 'answers0-1' => 'DERIVE', |
||
59 | 'answers1-10' => 'DERIVE', |
||
60 | 'answers10-100' => 'DERIVE', |
||
61 | 'answers100-1000' => 'DERIVE', |
||
62 | 'cache-entries' => 'GAUGE', |
||
63 | 'cache-hits' => 'DERIVE', |
||
64 | 'cache-misses' => 'DERIVE', |
||
65 | 'case-mismatches' => 'DERIVE', |
||
66 | 'chain-resends' => 'DERIVE', |
||
67 | 'client-parse-errors' => 'DERIVE', |
||
68 | 'concurrent-queries' => 'GAUGE', |
||
69 | 'dlg-only-drops' => 'DERIVE', |
||
70 | 'dont-outqueries' => 'DERIVE', |
||
71 | 'edns-ping-matches' => 'DERIVE', |
||
72 | 'edns-ping-mismatches' => 'DERIVE', |
||
73 | 'failed-host-entries' => 'GAUGE', |
||
74 | 'ipv6-outqueries' => 'DERIVE', |
||
75 | 'ipv6-questions' => 'DERIVE', |
||
76 | 'malloc-bytes' => 'GAUGE', |
||
77 | 'max-mthread-stack' => 'GAUGE', |
||
78 | 'negcache-entries' => 'GAUGE', |
||
79 | 'no-packet-error' => 'DERIVE', |
||
80 | 'noedns-outqueries' => 'DERIVE', |
||
81 | 'noerror-answers' => 'DERIVE', |
||
82 | 'noping-outqueries' => 'DERIVE', |
||
83 | 'nsset-invalidations' => 'DERIVE', |
||
84 | 'nsspeeds-entries' => 'GAUGE', |
||
85 | 'nxdomain-answers' => 'DERIVE', |
||
86 | 'outgoing-timeouts' => 'DERIVE', |
||
87 | 'over-capacity-drops' => 'DERIVE', |
||
88 | 'packetcache-entries' => 'GAUGE', |
||
89 | 'packetcache-hits' => 'DERIVE', |
||
90 | 'packetcache-misses' => 'DERIVE', |
||
91 | 'policy-drops' => 'DERIVE', |
||
92 | 'qa-latency' => 'GAUGE', |
||
93 | 'questions' => 'DERIVE', |
||
94 | 'resource-limits' => 'DERIVE', |
||
95 | 'security-status' => 'GAUGE', |
||
96 | 'server-parse-errors' => 'DERIVE', |
||
97 | 'servfail-answers' => 'DERIVE', |
||
98 | 'spoof-prevents' => 'DERIVE', |
||
99 | 'sys-msec' => 'DERIVE', |
||
100 | 'tcp-client-overflow' => 'DERIVE', |
||
101 | 'tcp-clients' => 'GAUGE', |
||
102 | 'tcp-outqueries' => 'DERIVE', |
||
103 | 'tcp-questions' => 'DERIVE', |
||
104 | 'throttle-entries' => 'GAUGE', |
||
105 | 'throttled-out' => 'DERIVE', |
||
106 | 'throttled-outqueries' => 'DERIVE', |
||
107 | 'too-old-drops' => 'DERIVE', |
||
108 | 'unauthorized-tcp' => 'DERIVE', |
||
109 | 'unauthorized-udp' => 'DERIVE', |
||
110 | 'unexpected-packets' => 'DERIVE', |
||
111 | 'unreachables' => 'DERIVE', |
||
112 | 'uptime' => 'DERIVE', |
||
113 | 'user-msec' => 'DERIVE', |
||
114 | ]; |
||
115 | |||
116 | //decode and flatten the data |
||
117 | $stats = []; |
||
118 | foreach (json_decode($data, true) as $stat) { |
||
119 | $stats[$stat['name']] = $stat['value']; |
||
120 | } |
||
121 | d_echo($stats); |
||
122 | |||
123 | // only the stats we store in rrd |
||
124 | $rrd_def = new RrdDefinition(); |
||
125 | $fields = []; |
||
126 | foreach ($ds_list as $key => $type) { |
||
127 | $rrd_def->addDataset($key, $type, 0); |
||
128 | |||
129 | if (isset($stats[$key])) { |
||
130 | $fields[$key] = $stats[$key]; |
||
131 | } else { |
||
132 | $fields[$key] = 'U'; |
||
133 | } |
||
134 | } |
||
135 | |||
136 | $rrd_name = ['app', 'powerdns', 'recursor', $app_id]; |
||
137 | $tags = compact('name', 'app_id', 'rrd_name', 'rrd_def'); |
||
138 | data_update($device, 'app', $tags, $fields); |
||
139 | update_application($app, $data, $fields); |
||
140 | } |
||
141 | |||
142 | unset($data, $stats, $rrd_def, $rrd_name, $rrd_keys, $tags, $fields); |
||
143 |