Merge pull request #248925 from FugiMuffi/prometheus-sabnzbd-exporter

prometheus-sabnzbd-exporter: init at 0.1.70
This commit is contained in:
WilliButz
2023-09-25 12:09:36 +02:00
committed by GitHub
5 changed files with 125 additions and 0 deletions
@@ -68,6 +68,7 @@ let
"redis"
"rspamd"
"rtl_433"
"sabnzbd"
"scaphandre"
"script"
"shelly"
@@ -0,0 +1,47 @@
{ config, lib, pkgs, options }:
let
inherit (lib) mkOption types;
cfg = config.services.prometheus.exporters.sabnzbd;
in
{
port = 9387;
extraOpts = {
servers = mkOption {
description = "List of sabnzbd servers to connect to.";
type = types.listOf (types.submodule {
options = {
baseUrl = mkOption {
type = types.str;
description = "Base URL of the sabnzbd server.";
example = "http://localhost:8080/sabnzbd";
};
apiKeyFile = mkOption {
type = types.str;
description = "File containing the API key.";
example = "/run/secrets/sabnzbd_apikey";
};
};
});
};
};
serviceOpts =
let
servers = lib.zipAttrs cfg.servers;
apiKeys = lib.concatStringsSep "," (builtins.map (file: "$(cat ${file})") servers.apiKeyFile);
in
{
environment = {
METRICS_PORT = toString cfg.port;
METRICS_ADDR = cfg.listenAddress;
SABNZBD_BASEURLS = lib.concatStringsSep "," servers.baseUrl;
};
script = ''
export SABNZBD_APIKEYS="${apiKeys}"
exec ${lib.getExe pkgs.prometheus-sabnzbd-exporter}
'';
};
}
+38
View File
@@ -1178,6 +1178,44 @@ let
'';
};
sabnzbd = {
exporterConfig = {
enable = true;
servers = [{
baseUrl = "http://localhost:8080";
apiKeyFile = "/var/sabnzbd-apikey";
}];
};
metricProvider = {
services.sabnzbd.enable = true;
# unrar is required for sabnzbd
nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (pkgs.lib.getName pkg) [ "unrar" ];
# extract the generated api key before starting
systemd.services.sabnzbd-apikey = {
requires = [ "sabnzbd.service" ];
after = [ "sabnzbd.service" ];
requiredBy = [ "prometheus-sabnzbd-exporter.service" ];
before = [ "prometheus-sabnzbd-exporter.service" ];
script = ''
grep -Po '^api_key = \K.+' /var/lib/sabnzbd/sabnzbd.ini > /var/sabnzbd-apikey
'';
};
};
exporterTest = ''
wait_for_unit("sabnzbd.service")
wait_for_unit("prometheus-sabnzbd-exporter.service")
wait_for_open_port(8080)
wait_for_open_port(9387)
wait_until_succeeds(
"curl -sSf 'localhost:9387/metrics' | grep 'sabnzbd_queue_size{sabnzbd_instance=\"http://localhost:8080\"} 0.0'"
)
'';
};
scaphandre = {
exporterConfig = {
enable = true;
@@ -0,0 +1,38 @@
{ lib, fetchFromGitHub, python3Packages }:
python3Packages.buildPythonApplication rec {
pname = "sabnzbd_exporter";
version = "0.1.70";
format = "other";
src = fetchFromGitHub {
owner = "msroest";
repo = pname;
rev = version;
hash = "sha256-FkZAWIIlGX2VxRL3WS5J9lBgToQGbEQUqvf0xcdvynk=";
};
propagatedBuildInputs = with python3Packages; [ prometheus-client requests ];
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp sabnzbd_exporter.py $out/bin/
mkdir -p $out/share/${pname}
cp examples/* $out/share/${pname}/
runHook postInstall
'';
meta = with lib; {
description = "Prometheus exporter for sabnzbd";
homepage = "https://github.com/msroest/sabnzbd_exporter";
license = licenses.mit;
maintainers = with maintainers; [ fugi ];
platforms = platforms.all;
mainProgram = "sabnzbd_exporter.py";
};
}
+1
View File
@@ -27356,6 +27356,7 @@ with pkgs;
prometheus-redis-exporter = callPackage ../servers/monitoring/prometheus/redis-exporter.nix { };
prometheus-rabbitmq-exporter = callPackage ../servers/monitoring/prometheus/rabbitmq-exporter.nix { };
prometheus-rtl_433-exporter = callPackage ../servers/monitoring/prometheus/rtl_433-exporter.nix { };
prometheus-sabnzbd-exporter = callPackage ../servers/monitoring/prometheus/sabnzbd-exporter.nix { };
prometheus-sachet = callPackage ../servers/monitoring/prometheus/sachet.nix { };
prometheus-script-exporter = callPackage ../servers/monitoring/prometheus/script-exporter.nix { };
prometheus-shelly-exporter = callPackage ../servers/monitoring/prometheus/shelly-exporter.nix { };