NodeRRD: add many more DS, rrd.py: generate neighbor counts
This commit is contained in:
parent
43e70191f1
commit
7075d8481c
31
NodeRRD.py
31
NodeRRD.py
|
@ -7,6 +7,19 @@ class NodeRRD(RRD):
|
|||
ds_list = [
|
||||
DS('upstate', 'GAUGE', 120, 0, 1),
|
||||
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('AVERAGE', 0.5, 1, 120), # 2 hours of 1 minute samples
|
||||
|
@ -30,7 +43,23 @@ class NodeRRD(RRD):
|
|||
return os.path.basename(self.filename).rsplit('.', 2)[0] + ".png"
|
||||
|
||||
def update(self):
|
||||
super().update({'upstate': 1, 'clients': self.node.clients})
|
||||
values = {
|
||||
'upstate': 1,
|
||||
'clients': float(self.node.clients),
|
||||
'neighbors': float(self.node.neighbors),
|
||||
'vpn_neighbors': float(self.node.vpn_neighbors),
|
||||
'loadavg': float(self.node.statistics['loadavg']),
|
||||
}
|
||||
for item in ('rx', 'tx', 'mgmt_rx', 'mgmt_tx', 'forward'):
|
||||
try:
|
||||
values['%s_bytes' % item] = int(self.node.statistics['traffic'][item]['bytes'])
|
||||
except TypeError:
|
||||
pass
|
||||
try:
|
||||
values['%s_packets' % item] = int(self.node.statistics['traffic'][item]['packets'])
|
||||
except TypeError:
|
||||
pass
|
||||
super().update(values)
|
||||
|
||||
def graph(self, directory, timeframe):
|
||||
"""
|
||||
|
|
1
node.py
1
node.py
|
@ -12,6 +12,7 @@ class NoneDict:
|
|||
__bool__ = lambda self: False
|
||||
__getitem__ = lambda self, k: NoneDict()
|
||||
__json__ = lambda self: None
|
||||
__float__ = lambda self: float('NaN')
|
||||
def __setitem__(self, key, value):
|
||||
raise RuntimeError("NoneDict is readonly")
|
||||
|
||||
|
|
10
rrd.py
10
rrd.py
|
@ -33,7 +33,9 @@ class rrd:
|
|||
if node.flags['online']:
|
||||
if not node.flags['client']:
|
||||
nodes[node.id] = node
|
||||
node.clients = 0;
|
||||
node.clients = 0
|
||||
node.neighbors = 0
|
||||
node.vpn_neighbors = 0
|
||||
if 'legacy' in node.flags and node.flags['legacy']:
|
||||
clientCount -= 1
|
||||
else:
|
||||
|
@ -45,6 +47,12 @@ class rrd:
|
|||
nodes[source].clients += 1
|
||||
elif target in nodes and not source in nodes:
|
||||
nodes[target].clients += 1
|
||||
elif source in nodes and target in nodes:
|
||||
nodes[source].neighbors += 1
|
||||
nodes[target].neighbors += 1
|
||||
if link.type == 'vpn':
|
||||
nodes[target].vpn_neighbors += 1
|
||||
nodes[source].vpn_neighbors += 1
|
||||
|
||||
self.globalDb.update(len(nodes), clientCount)
|
||||
for node in nodes.values():
|
||||
|
|
Loading…
Reference in a new issue