org: monitor kfet

This commit is contained in:
sinavir 2024-04-13 23:40:41 +02:00
parent 20cd845627
commit 22ba6b0237
4 changed files with 69 additions and 0 deletions

View file

@ -22,6 +22,7 @@
./webpass.nix ./webpass.nix
./prometheus.nix ./prometheus.nix
./grafana.nix ./grafana.nix
./kfet-monitor
]; ];
time.timeZone = "Europe/Paris"; time.timeZone = "Europe/Paris";

View file

@ -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";
};
};
}

View file

@ -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";
};
}

View file

@ -20,6 +20,10 @@ in
webExternalUrl = "https://${host}"; webExternalUrl = "https://${host}";
retentionTime = "5y";
extraFlags = "--storage.tsdb.retention.size=2GB";
rules = [ '' rules = [ ''
groups: groups:
- name: Chrony - name: Chrony
@ -42,6 +46,10 @@ in
job_name = "chrony"; job_name = "chrony";
static_configs = [ { targets = [ "10.10.10.3:9123" ]; } ]; static_configs = [ { targets = [ "10.10.10.3:9123" ]; } ];
} }
{
job_name = "kfet";
static_configs = [ { targets = [ "127.0.0.1:9802" ]; } ];
}
]; ];
}; };