Added directory for rrd-data to command line options

master
Thomas Hooge 2015-12-02 13:33:14 +01:00
parent ec3c414594
commit a5a9690c25
1 changed files with 22 additions and 8 deletions

View File

@ -2,6 +2,11 @@
""" """
backend.py - ffmap-backend runner backend.py - ffmap-backend runner
https://github.com/ffnord/ffmap-backend https://github.com/ffnord/ffmap-backend
Erweiterte Version von Freifunk Pinneberg
- Graphiken aus RRD-Daten nur auf Anforderung erzeugen
- Verzeichnis für die RRD-Nodedb als Kommandozeilenparameter
""" """
import argparse import argparse
import json import json
@ -56,7 +61,7 @@ def main(params):
'Unparseable value "{0}" in --mesh parameter.'. 'Unparseable value "{0}" in --mesh parameter.'.
format(value)) format(value))
# read nodedb state from node.json # read nodedb state from nodes.json
try: try:
with open(nodes_fn, 'r') as nodedb_handle: with open(nodes_fn, 'r') as nodedb_handle:
nodedb = json.load(nodedb_handle) nodedb = json.load(nodedb_handle)
@ -151,6 +156,9 @@ def main(params):
# optional rrd graphs (trigger with --rrd) # optional rrd graphs (trigger with --rrd)
if params['rrd']: if params['rrd']:
if params['nodedb']:
rrd = RRD(params['nodedb'], os.path.join(params['dest_dir'], 'nodes'))
else:
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'))
@ -159,7 +167,11 @@ def main(params):
rrd.update_images() rrd.update_images()
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser()
# get options from command line
parser = argparse.ArgumentParser(
description = "Collect data for ffmap: creates json files and "
"optional rrd data and graphs")
parser.add_argument('-a', '--aliases', parser.add_argument('-a', '--aliases',
help='Read aliases from FILE', help='Read aliases from FILE',
@ -175,13 +187,15 @@ if __name__ == '__main__':
parser.add_argument('-V', '--vpn', nargs='+', metavar='MAC', parser.add_argument('-V', '--vpn', nargs='+', metavar='MAC',
help='Assume MAC addresses are part of vpn') help='Assume MAC addresses are part of vpn')
parser.add_argument('-p', '--prune', metavar='DAYS', type=int, parser.add_argument('-p', '--prune', metavar='DAYS', type=int,
help='forget nodes offline for at least DAYS') help='Forget nodes offline for at least DAYS')
parser.add_argument('--with-rrd', dest='rrd', action='store_true', parser.add_argument('--with-rrd', dest='rrd', action='store_true',
default=False, default=False,
help='enable the collection of RRD data') help='Enable the collection of RRD data')
parser.add_argument('--nodedb', metavar='RRD_DIR', action='store',
help='Directory for node RRD data files')
parser.add_argument('--with-img', dest='img', action='store_true', parser.add_argument('--with-img', dest='img', action='store_true',
default=False, default=False,
help='enable the rendering of RRD graphs (cpu ' help='Enable the rendering of RRD graphs (cpu '
'intensive)') 'intensive)')
options = vars(parser.parse_args()) options = vars(parser.parse_args())