DMRlink/pickle_stat_reader.py

110 lines
4.4 KiB
Python
Raw Normal View History

2016-11-23 08:50:56 -05:00
#!/usr/bin/env python
#
###############################################################################
# Copyright (C) 2016 Cortney T. Buffington, N0MJS <n0mjs@me.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
###############################################################################
2015-06-30 12:51:04 -04:00
from __future__ import print_function
from cPickle import load
from pprint import pprint
2015-06-30 21:59:13 -04:00
from time import ctime
2015-06-30 13:43:30 -04:00
from twisted.internet import reactor
from twisted.internet import task
from binascii import b2a_hex as h
2015-06-30 12:51:04 -04:00
2016-11-23 08:50:56 -05:00
__author__ = 'Cortney T. Buffington, N0MJS'
__copyright__ = 'Copyright (c) 2015 Cortney T. Buffington, N0MJS and the K0USY Group'
__credits__ = 'Adam Fast, KC0YLK, Dave Kierzkowski, KD8EYF'
__license__ = 'GNU GPLv3'
__maintainer__ = 'Cort Buffington, N0MJS'
__email__ = 'n0mjs@me.com'
2015-06-30 12:51:04 -04:00
# This is the only user-configuration necessary
# Tell the program where the pickle file is
2015-06-30 21:56:00 -04:00
# Tell the program how often to print a report
2015-06-30 21:38:04 -04:00
stat_file = '../dmrlink_stats.pickle'
2015-06-30 21:56:00 -04:00
frequency = 30
2015-06-30 12:51:04 -04:00
2015-06-30 13:43:30 -04:00
def int_id(_hex_string):
return int(h(_hex_string), 16)
2015-06-30 12:51:04 -04:00
def read_dict():
try:
with open(stat_file, 'rb') as file:
NETWORK = load(file)
return NETWORK
except IOError as detail:
print('I/O Error: {}'.format(detail))
except EOFError:
print('EOFError')
2015-06-30 13:43:30 -04:00
def print_stats():
NETWORK = read_dict()
if NETWORK != "None":
2015-06-30 21:59:13 -04:00
print('NETWORK STATISTICS REPORT:', ctime())
2015-07-01 08:53:11 -04:00
2015-06-30 13:43:30 -04:00
for ipsc in NETWORK:
stat = NETWORK[ipsc]['MASTER']['STATUS']
2015-07-01 08:53:11 -04:00
master = NETWORK[ipsc]['LOCAL']['MASTER_PEER']
2015-06-30 13:43:30 -04:00
print(ipsc)
2015-07-01 08:53:11 -04:00
if master:
2015-06-30 21:47:22 -04:00
print(' MASTER Information:')
2015-07-01 08:53:11 -04:00
print(' RADIO ID: {} (self)'.format(str(int_id(NETWORK[ipsc]['LOCAL']['RADIO_ID'])).rjust(8,'0')))
2015-06-30 21:47:22 -04:00
else:
print(' MASTER Information:')
2015-08-05 11:20:42 -04:00
print(' RADIO ID: {} CONNECTED: {}, KEEP ALIVES: SENT {} RECEIVED {} MISSED {} ({})'.format(\
2015-07-01 08:53:11 -04:00
str(int_id(NETWORK[ipsc]['MASTER']['RADIO_ID'])).rjust(8,'0'),\
stat['CONNECTED'],stat['KEEP_ALIVES_SENT'],\
stat['KEEP_ALIVES_RECEIVED'],\
2015-08-05 11:20:42 -04:00
stat['KEEP_ALIVES_MISSED'],\
NETWORK[ipsc]['MASTER']['IP']))
2015-07-01 08:53:11 -04:00
2015-06-30 13:43:30 -04:00
print(' PEER Information:')
2015-07-01 08:53:11 -04:00
if master:
for peer in NETWORK[ipsc]['PEERS']:
stat = NETWORK[ipsc]['PEERS'][peer]['STATUS']
2015-08-05 11:20:42 -04:00
print(' RADIO ID: {} CONNECTED: {}, KEEP ALIVES: RECEIVED {} ({})'.format(\
2015-07-01 08:53:11 -04:00
str(int_id(peer)).rjust(8,'0'),\
stat['CONNECTED'],\
2015-08-05 11:20:42 -04:00
stat['KEEP_ALIVES_RECEIVED'],\
NETWORK[ipsc]['PEERS'][peer]['IP']))
2015-07-01 08:53:11 -04:00
else:
for peer in NETWORK[ipsc]['PEERS']:
stat = NETWORK[ipsc]['PEERS'][peer]['STATUS']
if peer == NETWORK[ipsc]['LOCAL']['RADIO_ID']:
print(' RADIO ID: {} (self)'.format(str(int_id(peer)).rjust(8,'0')))
else:
2015-08-05 11:20:42 -04:00
print(' RADIO ID: {} CONNECTED: {}, KEEP ALIVES: SENT {} RECEIVED {} MISSED {} ({})'.format(\
2015-07-01 08:53:11 -04:00
str(int_id(peer)).rjust(8,'0'),\
stat['CONNECTED'],\
stat['KEEP_ALIVES_SENT'],\
stat['KEEP_ALIVES_RECEIVED'],\
2015-08-05 11:20:42 -04:00
stat['KEEP_ALIVES_MISSED'],\
NETWORK[ipsc]['PEERS'][peer]['IP']))
2015-06-30 13:43:30 -04:00
print()
2015-06-30 21:49:02 -04:00
print()
2015-06-30 13:43:30 -04:00
if __name__ == '__main__':
output_stats = task.LoopingCall(print_stats)
2015-06-30 21:56:00 -04:00
output_stats.start(frequency)
2015-06-30 13:43:30 -04:00
reactor.run()