nixos/prometheus-sabnzbd-exporter: init
This commit is contained in:
parent
c2d5ed9744
commit
5e75b36302
|
@ -67,6 +67,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}
|
||||
'';
|
||||
};
|
||||
}
|
|
@ -1143,6 +1143,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;
|
||||
|
|
Loading…
Reference in a new issue