diff --git a/morph/lib/storage.nix b/morph/lib/storage.nix index 86e142286351237099337d38d03a9b54255b8246..15e2373737a7ff2f1efe8cf2c41b59de606f0a1a 100644 --- a/morph/lib/storage.nix +++ b/morph/lib/storage.nix @@ -43,8 +43,12 @@ in { ../../nixos/modules/monitoring/vpn/client.nix # Expose base system metrics over the monitoringvpn. ../../nixos/modules/monitoring/exporters/node.nix + # Collect Tahoe OpenMetrics statistics. + ../../nixos/modules/monitoring/exporters/tahoe.nix ]; + services.private-storage.monitoring.tahoe.enable = true; + # Turn on the Private Storage (Tahoe-LAFS) service. services.private-storage = { # Yep. Turn it on. diff --git a/nixos/modules/monitoring/exporters/tahoe.nix b/nixos/modules/monitoring/exporters/tahoe.nix new file mode 100644 index 0000000000000000000000000000000000000000..f63c21e3b0861c9ddeb94a3b4784a8d8a78d9377 --- /dev/null +++ b/nixos/modules/monitoring/exporters/tahoe.nix @@ -0,0 +1,59 @@ +# Tahoe Prometheus metrics collector +# +# Scope: Retrieves OpenMetrics from Tahoe and puts them +# where textfile collector can find them. +# +# Usage: Import this to every server running Tahoe. +# +# See https://nixos.org/manual/nixos/stable/#module-services-prometheus-exporters + +{ config, options, lib, ourpkgs, pkgs, ... }: + +let + cfg = config.services.private-storage.monitoring.tahoe; + +in { + options.services.private-storage.monitoring.tahoe = { + enable = lib.mkEnableOption "Tahoe OpenMetrics collecting service"; + scrapeEndpoint = lib.mkOption { + type = lib.types.str; + description = "Where to get our metrics from?"; + default = "http://localhost:3456/statistics?t=openmetrics"; + }; + outFile = lib.mkOption { + type = lib.types.str; + description = "Where to store the temporary file for node exporter to scrape?"; + default = "/run/prometheus-node-exporter/tahoe.prom"; + }; + interval = lib.mkOption { + type = lib.types.str; + description = '' + How often to do it? + See https://www.freedesktop.org/software/systemd/man/systemd.time.html#Calendar%20Events + ''; + # Every five minutes. + default = "*:0/5"; + }; + }; + + config = + lib.mkIf cfg.enable { + environment.systemPackages = [ pkgs.curl ]; + systemd.services.tahoe-metrics-collector = { + enable = true; + description = "Tahoe metrics gathering service"; + wantedBy = [ "multi-user.target" ]; + startAt = cfg.interval; + path = [ pkgs.curl ]; + + # Curl to a temp file and then move atomically so textfile collector + # won't read a partial file. + # See https://github.com/prometheus/node_exporter#textfile-collector + script = '' + curl --silent --show-error --fail-with-body --output "${cfg.outFile}.tmp" "${cfg.scrapeEndpoint}" + mv "${cfg.outFile}.tmp" "${cfg.outFile}" + ''; + }; + }; +} +