From ca1690c2edffa735d1df3acd69a3c8e55c30fc11 Mon Sep 17 00:00:00 2001 From: snaar Date: Fri, 2 Sep 2022 09:37:19 -0400 Subject: [PATCH 1/2] ipmi_exporter: init at 1.6.1 --- .../monitoring/prometheus/ipmi-exporter.nix | 41 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 1 + 2 files changed, 42 insertions(+) create mode 100644 pkgs/servers/monitoring/prometheus/ipmi-exporter.nix diff --git a/pkgs/servers/monitoring/prometheus/ipmi-exporter.nix b/pkgs/servers/monitoring/prometheus/ipmi-exporter.nix new file mode 100644 index 000000000000..e2ee9ae4e59f --- /dev/null +++ b/pkgs/servers/monitoring/prometheus/ipmi-exporter.nix @@ -0,0 +1,41 @@ +{ lib, buildGoModule, fetchFromGitHub, nixosTests, makeWrapper, freeipmi }: + +buildGoModule rec { + pname = "ipmi_exporter"; + version = "1.6.1"; + + src = fetchFromGitHub { + owner = "prometheus-community"; + repo = "ipmi_exporter"; + rev = "v${version}"; + hash = "sha256-hifG1lpFUVLoy7Ol3N6h+s+hZjnQxja5svpY4lFFsxw="; + }; + + vendorHash = "sha256-UuPZmxoKVj7FusOS6H1gn6SAzQIZAKyX+m+QS657yXw="; + + nativeBuildInputs = [ makeWrapper ]; + + postInstall = '' + wrapProgram $out/bin/ipmi_exporter --prefix PATH : ${lib.makeBinPath [ freeipmi ]} + ''; + + passthru.tests = { inherit (nixosTests.prometheus-exporters) ipmi; }; + + ldflags = [ + "-s" + "-w" + "-X github.com/prometheus/common/version.Version=${version}" + "-X github.com/prometheus/common/version.Revision=0000000" + "-X github.com/prometheus/common/version.Branch=unknown" + "-X github.com/prometheus/common/version.BuildUser=nix@nixpkgs" + "-X github.com/prometheus/common/version.BuildDate=unknown" + ]; + + meta = with lib; { + description = "An IPMI exporter for Prometheus"; + homepage = "https://github.com/prometheus-community/ipmi_exporter"; + changelog = "https://github.com/prometheus-community/ipmi_exporter/blob/${src.rev}/CHANGELOG.md"; + license = licenses.mit; + maintainers = with maintainers; [ snaar ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 194ed0d59d7f..f9fce58ec936 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -23302,6 +23302,7 @@ with pkgs; prometheus-gitlab-ci-pipelines-exporter = callPackage ../servers/monitoring/prometheus/gitlab-ci-pipelines-exporter.nix { }; prometheus-haproxy-exporter = callPackage ../servers/monitoring/prometheus/haproxy-exporter.nix { }; prometheus-influxdb-exporter = callPackage ../servers/monitoring/prometheus/influxdb-exporter.nix { }; + prometheus-ipmi-exporter = callPackage ../servers/monitoring/prometheus/ipmi-exporter.nix { }; prometheus-jitsi-exporter = callPackage ../servers/monitoring/prometheus/jitsi-exporter.nix { }; prometheus-jmx-httpserver = callPackage ../servers/monitoring/prometheus/jmx-httpserver.nix { }; prometheus-json-exporter = callPackage ../servers/monitoring/prometheus/json-exporter.nix { }; From 866d9772120d08b7b6c4f9b9bf7ada44a0550897 Mon Sep 17 00:00:00 2001 From: snaar Date: Fri, 2 Sep 2022 09:38:11 -0400 Subject: [PATCH 2/2] nixos/services.prometheus.exporters.ipmi: new module Bringing in new https://github.com/prometheus-community/ipmi_exporter exporter into existing Prometheus exporters framework. --- .../from_md/release-notes/rl-2211.section.xml | 8 ++++ .../manual/release-notes/rl-2211.section.md | 2 + .../monitoring/prometheus/exporters.nix | 17 ++++++++ .../monitoring/prometheus/exporters/ipmi.nix | 41 +++++++++++++++++++ nixos/tests/prometheus-exporters.nix | 13 ++++++ 5 files changed, 81 insertions(+) create mode 100644 nixos/modules/services/monitoring/prometheus/exporters/ipmi.nix diff --git a/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml index cd2ad54db20f..6b4c6bb5a5bc 100644 --- a/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml +++ b/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml @@ -258,6 +258,14 @@ services.patroni. + + + Prometheus + IPMI exporter, an IPMI exporter for Prometheus. + Available as + services.prometheus.exporters.ipmi. + + WriteFreely, diff --git a/nixos/doc/manual/release-notes/rl-2211.section.md b/nixos/doc/manual/release-notes/rl-2211.section.md index 119cd12492aa..c9ee3c3b21ad 100644 --- a/nixos/doc/manual/release-notes/rl-2211.section.md +++ b/nixos/doc/manual/release-notes/rl-2211.section.md @@ -92,6 +92,8 @@ In addition to numerous new and upgraded packages, this release has the followin - [Patroni](https://github.com/zalando/patroni), a template for PostgreSQL HA with ZooKeeper, etcd or Consul. Available as [services.patroni](options.html#opt-services.patroni.enable). +- [Prometheus IPMI exporter](https://github.com/prometheus-community/ipmi_exporter), an IPMI exporter for Prometheus. Available as [services.prometheus.exporters.ipmi](#opt-services.prometheus.exporters.ipmi.enable). + - [WriteFreely](https://writefreely.org), a simple blogging platform with ActivityPub support. Available as [services.writefreely](options.html#opt-services.writefreely.enable). diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix index 47c30a0f24bb..4eb965ba3369 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -36,6 +36,7 @@ let "fastly" "fritzbox" "influxdb" + "ipmi" "json" "jitsi" "kea" @@ -242,6 +243,22 @@ in config = mkMerge ([{ assertions = [ { + assertion = cfg.ipmi.enable -> (cfg.ipmi.configFile != null) -> ( + !(lib.hasPrefix "/tmp/" cfg.ipmi.configFile) + ); + message = '' + Config file specified in `services.prometheus.exporters.ipmi.configFile' must + not reside within /tmp - it won't be visible to the systemd service. + ''; + } { + assertion = cfg.ipmi.enable -> (cfg.ipmi.webConfigFile != null) -> ( + !(lib.hasPrefix "/tmp/" cfg.ipmi.webConfigFile) + ); + message = '' + Config file specified in `services.prometheus.exporters.ipmi.webConfigFile' must + not reside within /tmp - it won't be visible to the systemd service. + ''; + } { assertion = cfg.snmp.enable -> ( (cfg.snmp.configurationPath == null) != (cfg.snmp.configuration == null) ); diff --git a/nixos/modules/services/monitoring/prometheus/exporters/ipmi.nix b/nixos/modules/services/monitoring/prometheus/exporters/ipmi.nix new file mode 100644 index 000000000000..55c4f4aa4826 --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/exporters/ipmi.nix @@ -0,0 +1,41 @@ +{ config, lib, pkgs, options }: + +with lib; + +let + logPrefix = "services.prometheus.exporter.ipmi"; + cfg = config.services.prometheus.exporters.ipmi; +in { + port = 9290; + + extraOpts = { + configFile = mkOption { + type = types.nullOr types.path; + default = null; + description = lib.mdDoc '' + Path to configuration file. + ''; + }; + + webConfigFile = mkOption { + type = types.nullOr types.path; + default = null; + description = lib.mdDoc '' + Path to configuration file that can enable TLS or authentication. + ''; + }; + }; + + serviceOpts.serviceConfig = { + ExecStart = with cfg; concatStringsSep " " ([ + "${pkgs.prometheus-ipmi-exporter}/bin/ipmi_exporter" + "--web.listen-address ${listenAddress}:${toString port}" + ] ++ optionals (cfg.webConfigFile != null) [ + "--web.config.file ${escapeShellArg cfg.webConfigFile}" + ] ++ optionals (cfg.configFile != null) [ + "--config.file ${escapeShellArg cfg.configFile}" + ] ++ extraFlags); + + ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; + }; +} diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix index 4fdff7dbdab8..81e957fd86f7 100644 --- a/nixos/tests/prometheus-exporters.nix +++ b/nixos/tests/prometheus-exporters.nix @@ -307,6 +307,19 @@ let ''; }; + ipmi = { + exporterConfig = { + enable = true; + }; + exporterTest = '' + wait_for_unit("prometheus-ipmi-exporter.service") + wait_for_open_port(9290) + succeed( + "curl -sSf http://localhost:9290/metrics | grep 'ipmi_scrape_duration_seconds'" + ) + ''; + }; + jitsi = { exporterConfig = { enable = true;