diff --git a/machines/thorite/monitoring.nix b/machines/thorite/monitoring.nix index afb0b6e..e02ecad 100644 --- a/machines/thorite/monitoring.nix +++ b/machines/thorite/monitoring.nix @@ -13,6 +13,7 @@ let grafanaUrl ntfyUrl internalDomain + transmissionExporterUrl ; removeHttps = s: lib.removePrefix "https://" s; in @@ -154,6 +155,24 @@ in address = "thorite.coho-tet.ts.net"; port = 3100; } + { + name = "transmission"; + scheme = "http"; + address = transmissionExporterUrl; + port = 19091; + } + { + name = "sonarr"; + scheme = "http"; + address = "weilite.${internalDomain}"; + port = 21560; + } + { + name = "radarr"; + scheme = "http"; + address = "weilite.${internalDomain}"; + port = 21561; + } ]) ++ (mkCaddyScrapes [ { address = "thorite.coho-tet.ts.net"; } diff --git a/machines/weilite/secrets.yaml b/machines/weilite/secrets.yaml index 0e63460..0fc2813 100644 --- a/machines/weilite/secrets.yaml +++ b/machines/weilite/secrets.yaml @@ -7,6 +7,10 @@ restic: localpass: ENC[AES256_GCM,data:GIQAmkpDmGu4+sSG5/b5yQ==,iv:dcu6F8NnVjeQzEG2vM3fOV5owI0PWc86ts20UP3vN18=,tag:vsG8x062FG1pH5YNcAajeg==,type:str] transmission: rpc-password: ENC[AES256_GCM,data:4dumy0hygGOuwU3ANky3xEKRDRBAJWE=,iv:HVV2J+F8HndHZNsMD2YmkWrJOzk5JIapGd0SuQP8VqU=,tag:xqp5pxh5cYYogA4alrmIfg==,type:str] +sonarr: + api-key: ENC[AES256_GCM,data:/CkApTCLQy8TLHGKSM1saacNi9uQDswAjshRSLJk1hg=,iv:PNX4BZLx7krs12lxgORMSarnt0c/ga8yPtoLSzbQ+sY=,tag:V1pp9OCtX5/5fbwLBMGlOQ==,type:str] +radarr: + api-key: ENC[AES256_GCM,data:AeJArngvgmqnxk2g13QjMa6XS893B+3ZdX2K8OqXRQg=,iv:NrQf3yyqRpHMeWQ3bpPH4fUDdo/x2uB6pQCq0ZrFP5c=,tag:Yj2PSy6zRfe8anW0RGuZAQ==,type:str] sops: kms: [] gcp_kms: [] @@ -31,8 +35,8 @@ sops: V0thRjU4WGpQRGFpcnoxSjZTZHhTTkUKzNMHh9p7GUY3hL5XZ9S4x20CwaItsXFV RKujsFVVBd8Kuq/jyOCBTRCscuHI4LW/wYeZYHFEZFSTK2liAqspgw== -----END AGE ENCRYPTED FILE----- - lastmodified: "2025-02-01T15:54:35Z" - mac: ENC[AES256_GCM,data:hDX2lQ5GbBGTqioEqNc/k4NvBW7/3ISOVUk8/6CkuW6ZQHUeMnfziWV7faw+DiMvYmwFUJ4mhY77Je5+gid0Ae5JyNxznBW2uzpXvLcTBsYz8iSZL6Jw5FciPIgkGDN5U5wMkusS6Ok2W/idIgmwlmxf3ACNaf7e0QpypwYwxZw=,iv:mkIQ2rvTpQXRuRarlcl/aIKDY3JmJKVsr1oS4+3vmnk=,tag:of2CSCqZAJaaZ5DvC6+Amg==,type:str] + lastmodified: "2025-02-11T08:45:49Z" + mac: ENC[AES256_GCM,data:iObzkfSxKET1kE8yQbSxffG1qDO95SWfIRSdwbYcwP4mHOrl5sOtlGEjexVaLl7uKa0SMCK6BghbMr4EdLatiOmngsAzr8bxe/GsPZiCze04nr0VbKBgHxKr74gT8d14dwV+Y+np/5fgRZea7zxzJ4YaVfeUOG9PBsa7L6RWbx0=,iv:LMM096xLa5cOiLVTiFO20jBUaK1Uw4aOqsz7eH9u9vc=,tag:C1fPHN9KFbydcy1lRAhGvQ==,type:str] pgp: [] unencrypted_suffix: _unencrypted version: 3.9.2 diff --git a/machines/weilite/services/media-download.nix b/machines/weilite/services/media-download.nix index cc5657e..97c7110 100644 --- a/machines/weilite/services/media-download.nix +++ b/machines/weilite/services/media-download.nix @@ -1,5 +1,14 @@ { config, pkgs, ... }: +let + inherit (config.my-lib.settings) + internalDomain + ; +in { + sops.secrets = { + "sonarr/api-key" = { }; + "radarr/api-key" = { }; + }; services.jackett = { enable = true; openFirewall = false; @@ -20,6 +29,22 @@ enable = true; }; + services.prometheus.exporters.exportarr-sonarr = { + enable = true; + url = "http://127.0.0.1:8989"; + apiKeyFile = config.sops.secrets."sonarr/api-key".path; + listenAddress = "weilite.${internalDomain}"; + port = 21560; + }; + + services.prometheus.exporters.exportarr-radarr = { + enable = true; + url = "http://127.0.0.1:7878"; + apiKeyFile = config.sops.secrets."radarr/api-key".path; + listenAddress = "weilite.${internalDomain}"; + port = 21561; + }; + users.groups.media.members = [ config.services.sonarr.user config.services.radarr.user diff --git a/machines/weilite/services/transmission.nix b/machines/weilite/services/transmission.nix index b025819..0c1e969 100644 --- a/machines/weilite/services/transmission.nix +++ b/machines/weilite/services/transmission.nix @@ -1,6 +1,12 @@ -{ config, pkgs, ... }: +{ + config, + pkgs, + lib, + ... +}: let cfg = config.services.transmission; + inherit (config.my-lib.settings) transmissionExporterUrl; in { sops.secrets = { @@ -13,6 +19,12 @@ in }; }; + sops.templates."transmission-cred.env" = { + content = '' + TRANSMISSION_PASSWORD=${config.sops.placeholder."transmission/rpc-password"} + ''; + }; + services.transmission = { enable = true; package = pkgs.transmission_4; @@ -64,6 +76,22 @@ in services.caddy.virtualHosts."https://weilite.coho-tet.ts.net:9091".extraConfig = '' reverse_proxy 127.0.0.1:${toString cfg.settings.rpc-port} ''; + + systemd.services.prometheus-transmission-exporter = { + enable = true; + wantedBy = [ "transmission.service" ]; + environment = { + WEB_ADDR = transmissionExporterUrl; + TRANSMISSION_ADDR = "http://127.0.0.1:${toString cfg.settings.rpc-port}"; + TRANSMISSION_USERNAME = "xin"; + }; + after = [ "tailscaled.service" ]; + serviceConfig = { + ExecStart = "${lib.getExe pkgs.transmission-exporter}"; + EnvironmentFile = config.sops.templates."transmission-cred.env".path; + }; + }; + networking.firewall.allowedTCPPorts = [ 9091 ]; # allow on lan users.groups.media.members = [ cfg.user ]; } diff --git a/overlays/add-pkgs.nix b/overlays/add-pkgs.nix index f1b214e..ac76b8e 100644 --- a/overlays/add-pkgs.nix +++ b/overlays/add-pkgs.nix @@ -9,4 +9,6 @@ "idbloader.img" ]; }; + + transmission-exporter = prev.callPackage ./pkgs/transmission-exporter.nix { }; }) diff --git a/overlays/my-lib/settings.nix b/overlays/my-lib/settings.nix index be97568..e4a219f 100644 --- a/overlays/my-lib/settings.nix +++ b/overlays/my-lib/settings.nix @@ -13,6 +13,8 @@ synapseUrl = "https://xiny.li"; synapseDelegateUrl = "https://synapse.xiny.li"; + transmissionExporterUrl = "weilite.coho-tet.ts.net:19091"; + prometheusCollectors = [ "thorite.coho-tet.ts.net" ]; diff --git a/overlays/pkgs/transmission-exporter.nix b/overlays/pkgs/transmission-exporter.nix new file mode 100644 index 0000000..b5e70b8 --- /dev/null +++ b/overlays/pkgs/transmission-exporter.nix @@ -0,0 +1,32 @@ +{ + lib, + fetchFromGitHub, + buildGoModule, +}: +buildGoModule rec { + pname = "transmission-exporter"; + version = "0-unstable-2024-10-09"; + rev = "v${version}"; + + src = fetchFromGitHub { + rev = "a7872aa2975c7a95af680c51198f4a363e226c8f"; + owner = "metalmatze"; + repo = "transmission-exporter"; + sha256 = "sha256-Ky7eCvC1AqHheqGGOGBNKbtVgg4Y8hDG67gCVlpUwZo="; + }; + + vendorHash = "sha256-YhmfrM5iAK0zWcUM7LmbgFnH+k2M/tE+f/QQIQmQlZs="; + + ldflags = [ + "-X github.com/prometheus/common/version.Version=${version}" + "-X github.com/prometheus/common/version.Revision=${rev}" + ]; + + meta = { + description = "Prometheus exporter for Transmission torrent client."; + homepage = "https://github.com/pborzenkov/transmission-exporter"; + mainProgram = "transmission-exporter"; + license = [ lib.licenses.mit ]; + maintainers = [ lib.maintainers.xinyangli ]; + }; +}