Various fixes for unbound.chart.py:
* Fixed broken framework import and check function. Somehow I accidentally commited ones from an older development revision. * Add correct handling for the two values we need to track that are not integers. * Split the auto-configuration logic out of __init__() so code is a bit more concise.
Austin S. Hemmelgarn committed
May 2, 2018 at 08:15 UTC
803b6bdba94dfbc195bfb1d404544179bc2ac58e
1 file changed
+43
-39
python.d/unbound.chart.py
+43
-39
@@ -5,8 +5,9 @@
5
import os
6
import yaml
7
8
-from base.FrameworkServices.SocketService import SocketService
8
+from bases.FrameworkServices.SocketService import SocketService
9
10
+PRECISION = 1000
11
12
ORDER = ['queries', 'reqlist', 'recursion']
13
@@ -36,8 +37,8 @@ CHARTS = {
37
'recursion': {
38
'options': [None, 'Recursion Timings', 'seconds', 'Unbound', 'unbound.recursion', 'line'],
39
'lines': [
39
- ['recursive_avg', 'Average', 'absolute', 1, 1],
40
- ['recursive_med', 'Median', 'absolute', 1, 1]
40
+ ['recursive_avg', 'Average', 'absolute', 1, PRECISION],
41
+ ['recursive_med', 'Median', 'absolute', 1, PRECISION]
42
]
43
}
44
}
@@ -47,7 +48,7 @@ EXTENDED_ORDER = ['cache']
48
49
EXTENDED_CHARTS = {
50
'cache': {
50
- 'options': [None, 'Cache Sizes', 'items', 'Unbound', 'unbound.cache', 'line'],
51
+ 'options': [None, 'Cache Sizes', 'items', 'Unbound', 'unbound.cache', 'stacked'],
52
'lines': [
53
['cache_message', 'Message Cache', 'absolute', 1, 1],
54
['cache_rrset', 'RRSet Cache', 'absolute', 1, 1],
@@ -59,28 +60,28 @@ EXTENDED_CHARTS = {
60
}
61
}
62
62
-# This maps the Unbound stat names to our names.
63
+# This maps the Unbound stat names to our names and precision requiremnets.
64
STAT_MAP = {
64
- 'total.num.queries_ip_ratelimited': 'ratelimit',
65
- 'total.num.cachehits': 'cachehit',
66
- 'total.num.cachemiss': 'cachemiss',
67
- 'total.num.zero_ttl': 'expired',
68
- 'total.num.prefetch': 'prefetch',
69
- 'total.num.recursivereplies': 'recursive',
70
- 'total.requestlist.avg': 'reqlist_avg',
71
- 'total.requestlist.max': 'reqlist_max',
72
- 'total.requestlist.overwritten': 'reqlist_overwritten',
73
- 'total.requestlist.exceeded': 'reqlist_exceeded',
74
- 'total.requestlist.current.all': 'reqlist_current',
75
- 'total.requestlist.current.user': 'reqlist_user',
76
- 'total.recursion.time.avg': 'recursive_avg',
77
- 'total.recursion.time.median': 'recursive_med',
78
- 'msg.cache.count': 'cache_message',
79
- 'rrset.cache.count': 'cache_rrset',
80
- 'infra.cache.count': 'cache_infra',
81
- 'key.cache.count': 'cache_key',
82
- 'dnscrypt_shared_secret.cache.count': 'cache_dnscss',
83
- 'dnscrypt_nonce.cache.count': 'cache_dnscn'
65
+ 'total.num.queries_ip_ratelimited': ('ratelimit', 1),
66
+ 'total.num.cachehits': ('cachehit', 1),
67
+ 'total.num.cachemiss': ('cachemiss', 1),
68
+ 'total.num.zero_ttl': ('expired', 1),
69
+ 'total.num.prefetch': ('prefetch', 1),
70
+ 'total.num.recursivereplies': ('recursive', 1),
71
+ 'total.requestlist.avg': ('reqlist_avg', 1),
72
+ 'total.requestlist.max': ('reqlist_max', 1),
73
+ 'total.requestlist.overwritten': ('reqlist_overwritten', 1),
74
+ 'total.requestlist.exceeded': ('reqlist_exceeded', 1),
75
+ 'total.requestlist.current.all': ('reqlist_current', 1),
76
+ 'total.requestlist.current.user': ('reqlist_user', 1),
77
+ 'total.recursion.time.avg': ('recursive_avg', PRECISION),
78
+ 'total.recursion.time.median': ('recursive_med', PRECISION),
79
+ 'msg.cache.count': ('cache_message', 1),
80
+ 'rrset.cache.count': ('cache_rrset', 1),
81
+ 'infra.cache.count': ('cache_infra', 1),
82
+ 'key.cache.count': ('cache_key', 1),
83
+ 'dnscrypt_shared_secret.cache.count': ('cache_dnscss', 1),
84
+ 'dnscrypt_nonce.cache.count': ('cache_dnscn', 1)
85
}
86
87
@@ -102,6 +103,20 @@ class Service(SocketService):
103
self.request = 'UBCT1 stats\n'
104
self._parse_config()
105
self.debug('Unbound config: {0}'.format(self.ubconf))
106
+ self._auto_config()
107
+ self.debug('Extended stats: {0}'.format(self.ext))
108
+ if self.unix_socket:
109
+ self.debug('Using unix socket: {0}'.format(self.unix_socket))
110
+ for key in self.definitions.keys():
111
+ self.definitions[key]['options'][4] = 'Local'
112
+ else:
113
+ self.debug('Connecting to: {0}:{1}'.format(self.host, self.port))
114
+ self.debug('Using key: {0}'.format(self.key))
115
+ self.debug('Using certificate: {0}'.format(self.cert))
116
+ for key in self.definitions.keys():
117
+ self.definitions[key]['options'][4] = self.host
118
+
119
+ def _auto_config(self):
120
if os.access(self.ubconf, os.R_OK):
121
with open(self.ubconf, 'r') as ubconf:
122
try:
@@ -121,24 +136,13 @@ class Service(SocketService):
136
else:
137
if not self.unix_socket:
138
self.unix_socket = conf['remote-control'].get('control-interface')
124
- self.debug('Extended stats: {0}'.format(self.ext))
125
- if self.unix_socket:
126
- self.debug('Using unix socket: {0}'.format(self.unix_socket))
127
- for key in self.definitions.keys():
128
- self.definitions[key]['options'][4] = 'Local'
129
- else:
130
- self.debug('Connecting to: {0}:{1}'.format(self.host, self.port))
131
- self.debug('Using key: {0}'.format(self.key))
132
- self.debug('Using certificate: {0}'.format(self.cert))
133
- for key in self.definitions.keys():
134
- self.definitions[key]['options'][4] = self.host
135
-
139
140
def check(self):
141
# We need to check that auth works, otherwise there's no point.
142
self._connect()
143
+ result = bool(self._sock)
144
self._disconnect()
141
- return bool(self._sock)
145
+ return result
146
147
def _check_raw_data(self, data):
148
# The server will close the connection when it's done sending
@@ -154,5 +158,5 @@ class Service(SocketService):
158
tmp[stat[0]] = stat[1]
159
for item in STAT_MAP.keys():
160
if item in tmp.keys():
157
- data[STAT_MAP[item]] = float(tmp[item])
161
+ data[STAT_MAP[item][0]] = float(tmp[item]) * STAT_MAP[item][1]
162
return data