summaryrefslogtreecommitdiffstats
path: root/python.d/isc_dhcpd.chart.py
diff options
context:
space:
mode:
Diffstat (limited to 'python.d/isc_dhcpd.chart.py')
-rw-r--r--python.d/isc_dhcpd.chart.py37
1 files changed, 17 insertions, 20 deletions
diff --git a/python.d/isc_dhcpd.chart.py b/python.d/isc_dhcpd.chart.py
index 54fbfb1f..bb9ba5cb 100644
--- a/python.d/isc_dhcpd.chart.py
+++ b/python.d/isc_dhcpd.chart.py
@@ -48,31 +48,31 @@ class Service(SimpleService):
except (ValueError, IndexError, AttributeError, SyntaxError) as e:
self.error('Pools configurations is incorrect', str(e))
return False
-
+
# Creating static charts
self.order = ['parse_time', 'leases_size', 'utilization', 'total']
self.definitions = {'utilization':
{'options':
- [None, 'Pools utilization', 'used %', 'Utilization', 'isc_dhcpd.util', 'line'],
+ [None, 'Pools utilization', 'used %', 'utilization', 'isc_dhcpd.util', 'line'],
'lines': []},
'total':
{'options':
- [None, 'Total all pools', 'leases', 'Utilization', 'isc_dhcpd.total', 'line'],
+ [None, 'Total all pools', 'leases', 'utilization', 'isc_dhcpd.total', 'line'],
'lines': [['total', 'leases', 'absolute']]},
'parse_time':
{'options':
- [None, 'Parse time', 'ms', 'Parse stats', 'isc_dhcpd.parse', 'line'],
+ [None, 'Parse time', 'ms', 'parse stats', 'isc_dhcpd.parse', 'line'],
'lines': [['ptime', 'time', 'absolute']]},
'leases_size':
{'options':
- [None, 'dhcpd.leases file size', 'kilobytes', 'Parse stats', 'isc_dhcpd.lsize', 'line'],
+ [None, 'dhcpd.leases file size', 'kilobytes', 'parse stats', 'isc_dhcpd.lsize', 'line'],
'lines': [['lsize', 'size', 'absolute']]}}
# Creating dynamic charts
for pool in self.pools:
self.definitions['utilization']['lines'].append([''.join(['ut_', pool]), pool, 'absolute'])
self.order.append(''.join(['leases_', pool]))
self.definitions[''.join(['leases_', pool])] = \
- {'options': [None, 'Active leases', 'leases', 'Pools', 'isc_dhcpd.lease', 'area'],
+ {'options': [None, 'Active leases', 'leases', 'pools', 'isc_dhcpd.lease', 'area'],
'lines': [[''.join(['le_', pool]), pool, 'absolute']]}
self.info('Plugin was started succesfully')
@@ -93,13 +93,10 @@ class Service(SimpleService):
part2 = filterfalse(find_ends, dhcp_leases)
raw_result = dict(zip(part1, part2))
time_end = time()
-
file_parse_time = round((time_end - time_start) * 1000)
-
except Exception as e:
self.error("Failed to parse leases file:", str(e))
return None
-
else:
result = (raw_result, file_parse_time)
return result
@@ -109,32 +106,31 @@ class Service(SimpleService):
:return: dict
"""
raw_leases = self._get_raw_data()
-
if not raw_leases:
return None
# Result: {ipaddress: end lease time, ...}
- all_leases = {k[6:len(k)-3]:v[7:len(v)-2] for k, v in raw_leases[0].items()}
+ all_leases = dict([(k[6:len(k)-3], v[7:len(v)-2]) for k, v in raw_leases[0].items()])
# Result: [active binding, active binding....]. (Expire time (ends date;) - current time > 0)
active_leases = [k for k, v in all_leases.items() if is_binding_active(all_leases[k])]
# Result: {pool: number of active bindings in pool, ...}
- pools_count = {pool: len([lease for lease in active_leases if is_address_in(lease, pool)])
- for pool in self.pools}
+ pools_count = dict([(pool, len([lease for lease in active_leases if is_address_in(lease, pool)]))
+ for pool in self.pools])
# Result: {pool: number of host ip addresses in pool, ...}
- pools_max = {pool: (2 ** (32 - int(pool.split('/')[1])) - 2)
- for pool in self.pools}
+ pools_max = dict([(pool, (2 ** (32 - int(pool.split('/')[1])) - 2))
+ for pool in self.pools])
# Result: {pool: % utilization, ....} (percent)
- pools_util = {pool:int(round(float(pools_count[pool]) / pools_max[pool] * 100, 0))
- for pool in self.pools}
+ pools_util = dict([(pool, int(round(float(pools_count[pool]) / pools_max[pool] * 100, 0)))
+ for pool in self.pools])
# Bulding dicts to send to netdata
- final_count = {''.join(['le_', k]): v for k, v in pools_count.items()}
- final_util = {''.join(['ut_', k]): v for k, v in pools_util.items()}
-
+ final_count = dict([(''.join(['le_', k]), v) for k, v in pools_count.items()])
+ final_util = dict([(''.join(['ut_', k]), v) for k, v in pools_util.items()])
+
to_netdata = {'total': len(active_leases)}
to_netdata.update({'lsize': int(stat(self.leases_path)[6] / 1024)})
to_netdata.update({'ptime': int(raw_leases[1])})
@@ -159,6 +155,7 @@ def find_lease(value):
def find_ends(value):
return value[2:6] != 'ends'
+
def return_utf(s):
# python2 returns "<type 'str'>" for simple strings
# python3 returns "<class 'str'>" for unicode strings