Commit aed97e1a authored by Joanne Hugé's avatar Joanne Hugé

WIP

parent 76a7aa96
...@@ -2,7 +2,6 @@ import errno ...@@ -2,7 +2,6 @@ import errno
import os import os
import time import time
from .util import JSONPromise
from .util import get_json_log_latest_timestamp from .util import get_json_log_latest_timestamp
from zope.interface import implementer from zope.interface import implementer
......
...@@ -4,44 +4,12 @@ import logging ...@@ -4,44 +4,12 @@ import logging
import os import os
from dateutil import parser from dateutil import parser
from .util import get_json_log_latest_timestamp
from zope.interface import implementer from zope.interface import implementer
from slapos.grid.promise import interface from slapos.grid.promise import interface
from slapos.grid.promise.generic import GenericPromise from slapos.grid.promise.generic import GenericPromise
# Get all data in the last "interval" seconds from JSON log
def get_data_interval(log, interval):
log_number = 0
latest_timestamp = 0
data_list = []
while True:
try:
f = open("{}.{}".format(log, log_number) if log_number else log, "rb")
except OSError:
return data_list
try:
f.seek(0, os.SEEK_END)
while True:
try:
while f.seek(-2, os.SEEK_CUR) and f.read(1) != b'\n':
pass
except OSError:
break
pos = f.tell()
l = json.loads(f.readline().decode().replace("'", '"'))
timestamp = parser.parse(l['time'])
data_list.append(l['data'])
if not latest_timestamp:
latest_timestamp = timestamp
if (latest_timestamp - timestamp).total_seconds() > interval:
return data_list
f.seek(pos, os.SEEK_SET)
finally:
f.close()
log_number += 1
@implementer(interface.IPromise) @implementer(interface.IPromise)
class RunPromise(GenericPromise): class RunPromise(GenericPromise):
...@@ -71,27 +39,22 @@ class RunPromise(GenericPromise): ...@@ -71,27 +39,22 @@ class RunPromise(GenericPromise):
return return
amarisoft_stats_log = self.getConfig('amarisoft-stats-log') amarisoft_stats_log = self.getConfig('amarisoft-stats-log')
stats_period = int(self.getConfig('stats-period')) stats_period = int(self.getConfig('stats-period'))
min_rxtx_delay_threshold = float(self.getConfig('min-rxtx-delay', 5)) min_rxtx_delay_threshold = float(self.getConfig('min-rxtx-delay', 0))
avg_rxtx_delay_threshold = float(self.getConfig('avg-rxtx-delay', 7))
data_list = get_data_interval(amarisoft_stats_log, stats_period * 2) data_list = get_json_log_data_interval(amarisoft_stats_log, stats_period * 2)
min_rxtx_delay_it = filter(lambda x: float(x['rf']['rxtx_delay_min']), data_list) min_rxtx_delay_it = filter(lambda x: float(x['rf']['rxtx_delay_min']), data_list)
avg_rxtx_delay_it = filter(lambda x: float(x['rf']['rxtx_delay_avg']), data_list) if not min_rxtx_delay_it:
if not min_rxtx_delay_it or not avg_rxtx_delay_it:
self.logger.error("No TX/RX diff data available") self.logger.error("No TX/RX diff data available")
else: else:
min_rxtx_delay = min(min_rxtx_delay_it) min_rxtx_delay = min(min_rxtx_delay_it)
avg_rxtx_delay = min(avg_rxtx_delay_it)
if min_rxtx_delay > min_rxtx_delay_threshold: if min_rxtx_delay > min_rxtx_delay_threshold:
self.logger.error("The minimum available time %s (ms) for radio front end processing is higher than a threshold %s (ms) depending on the radio front end." % (min_rxtx_delay, min_rxtx_delay_threshold)) self.logger.error("The minimum available time %s (ms) for radio front end processing is lower than the threshold %s (ms)." % (min_rxtx_delay, min_rxtx_delay_threshold))
if avg_rxtx_delay > avg_rxtx_delay_threshold:
self.logger.error("The average available time %s (ms) for radio front end processing is higher than a threshold %s (ms) depending on the radio front end." % (avg_rxtx_delay, avg_rxtx_delay_threshold))
else: else:
self.logger.info("The minimum %s (ms) and average %s (ms) available time for radio front end processing OK" % (min_rxtx_delay, avg_rxtx_delay)) self.logger.info("The minimum %s (ms) available time for radio front end processing is OK" % (min_rxtx_delay,))
self.json_logger.info("Minimum and average available time for radio front end processing (ms)", self.json_logger.info("Minimum available time for radio front end processing (ms)",
extra={'data': {'min_rxtx_delay': min_rxtx_delay, 'avg_rxtx_delay': avg_rxtx_delay}}) extra={'data': {'min_rxtx_delay': min_rxtx_delay}})
def test(self): def test(self):
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment