-
Notifications
You must be signed in to change notification settings - Fork 595
Expand file tree
/
Copy pathbind.py
More file actions
executable file
·159 lines (139 loc) · 5.71 KB
/
bind.py
File metadata and controls
executable file
·159 lines (139 loc) · 5.71 KB
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
# coding=utf-8
"""
Collects stats from bind 9.5's statistics server
#### Dependencies
* [bind 9.5](http://www.isc.org/software/bind/new-features/9.5)
configured with libxml2 and statistics-channels
"""
import diamond.collector
import sys
import urllib2
from diamond.collector import str_to_bool
if sys.version_info >= (2, 5):
import xml.etree.cElementTree as ElementTree
else:
import cElementTree as ElementTree
class BindCollector(diamond.collector.Collector):
def get_default_config_help(self):
config_help = super(BindCollector, self).get_default_config_help()
config_help.update({
'host': "",
'port': "",
'publish': "Available stats:\n" +
" - resolver (Per-view resolver and cache statistics)\n" +
" - server (Incoming requests and their answers)\n" +
" - zonemgmt (Zone management requests/responses)\n" +
" - sockets (Socket statistics)\n" +
" - memory (Global memory usage)\n",
'publish_view_bind': "",
'publish_view_meta': "",
'derivative': "",
})
return config_help
def get_default_config(self):
"""
Returns the default collector settings
"""
config = super(BindCollector, self).get_default_config()
config.update({
'host': 'localhost',
'port': 8080,
'path': 'bind',
# Available stats:
# - resolver (Per-view resolver and cache statistics)
# - server (Incoming requests and their answers)
# - zonemgmt (Requests/responses related to zone management)
# - sockets (Socket statistics)
# - memory (Global memory usage)
'publish': [
'resolver',
'server',
'zonemgmt',
'sockets',
'memory',
],
# By default we don't publish these special views
'publish_view_bind': False,
'publish_view_meta': False,
'derivative': True,
})
return config
def clean_counter(self, name, value):
if str_to_bool(self.config['derivative']):
value = self.derivative(name, value)
if value < 0:
value = 0
self.publish(name, value)
def collect(self):
try:
req = urllib2.urlopen('http://%s:%d/' % (
self.config['host'], int(self.config['port'])))
except Exception, e:
self.log.error('Couldnt connect to bind: %s', e)
return {}
tree = ElementTree.parse(req)
if not tree:
raise ValueError("Corrupt XML file, no statistics found")
root = tree.find('bind/statistics')
if 'resolver' in self.config['publish']:
for view in root.findall('views/view'):
name = view.find('name').text
if name == '_bind' and not self.config['publish_view_bind']:
continue
if name == '_meta' and not self.config['publish_view_meta']:
continue
nzones = len(view.findall('zones/zone'))
self.publish('view.%s.zones' % name, nzones)
for counter in view.findall('rdtype'):
self.clean_counter(
'view.%s.query.%s' % (name,
counter.find('name').text),
int(counter.find('counter').text)
)
for counter in view.findall('resstat'):
self.clean_counter(
'view.%s.resstat.%s' % (name,
counter.find('name').text),
int(counter.find('counter').text)
)
for counter in view.findall('cache/rrset'):
self.clean_counter(
'view.%s.cache.%s' % (
name, counter.find('name').text.replace('!',
'NOT_')),
int(counter.find('counter').text)
)
if 'server' in self.config['publish']:
for counter in root.findall('server/requests/opcode'):
self.clean_counter(
'requests.%s' % counter.find('name').text,
int(counter.find('counter').text)
)
for counter in root.findall('server/queries-in/rdtype'):
self.clean_counter(
'queries.%s' % counter.find('name').text,
int(counter.find('counter').text)
)
for counter in root.findall('server/nsstat'):
self.clean_counter(
'nsstat.%s' % counter.find('name').text,
int(counter.find('counter').text)
)
if 'zonemgmt' in self.config['publish']:
for counter in root.findall('server/zonestat'):
self.clean_counter(
'zonestat.%s' % counter.find('name').text,
int(counter.find('counter').text)
)
if 'sockets' in self.config['publish']:
for counter in root.findall('server/sockstat'):
self.clean_counter(
'sockstat.%s' % counter.find('name').text,
int(counter.find('counter').text)
)
if 'memory' in self.config['publish']:
for counter in root.find('memory/summary').getchildren():
self.publish(
'memory.%s' % counter.tag,
int(counter.text)
)