From 22ba6b0237d4f0a568892b5f06f6484117f149d2 Mon Sep 17 00:00:00 2001 From: sinavir Date: Sat, 13 Apr 2024 23:40:41 +0200 Subject: [PATCH] org: monitor kfet --- machines/hackens-org/_configuration.nix | 1 + machines/hackens-org/kfet-monitor/default.nix | 25 +++++++++++++ .../kfet-monitor/websocket-exporter.nix | 35 +++++++++++++++++++ machines/hackens-org/prometheus.nix | 8 +++++ 4 files changed, 69 insertions(+) create mode 100644 machines/hackens-org/kfet-monitor/default.nix create mode 100644 machines/hackens-org/kfet-monitor/websocket-exporter.nix diff --git a/machines/hackens-org/_configuration.nix b/machines/hackens-org/_configuration.nix index 68ffe69..cdb1245 100644 --- a/machines/hackens-org/_configuration.nix +++ b/machines/hackens-org/_configuration.nix @@ -22,6 +22,7 @@ ./webpass.nix ./prometheus.nix ./grafana.nix + ./kfet-monitor ]; time.timeZone = "Europe/Paris"; diff --git a/machines/hackens-org/kfet-monitor/default.nix b/machines/hackens-org/kfet-monitor/default.nix new file mode 100644 index 0000000..5fef9e0 --- /dev/null +++ b/machines/hackens-org/kfet-monitor/default.nix @@ -0,0 +1,25 @@ +{ lib, pkgs, ...}: +let + wsScraper = pkgs.callPackage ./websocket-exporter.nix {}; +in +{ + systemd.services.kfet-open-recorder = { + environment = { + WEBSOCKET_EXPORTER_URI = "wss://cof.ens.fr/ws/k-fet/open"; + WEBSOCKET_EXPORTER_MATCH_TYPE = "contains"; + WEBSOCKET_EXPORTER_EXPECTED_MESSAGE = "open"; + WEBSOCKET_EXPORTER_LISTEN_ADDR = "127.0.0.1"; + }; + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + wants = [ "network.target" ]; + + serviceConfig = { + ExecStart = "${lib.getExe wsScraper}"; + Restart = "always"; + RestartSec = 5; + DynamicUser = true; + StateDirectory = "kfet-open-recorder"; + }; + }; +} diff --git a/machines/hackens-org/kfet-monitor/websocket-exporter.nix b/machines/hackens-org/kfet-monitor/websocket-exporter.nix new file mode 100644 index 0000000..5f4d1bb --- /dev/null +++ b/machines/hackens-org/kfet-monitor/websocket-exporter.nix @@ -0,0 +1,35 @@ +{ lib +, python3 +, fetchFromGitHub +}: + +python3.pkgs.buildPythonApplication rec { + pname = "blackbox-websocket-exporter"; + version = "unstable-2021-12-15"; + pyproject = true; + + src = fetchFromGitHub { + owner = "smohsensh"; + repo = "blackbox-websocket-exporter"; + rev = "6f9f32396f740fe606bf1b0118a27ad5caa3d9a6"; + hash = "sha256-+G7xw5631TllDGNzVK9swbSNfVu4r4glbYIblEa0WqA="; + }; + + nativeBuildInputs = [ + python3.pkgs.setuptools + python3.pkgs.wheel + ]; + + propagatedBuildInputs = with python3.pkgs; [ + prometheus-client + websockets + ]; + + meta = with lib; { + description = "A Blackbox Websocket Uptime Exporter for Prometheus"; + homepage = "https://github.com/smohsensh/blackbox-websocket-exporter"; + license = licenses.mit; + maintainers = with maintainers; [ ]; + mainProgram = "websocket_exporter"; + }; +} diff --git a/machines/hackens-org/prometheus.nix b/machines/hackens-org/prometheus.nix index 8e92c98..8e5c1c1 100644 --- a/machines/hackens-org/prometheus.nix +++ b/machines/hackens-org/prometheus.nix @@ -20,6 +20,10 @@ in webExternalUrl = "https://${host}"; + retentionTime = "5y"; + + extraFlags = "--storage.tsdb.retention.size=2GB"; + rules = [ '' groups: - name: Chrony @@ -42,6 +46,10 @@ in job_name = "chrony"; static_configs = [ { targets = [ "10.10.10.3:9123" ]; } ]; } + { + job_name = "kfet"; + static_configs = [ { targets = [ "127.0.0.1:9802" ]; } ]; + } ]; };