Skip to content

Commit

Permalink
prometheus.exporters.qbittorrent: init
Browse files Browse the repository at this point in the history
  • Loading branch information
milahu committed Sep 20, 2024
1 parent 25ae33d commit 3f7b4f1
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
11 changes: 11 additions & 0 deletions nixos/modules/services/monitoring/prometheus/exporters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ let
"process"
"pve"
"py-air-control"
"qbittorrent"
"redis"
"restic"
"rspamd"
Expand Down Expand Up @@ -441,6 +442,16 @@ in
echo "DELUGE_PASSWORD=$(cat ${config.services.prometheus.exporters.deluge.delugePasswordFile})" > /etc/deluge-exporter/password
'';
};
})] ++ [(mkIf (
config.services.prometheus.exporters.qbittorrent.enable &&
config.services.prometheus.exporters.qbittorrent.qbittorrentPasswordFile != null
) {
system.activationScripts = {
qbittorrent-exported.text = ''
mkdir -p /etc/qbittorrent-exporter
echo "QBITTORRENT_PASS=$(cat ${config.services.prometheus.exporters.qbittorrent.qbittorrentPasswordFile})" > /etc/qbittorrent-exporter/password
'';
};
})] ++ (mapAttrsToList (name: conf:
mkExporterConf {
inherit name;
Expand Down
100 changes: 100 additions & 0 deletions nixos/modules/services/monitoring/prometheus/exporters/qbittorrent.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# based on nixpkgs/nixos/modules/services/monitoring/prometheus/exporters/deluge.nix

{ config, lib, pkgs, ... }:

let
cfg = config.services.prometheus.exporters.qbittorrent;
inherit (lib) mkOption mkPackageOption types concatStringsSep;

Check failure on line 7 in nixos/modules/services/monitoring/prometheus/exporters/qbittorrent.nix

View workflow job for this annotation

GitHub Actions / exp-nixf-tidy-check

sema-unused-def-let

definition `concatStringsSep` in let-expression is not used
in
{
port = 9355;

extraOpts = {
package = mkPackageOption pkgs "prometheus-qbittorrent-exporter" { };

qbittorrentHost = mkOption {
type = types.str;
default = "localhost";
description = ''
Hostname where qbittorrent is running.
'';
};

qbittorrentPort = mkOption {
type = types.port;
# TODO default?
default = 1952;
description = ''
Port where qbittorrent is listening.
'';
};

qbittorrentUser = mkOption {
type = types.str;
default = "admin";
description = ''
User to connect to qbittorrent.
'';
};

qbittorrentPassword = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Password to connect to qbittorrent.
This stores the password unencrypted in the nix store and is thus considered unsafe. Prefer
using the qbittorrentPasswordFile option.
'';
};

qbittorrentPasswordFile = mkOption {
type = types.nullOr types.path;
default = null;
description = ''
File containing the password to connect to qbittorrent.
'';
};

/*
exportPerTorrentMetrics = mkOption {
type = types.bool;
default = false;
description = ''
Enable per-torrent metrics.
This may significantly increase the number of time series depending on the number of
torrents in your qbittorrent instance.
'';
};
*/
};
serviceOpts = {
serviceConfig = {
ExecStart = ''
${cfg.package}/bin/qbittorrent-exporter
'';
Environment = [
"QBITTORRENT_HOST=${cfg.qbittorrentHost}"
"QBITTORRENT_PORT=${toString cfg.qbittorrentPort}"
# Whether to use SSL to connect or not. Will be forced to True when using port 443
"QBITTORRENT_SSL=False"
# qbittorrent server path or base URL
"QBITTORRENT_URL_BASE="
"QBITTORRENT_USER=${cfg.qbittorrentUser}"
# https://github.com/esanchezm/prometheus-qbittorrent-exporter/issues/41
"EXPORTER_ADDRESS=${toString cfg.listenAddress}"
"EXPORTER_PORT=${toString cfg.port}"
# Log level. One of: DEBUG, INFO, WARNING, ERROR, CRITICAL
"EXPORTER_LOG_LEVEL=INFO"
# Prefix to add to all the metrics
"METRICS_PREFIX=qbittorrent"
# Whether to verify SSL certificate when connecting to the qbittorrent server. Any other value but True will disable the verification
"VERIFY_WEBUI_CERTIFICATE=True"
] ++ lib.optionals (cfg.qbittorrentPassword != null) [
"QBITTORRENT_PASS=${cfg.qbittorrentPassword}"
];
EnvironmentFile = lib.optionalString (cfg.qbittorrentPasswordFile != null) "/etc/qbittorrent-exporter/password";
};
};
}

0 comments on commit 3f7b4f1

Please sign in to comment.