Skip to content
Snippets Groups Projects
Commit 248c7481 authored by David Schmitz's avatar David Schmitz
Browse files

snmpstats: add info about duration of last polling

parent 2228d48a
Branches
Tags
No related merge requests found
...@@ -167,11 +167,22 @@ def load_history(): ...@@ -167,11 +167,22 @@ def load_history():
try: try:
with open(settings.SNMP_TEMP_FILE, "r") as f: with open(settings.SNMP_TEMP_FILE, "r") as f:
history = json.load(f) history = json.load(f)
f.close()
except: except:
logger.info("There is no file with SNMP historical data.") logger.info("There is no file with SNMP historical data.")
pass pass
return history return history
# TODO: need locking for ro access?
def get_last_msrm_delay_time():
last_msrm_delay_time = ""
try:
history = load_history()
last_msrm_delay_time = history['_last_msrm_delay_time']
except Exception as e:
logger.info("get_last_msrm_delay_time(): got exception: "+str(e))
return last_msrm_delay_time
def save_history(history, nowstr): def save_history(history, nowstr):
# store updated history # store updated history
tf = settings.SNMP_TEMP_FILE + "." + nowstr tf = settings.SNMP_TEMP_FILE + "." + nowstr
...@@ -218,6 +229,9 @@ def poll_snmp_statistics(): ...@@ -218,6 +229,9 @@ def poll_snmp_statistics():
# load history # load history
history = load_history() history = load_history()
now2 = datetime.now()
msrm_delay_time = now2 - now
zero_measurement = { "bytes" : 0, "packets" : 0 } zero_measurement = { "bytes" : 0, "packets" : 0 }
null_measurement = 0 null_measurement = 0
...@@ -228,8 +242,10 @@ def poll_snmp_statistics(): ...@@ -228,8 +242,10 @@ def poll_snmp_statistics():
except Exception as e: except Exception as e:
logger.info("poll_snmp_statistics(): got exception while trying to access history[_last_poll_time]: "+str(e)) logger.info("poll_snmp_statistics(): got exception while trying to access history[_last_poll_time]: "+str(e))
last_poll_no_time=None last_poll_no_time=None
logger.info("poll_snmp_statistics(): snmpstats: msrm_delay_time="+str(msrm_delay_time))
logger.info("poll_snmp_statistics(): snmpstats: last_poll_no_time="+str(last_poll_no_time)) logger.info("poll_snmp_statistics(): snmpstats: last_poll_no_time="+str(last_poll_no_time))
history['_last_poll_no_time']=nowstr history['_last_poll_no_time']=nowstr
history['_last_msrm_delay_time']=str(msrm_delay_time)
try: try:
history_per_rule = history['_per_rule'] history_per_rule = history['_per_rule']
...@@ -255,7 +271,7 @@ def poll_snmp_statistics(): ...@@ -255,7 +271,7 @@ def poll_snmp_statistics():
toremove = [] toremove = []
for rule in history: for rule in history:
try: try:
if rule!='_last_poll_no_time' and rule!="_per_rule": if len(rule)>0 and rule[0]!='_':
#ts = datetime.strptime(history[rule][0]["ts"], '%Y-%m-%dT%H:%M:%S.%f') #ts = datetime.strptime(history[rule][0]["ts"], '%Y-%m-%dT%H:%M:%S.%f')
ts = helper_stats_store_parse_ts(history[rule][0]["ts"]) ts = helper_stats_store_parse_ts(history[rule][0]["ts"])
if ts!=None and (now - ts).total_seconds() >= settings.SNMP_REMOVE_RULES_AFTER: if ts!=None and (now - ts).total_seconds() >= settings.SNMP_REMOVE_RULES_AFTER:
...@@ -268,7 +284,7 @@ def poll_snmp_statistics(): ...@@ -268,7 +284,7 @@ def poll_snmp_statistics():
if settings.STATISTICS_PER_MATCHACTION_ADD_FINAL_ZERO == True: if settings.STATISTICS_PER_MATCHACTION_ADD_FINAL_ZERO == True:
# for now workaround for low-level rules (by match params, not FoD rule id) no longer have data, typically because of haveing been deactivated # for now workaround for low-level rules (by match params, not FoD rule id) no longer have data, typically because of haveing been deactivated
for rule in history: for rule in history:
if rule!='_last_poll_no_time' and rule!="_per_rule": if len(rule)>0 and rule[0]!='_':
ts = history[rule][0]["ts"] ts = history[rule][0]["ts"]
if ts!=nowstr and ts==last_poll_no_time: if ts!=nowstr and ts==last_poll_no_time:
counter = {"ts": nowstr, "value": null_measurement } counter = {"ts": nowstr, "value": null_measurement }
......
...@@ -52,6 +52,8 @@ from flowspec.helpers import send_new_mail, get_peer_techc_mails ...@@ -52,6 +52,8 @@ from flowspec.helpers import send_new_mail, get_peer_techc_mails
import datetime import datetime
import os import os
from flowspec.snmpstats import load_history, get_last_msrm_delay_time
LOG_FILENAME = os.path.join(settings.LOG_FILE_LOCATION, 'celery_jobs.log') LOG_FILENAME = os.path.join(settings.LOG_FILE_LOCATION, 'celery_jobs.log')
# FORMAT = '%(asctime)s %(levelname)s: %(message)s' # FORMAT = '%(asctime)s %(levelname)s: %(message)s'
# logging.basicConfig(format=FORMAT) # logging.basicConfig(format=FORMAT)
...@@ -833,9 +835,11 @@ def routedetails(request, route_slug): ...@@ -833,9 +835,11 @@ def routedetails(request, route_slug):
route = get_object_or_404(Route, name=route_slug) route = get_object_or_404(Route, name=route_slug)
#return render(request, 'flowspy/route_details.html', {'route': route}) #return render(request, 'flowspy/route_details.html', {'route': route})
now = datetime.datetime.now() now = datetime.datetime.now()
last_msrm_delay_time = get_last_msrm_delay_time()
return render(request, 'flowspy/route_details.html', { return render(request, 'flowspy/route_details.html', {
'route': route, 'route': route,
'mytime': now, 'mytime': now,
'last_msrm_delay_time': last_msrm_delay_time,
'tz' : settings.TIME_ZONE, 'tz' : settings.TIME_ZONE,
'route_comments_len' : len(str(route.comments)) 'route_comments_len' : len(str(route.comments))
}) })
...@@ -847,9 +851,10 @@ def routestats(request, route_slug): ...@@ -847,9 +851,10 @@ def routestats(request, route_slug):
import time import time
res = {} res = {}
try: try:
with open(settings.SNMP_TEMP_FILE, "r") as f: #with open(settings.SNMP_TEMP_FILE, "r") as f:
res = json.load(f) # res = json.load(f)
f.close() #f.close()
res = load_history()
routename = create_junos_name(route) routename = create_junos_name(route)
route_id = str(route.id) route_id = str(route.id)
if not res: if not res:
......
...@@ -84,7 +84,7 @@ function myreloadPage() { ...@@ -84,7 +84,7 @@ function myreloadPage() {
</div> </div>
<div> <div>
<h2>Statistics</h2> <h2>Statistics</h2>
<div>(all times are in {{ tz }}; current System time: {{ mytime|date:'Y-m-d H:i' }}, active rules will be updated every 5 minutes)</div> <div>(all times are in {{ tz }}; current System time: {{ mytime|date:'Y-m-d H:i' }}, active rules will be updated every 5 minutes, last duration for measurement was {{ last_msrm_delay_time }})</div>
<div><span id="traffic-plot-loading">(Loading data...)</span> <div><span id="traffic-plot-loading">(Loading data...)</span>
<h3>Number of packets (absolute)</h3> <h3>Number of packets (absolute)</h3>
<div><canvas id="traffic-plot-pkts-abs" width=200 height=200></canvas></div> <div><canvas id="traffic-plot-pkts-abs" width=200 height=200></canvas></div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment