Avoid error when no data is available

This commit is contained in:
Martin Kompf 2019-09-24 15:06:21 +02:00
parent dcd1ac89df
commit 05004cbac0
1 changed files with 9 additions and 8 deletions

View File

@ -73,14 +73,15 @@ def detect_pauses(data):
def main(): def main():
#counter = read_fetch_output() #counter = read_fetch_output()
counter = read_rrd() counter = read_rrd()
pauses = detect_pauses(counter) if len(counter) > 0:
if verbose: pauses = detect_pauses(counter)
for p in pauses: if verbose:
print("Pause starting at {0:%Y-%m-%d %H:%M:%S}: {1:.1f} hours" for p in pauses:
.format(datetime.fromtimestamp(p['start']), p['duration']/3600.0)) print("Pause starting at {0:%Y-%m-%d %H:%M:%S}: {1:.1f} hours"
if len(pauses) == 0: .format(datetime.fromtimestamp(p['start']), p['duration']/3600.0))
print("Possible leak detected! There is no break of at least {0} hours." if len(pauses) == 0:
.format(min_pause/3600.0)) print("Possible leak detected! There is no break of at least {0} hours."
.format(min_pause/3600.0))
if __name__ == '__main__': if __name__ == '__main__':
main() main()