diff options
| author | mjkwiatkowski <mati.rewa@gmail.com> | 2026-06-26 13:33:10 +0200 |
|---|---|---|
| committer | mjkwiatkowski <mati.rewa@gmail.com> | 2026-06-26 13:33:10 +0200 |
| commit | 00945a67f551b90c528438bd24b6573abe603050 (patch) | |
| tree | b43025d097a9c70191f570720d993b24a8fcb00b /python_scripts/src | |
| parent | 15a3d5c6f55bec4a39f81f127dd1feec9660ecdc (diff) | |
Diffstat (limited to 'python_scripts/src')
| -rw-r--r-- | python_scripts/src/python_scripts/__main__.py | 25 | ||||
| -rw-r--r-- | python_scripts/src/python_scripts/__pycache__/__main__.cpython-314.pyc | bin | 3850 -> 4058 bytes | |||
| -rw-r--r-- | python_scripts/src/python_scripts/__pycache__/module2.cpython-314.pyc | bin | 1961 -> 1964 bytes | |||
| -rw-r--r-- | python_scripts/src/python_scripts/__pycache__/threshold_based.cpython-314.pyc | bin | 0 -> 1683 bytes | |||
| -rw-r--r-- | python_scripts/src/python_scripts/resources/readme.txt | 5 | ||||
| -rw-r--r-- | python_scripts/src/python_scripts/threshold_based.py (renamed from python_scripts/src/python_scripts/module2.py) | 16 |
6 files changed, 20 insertions, 26 deletions
diff --git a/python_scripts/src/python_scripts/__main__.py b/python_scripts/src/python_scripts/__main__.py index 4760e17c..896c7c3c 100644 --- a/python_scripts/src/python_scripts/__main__.py +++ b/python_scripts/src/python_scripts/__main__.py @@ -1,6 +1,6 @@ import redis import pandas as pd -import module2 +import threshold_based import requests from redis.exceptions import ( ConnectionError, @@ -18,8 +18,6 @@ r = redis.Redis(redis_host) PATH = "/home/matt/src/sunfish/python_scripts/src/python_scripts/resources" threshold = 0 dictionary = {} -alert_dictionary_red = {} -alert_dictionary_yellow = {} def iterate(frame): @@ -62,22 +60,17 @@ As suggested in https://redis.readthedocs.io/en/stable/examples/redis-stream-exa toack = lambda k, g, e: r.xack(k, g, e) -def print_xreadgroup_reply(reply, f): +def print_xreadgroup_reply(reply, f, output_file): global threshold for d_stream in reply: for element in d_stream[1]: - module2.check_metric( - element[1], - f, - threshold, - dictionary, - alert_dictionary_red, - alert_dictionary_yellow, + threshold_based.check_metric( + element[1], f, threshold, dictionary, output_file ) toack(d_stream[0], group, element[0]) -def read_entries(r, f): +def read_entries(r, f, output_file): while True: d = r.xreadgroup( groupname=group, @@ -86,15 +79,17 @@ def read_entries(r, f): count=10, streams={stream_key: ">"}, ) - print_xreadgroup_reply(d, f) + print_xreadgroup_reply(d, f, output_file) def main(): try: frames = create_dataframes() caluclate_threshold(frames[0]) - print(threshold) - read_entries(r, frames[0]) + + with open("output.txt", "w", encoding="utf-8") as f: + f.write(f"Threshold: {threshold}\n") + read_entries(r, frames[0], output_file=f) except Exception as e: print(f"exception caught: {e}") diff --git a/python_scripts/src/python_scripts/__pycache__/__main__.cpython-314.pyc b/python_scripts/src/python_scripts/__pycache__/__main__.cpython-314.pyc Binary files differindex f906b7d3..705a695c 100644 --- a/python_scripts/src/python_scripts/__pycache__/__main__.cpython-314.pyc +++ b/python_scripts/src/python_scripts/__pycache__/__main__.cpython-314.pyc diff --git a/python_scripts/src/python_scripts/__pycache__/module2.cpython-314.pyc b/python_scripts/src/python_scripts/__pycache__/module2.cpython-314.pyc Binary files differindex 4dc64294..a88d583d 100644 --- a/python_scripts/src/python_scripts/__pycache__/module2.cpython-314.pyc +++ b/python_scripts/src/python_scripts/__pycache__/module2.cpython-314.pyc diff --git a/python_scripts/src/python_scripts/__pycache__/threshold_based.cpython-314.pyc b/python_scripts/src/python_scripts/__pycache__/threshold_based.cpython-314.pyc Binary files differnew file mode 100644 index 00000000..8817f209 --- /dev/null +++ b/python_scripts/src/python_scripts/__pycache__/threshold_based.cpython-314.pyc diff --git a/python_scripts/src/python_scripts/resources/readme.txt b/python_scripts/src/python_scripts/resources/readme.txt index f921b523..b00086b8 100644 --- a/python_scripts/src/python_scripts/resources/readme.txt +++ b/python_scripts/src/python_scripts/resources/readme.txt @@ -1,2 +1,7 @@ This is the result of a raw simulation with the failureModels set to some statistical distribution in OpenDC. Based on the downtime in the `host.parquet` file, we calculate the threshold. +These results are based on this failureModel: +{ + "type": "prefab", + "prefabName" : "Pl05Exp" +} diff --git a/python_scripts/src/python_scripts/module2.py b/python_scripts/src/python_scripts/threshold_based.py index 1d54df75..13ce5e42 100644 --- a/python_scripts/src/python_scripts/module2.py +++ b/python_scripts/src/python_scripts/threshold_based.py @@ -5,33 +5,27 @@ import numpy as np """ The threshold should be set based on a OpenDC failure model with statistical distribution. """ -confidence_red = 0.95 +confidence_red = 0.90 confidence_yellow = 0.80 sigma = 0 -def check_metric( - stream, frame, threshold, dictionary, alert_dictionary_red, alert_dictionary_yellow -): +def check_metric(stream, frame, threshold, dictionary, output_file): timestamp = int(stream[b"timestamp"].decode()) host = str(stream[b"host_id"].decode()) dictionary[str(timestamp)] = dictionary.get(str(timestamp), 0) + 1 e_t = dictionary.get(str(timestamp)) - + # Heuristic based recognition if e_t > threshold * confidence_red: - print(f"Red,{timestamp}") - alert_dictionary_red[str(timestamp)] = alert_dictionary_red.get(str(timestamp), 0) + 1 - print(alert_dictionary_red) + output_file.write(f"Timestamp: {timestamp}, Alarm: red\n") alert = {"Name": "Alert", "Type": "Red", "Timestamp": str(timestamp)} alert_dt(alert) return if e_t > threshold * confidence_yellow: - alert_dictionary_yellow[str(timestamp)] = alert_dictionary_yellow.get(str(timestamp), 0) + 1 - print(alert_dictionary_yellow) - print(f"Yellow,{timestamp}") + output_file.write(f"Timestamp: {timestamp}, Alarm: yellow\n") alert = {"Name": "Alert", "Type": "Yellow", "Timestamp": str(timestamp)} alert_dt(alert) |
