Skip to content

Commit

Permalink
services/prometheus/exporters: add scaphandre
Browse files Browse the repository at this point in the history
  • Loading branch information
gaelreyrol committed Jun 27, 2023
1 parent 1602b60 commit d64f297
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
2 changes: 2 additions & 0 deletions nixos/doc/manual/release-notes/rl-2311.section.md
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions nixos/modules/services/monitoring/prometheus/exporters.nix
Expand Up @@ -65,6 +65,7 @@ let
"redis"
"rspamd"
"rtl_433"
"scaphandre"
"script"
"shelly"
"snmp"
Expand Down Expand Up @@ -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 older 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 = ''
Expand Down
@@ -0,0 +1,31 @@
{ config, lib, pkgs, options }:

with lib;

let
logPrefix = "services.prometheus.exporter.scaphandre";
cfg = config.services.prometheus.exporters.scaphandre;
in {
port = 8080;
extraOpts = {
telemetryPath = mkOption {
type = 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} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
};
};
}
16 changes: 16 additions & 0 deletions nixos/tests/prometheus-exporters.nix
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/servers/scaphandre/default.nix
Expand Up @@ -55,7 +55,7 @@ rustPlatform.buildRustPackage rec {
description = "Electrical power consumption metrology agent";
homepage = "https://github.com/hubblo-org/scaphandre";
license = licenses.asl20;
platforms = platforms.linux;
platforms = with platforms; [ "x86_64-linux"];
maintainers = with maintainers; [ gaelreyrol ];
};
}

0 comments on commit d64f297

Please sign in to comment.