Compare commits
1 Commits
master
...
detailed-r
Author | SHA1 | Date |
---|---|---|
Jan-Philipp Litza | 88e046a48c |
|
@ -154,7 +154,7 @@ def main(params):
|
||||||
script_directory = os.path.dirname(os.path.realpath(__file__))
|
script_directory = os.path.dirname(os.path.realpath(__file__))
|
||||||
rrd = RRD(os.path.join(script_directory, 'nodedb'),
|
rrd = RRD(os.path.join(script_directory, 'nodedb'),
|
||||||
os.path.join(params['dest_dir'], 'nodes'))
|
os.path.join(params['dest_dir'], 'nodes'))
|
||||||
rrd.update_database(nodedb['nodes'])
|
rrd.update_database(nodedb['nodes'], batadv_graph)
|
||||||
rrd.update_images()
|
rrd.update_images()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,25 +8,35 @@ class NodeRRD(RRD):
|
||||||
ds_list = [
|
ds_list = [
|
||||||
DS('upstate', 'GAUGE', 120, 0, 1),
|
DS('upstate', 'GAUGE', 120, 0, 1),
|
||||||
DS('clients', 'GAUGE', 120, 0, float('NaN')),
|
DS('clients', 'GAUGE', 120, 0, float('NaN')),
|
||||||
|
DS('neighbors', 'GAUGE', 120, 0, float('NaN')),
|
||||||
|
DS('vpn_neighbors', 'GAUGE', 120, 0, float('NaN')),
|
||||||
|
DS('loadavg', 'GAUGE', 120, 0, float('NaN')),
|
||||||
|
DS('rx_bytes', 'DERIVE', 120, 0, float('NaN')),
|
||||||
|
DS('rx_packets', 'DERIVE', 120, 0, float('NaN')),
|
||||||
|
DS('tx_bytes', 'DERIVE', 120, 0, float('NaN')),
|
||||||
|
DS('tx_packets', 'DERIVE', 120, 0, float('NaN')),
|
||||||
|
DS('mgmt_rx_bytes', 'DERIVE', 120, 0, float('NaN')),
|
||||||
|
DS('mgmt_rx_packets', 'DERIVE', 120, 0, float('NaN')),
|
||||||
|
DS('mgmt_tx_bytes', 'DERIVE', 120, 0, float('NaN')),
|
||||||
|
DS('mgmt_tx_packets', 'DERIVE', 120, 0, float('NaN')),
|
||||||
|
DS('forward_bytes', 'DERIVE', 120, 0, float('NaN')),
|
||||||
|
DS('forward_packets', 'DERIVE', 120, 0, float('NaN')),
|
||||||
]
|
]
|
||||||
rra_list = [
|
rra_list = [
|
||||||
# 2 hours of 1 minute samples
|
# 2 hours of 1 minute samples
|
||||||
RRA('AVERAGE', 0.5, 1, 120),
|
RRA('AVERAGE', 0.5, 1, 120),
|
||||||
# 5 days of 5 minute samples
|
# 7 days of 15 minute samples
|
||||||
RRA('AVERAGE', 0.5, 5, 1440),
|
RRA('AVERAGE', 0.5, 15, 672),
|
||||||
# 30 days of 1 hour samples
|
|
||||||
RRA('AVERAGE', 0.5, 60, 720),
|
|
||||||
# 1 year of 12 hour samples
|
|
||||||
RRA('AVERAGE', 0.5, 720, 730),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, filename, node=None):
|
def __init__(self, filename, node=None, graph=None):
|
||||||
"""
|
"""
|
||||||
Create a new RRD for a given node.
|
Create a new RRD for a given node.
|
||||||
|
|
||||||
If the RRD isn't supposed to be updated, the node can be omitted.
|
If the RRD isn't supposed to be updated, the node can be omitted.
|
||||||
"""
|
"""
|
||||||
self.node = node
|
self.node = node
|
||||||
|
self.node_graph = graph
|
||||||
super().__init__(filename)
|
super().__init__(filename)
|
||||||
self.ensure_sanity(self.ds_list, self.rra_list, step=60)
|
self.ensure_sanity(self.ds_list, self.rra_list, step=60)
|
||||||
|
|
||||||
|
@ -37,8 +47,28 @@ class NodeRRD(RRD):
|
||||||
|
|
||||||
# TODO: fix this, python does not support function overloading
|
# TODO: fix this, python does not support function overloading
|
||||||
def update(self):
|
def update(self):
|
||||||
super().update({'upstate': int(self.node['flags']['online']),
|
values = {
|
||||||
'clients': self.node['statistics']['clients']})
|
'upstate': int(self.node['flags']['online']),
|
||||||
|
'clients': float(self.node['statistics']['clients']),
|
||||||
|
'loadavg': float(self.node['statistics'].get('loadavg', 0)),
|
||||||
|
}
|
||||||
|
for item in ('rx', 'tx', 'mgmt_rx', 'mgmt_tx', 'forward'):
|
||||||
|
try:
|
||||||
|
values.update({
|
||||||
|
('%s_bytes' % item): int(self.node['statistics'].get('traffic', {}).get(item, {}).get('bytes', 0)),
|
||||||
|
('%s_packets' % item): int(self.node['statistics'].get('traffic', {}).get(item, {}).get('packets', 0)),
|
||||||
|
})
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
graph_node = next(key for key, node in self.node_graph.nodes(data=True) if node.get('node_id') == self.node['nodeinfo']['node_id'])
|
||||||
|
values.update({
|
||||||
|
'neighbors': float(len(self.node_graph[graph_node])),
|
||||||
|
'vpn_neighbors': float(len(list(filter(lambda edge: edge.get('vpn', False), self.node_graph[graph_node].values())))),
|
||||||
|
})
|
||||||
|
except StopIteration:
|
||||||
|
pass
|
||||||
|
super().update(values)
|
||||||
|
|
||||||
def graph(self, directory, timeframe):
|
def graph(self, directory, timeframe):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -27,7 +27,7 @@ class RRD(object):
|
||||||
except OSError:
|
except OSError:
|
||||||
os.mkdir(self.imagePath)
|
os.mkdir(self.imagePath)
|
||||||
|
|
||||||
def update_database(self, nodes):
|
def update_database(self, nodes, graph):
|
||||||
online_nodes = dict(filter(
|
online_nodes = dict(filter(
|
||||||
lambda d: d[1]['flags']['online'], nodes.items()))
|
lambda d: d[1]['flags']['online'], nodes.items()))
|
||||||
client_count = sum(map(
|
client_count = sum(map(
|
||||||
|
@ -35,7 +35,7 @@ class RRD(object):
|
||||||
|
|
||||||
self.globalDb.update(len(online_nodes), client_count)
|
self.globalDb.update(len(online_nodes), client_count)
|
||||||
for node_id, node in online_nodes.items():
|
for node_id, node in online_nodes.items():
|
||||||
rrd = NodeRRD(os.path.join(self.dbPath, node_id + '.rrd'), node)
|
rrd = NodeRRD(os.path.join(self.dbPath, node_id + '.rrd'), node, graph)
|
||||||
rrd.update()
|
rrd.update()
|
||||||
|
|
||||||
def update_images(self):
|
def update_images(self):
|
||||||
|
|
Loading…
Reference in New Issue