diff options
author | Pol Dellaiera <pol.dellaiera@protonmail.com> | 2023-06-28 09:46:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-28 09:46:08 +0200 |
commit | e1b3f7b15902d1f1b7560fd610f98a24821e1759 (patch) | |
tree | ed8297afb1c1a831fd8df70a29399a498ec67cec /nixos | |
parent | 32281c4ae8c9522ab80e2a85776d192dfd631bca (diff) | |
parent | e11f06a9517b306691231e8a4207365e48cc9d5c (diff) |
Merge pull request #239803 from gaelreyrol/prometheus-scaphandre-exporter-init
services/prometheus/exporters: add scaphandre
Diffstat (limited to 'nixos')
4 files changed, 67 insertions, 0 deletions
diff --git a/nixos/doc/manual/release-notes/rl-2311.section.md b/nixos/doc/manual/release-notes/rl-2311.section.md index 66bed591d48e5..c58985132be0e 100644 --- a/nixos/doc/manual/release-notes/rl-2311.section.md +++ b/nixos/doc/manual/release-notes/rl-2311.section.md @@ -76,6 +76,8 @@ - `services.nginx` gained a `defaultListen` option at server-level with support for PROXY protocol listeners, also `proxyProtocol` is now exposed in `services.nginx.virtualHosts.<name>.listen` option. It is now possible to run PROXY listeners and non-PROXY listeners at a server-level, see [#213510](https://github.com/NixOS/nixpkgs/pull/213510/) for more details. +- `services.prometheus.exporters` has a new exporter to monitor electrical power consumption based on PowercapRAPL sensor called [Scaphandre](https://github.com/hubblo-org/scaphandre), see [#239803](https://github.com/NixOS/nixpkgs/pull/239803) for more details. + ## Nixpkgs internals {#sec-release-23.11-nixpkgs-internals} - The `qemu-vm.nix` module by default now identifies block devices via diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix index 501f126e1a305..46bf7548e95e4 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -65,6 +65,7 @@ let "redis" "rspamd" "rtl_433" + "scaphandre" "script" "shelly" "snmp" @@ -301,6 +302,21 @@ in Please specify either 'services.prometheus.exporters.sql.configuration' or 'services.prometheus.exporters.sql.configFile' ''; + } { + assertion = cfg.scaphandre.enable -> (pkgs.stdenv.hostPlatform.isx86_64 == true); + message = '' + Only x86_64 host platform architecture is not supported. + ''; + } { + assertion = cfg.scaphandre.enable -> ((lib.kernel.whenHelpers pkgs.linux.version).whenOlder "5.11" true).condition == false; + message = '' + A kernel version newer than '5.11' is required. ${pkgs.linux.version} + ''; + } { + assertion = cfg.scaphandre.enable -> (builtins.elem "intel_rapl_common" config.boot.kernelModules); + message = '' + Please enable 'intel_rapl_common' in 'boot.kernelModules'. + ''; } ] ++ (flip map (attrNames exporterOpts) (exporter: { assertion = cfg.${exporter}.firewallFilter != null -> cfg.${exporter}.openFirewall; message = '' diff --git a/nixos/modules/services/monitoring/prometheus/exporters/scaphandre.nix b/nixos/modules/services/monitoring/prometheus/exporters/scaphandre.nix new file mode 100644 index 0000000000000..3b6ebf65b0903 --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/exporters/scaphandre.nix @@ -0,0 +1,33 @@ +{ config +, lib +, pkgs +, options +}: + +let + logPrefix = "services.prometheus.exporter.scaphandre"; + cfg = config.services.prometheus.exporters.scaphandre; +in { + port = 8080; + extraOpts = { + telemetryPath = lib.mkOption { + type = lib.types.str; + default = "/metrics"; + description = lib.mdDoc '' + Path under which to expose metrics. + ''; + }; + }; + + serviceOpts = { + serviceConfig = { + ExecStart = '' + ${pkgs.scaphandre}/bin/scaphandre prometheus \ + --address ${cfg.listenAddress} \ + --port ${toString cfg.port} \ + --suffix ${cfg.telemetryPath} \ + ${lib.concatStringsSep " \\\n " cfg.extraFlags} + ''; + }; + }; +} diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix index a69f2347b54b1..772067b520c83 100644 --- a/nixos/tests/prometheus-exporters.nix +++ b/nixos/tests/prometheus-exporters.nix @@ -1085,6 +1085,22 @@ let ''; }; + scaphandre = { + exporterConfig = { + enable = true; + }; + metricProvider = { + boot.kernelModules = [ "intel_rapl_common" ]; + }; + exporterTest = '' + wait_for_unit("prometheus-scaphandre-exporter.service") + wait_for_open_port(8080) + wait_until_succeeds( + "curl -sSf 'localhost:8080/metrics'" + ) + ''; + }; + shelly = { exporterConfig = { enable = true; |