ffmap-backend/ffmap/outputs/rrd.py

31 lines
789 B
Python
Raw Normal View History

2014-07-07 23:27:21 +02:00
import os
from ffmap.rrd.rrds import NodeRRD, GlobalRRD
2014-07-07 23:27:21 +02:00
class Output:
2014-07-07 23:27:21 +02:00
def __init__(self, directory="nodedb"):
self.directory = directory
try:
os.mkdir(self.directory)
except OSError:
pass
def output(self, nodedb):
2014-07-07 23:27:21 +02:00
nodes = set(nodedb.values())
clients = 0
nodecount = 0
for node in nodes:
clients += len(node.get("clients", []))
nodecount += 1
NodeRRD(
os.path.join(
self.directory,
str(node.id).replace(':', '') + '.rrd'
),
node
).update()
GlobalRRD(os.path.join(self.directory, "nodes.rrd")).update(
nodecount,
clients
)