From 1d56410e2693af5ab27b3a6c9d789e48e515b76b Mon Sep 17 00:00:00 2001 From: sinavir Date: Sun, 9 Jun 2024 15:27:25 +0200 Subject: [PATCH] org: patch kfet monitoring --- machines/hackens-org/kfet-monitor/patch | 61 +++++++++++++++++++ .../kfet-monitor/websocket-exporter.nix | 4 ++ machines/hackens-org/prometheus.nix | 2 +- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 machines/hackens-org/kfet-monitor/patch diff --git a/machines/hackens-org/kfet-monitor/patch b/machines/hackens-org/kfet-monitor/patch new file mode 100644 index 0000000..d207b11 --- /dev/null +++ b/machines/hackens-org/kfet-monitor/patch @@ -0,0 +1,61 @@ +diff --git a/websocket_exporter/probe.py b/websocket_exporter/probe.py +index a95b97e..a7b057e 100644 +--- a/websocket_exporter/probe.py ++++ b/websocket_exporter/probe.py +@@ -3,28 +3,29 @@ import logging + from time import perf_counter + from typing import Union + +-from websockets import NegotiationError, client, InvalidStatusCode ++from websockets import InvalidStatusCode, NegotiationError, client + +- +-EXACT_MATCH = 'exact' +-CONTAINS_MATCH = 'contains' ++EXACT_MATCH = "exact" ++CONTAINS_MATCH = "contains" + + + class ProbResults(object): + def __init__(self, up: int, latency: float = 0, received: int = 0): + self.up = up + self.latency = round(latency, 2) +- self.received = int(received) if received is not None else "NaN" ++ self.received = int(received) if received is not None else 0 + + def __str__(self): + if self.up: + return f'Websocket up, latency:{self.latency}s, expected response {"" if self.received else "NOT"} received' +- return f'Webserver DOWN' ++ return f"Webserver DOWN" + + + class WebSocketProbe(object): + +- def __init__(self, uri, message=None, expected=None, match=CONTAINS_MATCH, timeout=10): ++ def __init__( ++ self, uri, message=None, expected=None, match=CONTAINS_MATCH, timeout=10 ++ ): + """ + Create a websocket probe that tries establishing a connection and reports the metrics + :param uri: starts with 'ws://' or ws:// +@@ -68,13 +69,17 @@ class WebSocketProbe(object): + elapsed = 0 + while elapsed < self.timeout: + try: +- resp = await asyncio.wait_for(connection.recv(), timeout=(self.timeout-elapsed)) ++ resp = await asyncio.wait_for( ++ connection.recv(), timeout=(self.timeout - elapsed) ++ ) + if self._match(resp): + return True + await asyncio.sleep(1) + elapsed += 1 + except asyncio.TimeoutError: +- logging.info(f'Time out while waiting for {self.expected_message} from {self.uri}') ++ logging.info( ++ f"Time out while waiting for {self.expected_message} from {self.uri}" ++ ) + return None + return None + diff --git a/machines/hackens-org/kfet-monitor/websocket-exporter.nix b/machines/hackens-org/kfet-monitor/websocket-exporter.nix index 5f4d1bb..76961cf 100644 --- a/machines/hackens-org/kfet-monitor/websocket-exporter.nix +++ b/machines/hackens-org/kfet-monitor/websocket-exporter.nix @@ -15,6 +15,10 @@ python3.pkgs.buildPythonApplication rec { hash = "sha256-+G7xw5631TllDGNzVK9swbSNfVu4r4glbYIblEa0WqA="; }; + patches = [ + ./patch + ]; + nativeBuildInputs = [ python3.pkgs.setuptools python3.pkgs.wheel diff --git a/machines/hackens-org/prometheus.nix b/machines/hackens-org/prometheus.nix index 8e5c1c1..b766d0f 100644 --- a/machines/hackens-org/prometheus.nix +++ b/machines/hackens-org/prometheus.nix @@ -22,7 +22,7 @@ in retentionTime = "5y"; - extraFlags = "--storage.tsdb.retention.size=2GB"; + extraFlags = [ "--storage.tsdb.retention.size=2GB" ]; rules = [ '' groups: