From e02c03a09997ae1761037e616552ffa9591c32ed Mon Sep 17 00:00:00 2001 From: Cort Buffington Date: Sun, 5 Oct 2014 22:11:56 -0500 Subject: [PATCH] publish data structure to file --- .gitignore | 1 + dmrlink.py | 9 +++++++++ report.py | 14 ++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 report.py diff --git a/.gitignore b/.gitignore index e9a4c46..1bfdb8b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.out Icon dmrlink.cfg +stats.py pub* bridge_rules.py playback_config.py diff --git a/dmrlink.py b/dmrlink.py index 58ef0e7..a8e0429 100755 --- a/dmrlink.py +++ b/dmrlink.py @@ -23,6 +23,8 @@ import logging import time import signal +import cPickle as pickle + from logging.config import dictConfig from hmac import new as hmac_new from binascii import b2a_hex as h @@ -595,6 +597,11 @@ def print_master(_network): print('\t\tStatus: {}, KeepAlives Sent: {}, KeepAlives Outstanding: {}, KeepAlives Missed: {}' .format(_master['STATUS']['CONNECTED'], _master['STATUS']['KEEP_ALIVES_SENT'], _master['STATUS']['KEEP_ALIVES_OUTSTANDING'], _master['STATUS']['KEEP_ALIVES_MISSED'])) print('\t\t KeepAlives Received: {}, Last KeepAlive Received at: {}' .format(_master['STATUS']['KEEP_ALIVES_RECEIVED'], _master['STATUS']['KEEP_ALIVE_RX_TIME'])) +def write_ipsc_stats(): + file = open('stats.py', 'w') + pickle.dump(NETWORK, file) + file.close() + # Shut ourselves down gracefully with the IPSC peers. # def handler(_signal, _frame): @@ -1279,4 +1286,6 @@ if __name__ == '__main__': if NETWORK[ipsc_network]['LOCAL']['ENABLED']: networks[ipsc_network] = IPSC(ipsc_network) reactor.listenUDP(NETWORK[ipsc_network]['LOCAL']['PORT'], networks[ipsc_network]) + write_stats = task.LoopingCall(write_ipsc_stats) + write_stats.start(10) reactor.run() \ No newline at end of file diff --git a/report.py b/report.py new file mode 100644 index 0000000..003e654 --- /dev/null +++ b/report.py @@ -0,0 +1,14 @@ +from pprint import pprint +from twisted.internet import reactor +from twisted.internet import task +import cPickle as pickle + +def print_stats(): + stats_file = open('stats.py', 'r') + NETWORK = pickle.load(stats_file) + stats_file.close() + pprint(NETWORK['C-BRIDGE']) + +output_stats = task.LoopingCall(print_stats) +output_stats.start(10) +reactor.run() \ No newline at end of file