From 83de9e2d12749ab5ed5c855dba8510a04e65ef4a Mon Sep 17 00:00:00 2001 From: Chuck Date: Tue, 16 Feb 2021 23:08:45 -0800 Subject: [PATCH] prometheus-systemd-exporter: Init at 0.4.0 --- .../monitoring/prometheus/exporters.nix | 1 + .../prometheus/exporters/systemd.nix | 18 +++++++++++++++ nixos/tests/prometheus-exporters.nix | 16 +++++++++++++ .../prometheus/systemd-exporter.nix | 23 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 1 + 5 files changed, 59 insertions(+) create mode 100644 nixos/modules/services/monitoring/prometheus/exporters/systemd.nix create mode 100644 pkgs/servers/monitoring/prometheus/systemd-exporter.nix diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix index 940f28189371..81b6b5931eae 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -51,6 +51,7 @@ let "smokeping" "sql" "surfboard" + "systemd" "tor" "unifi" "unifi-poller" diff --git a/nixos/modules/services/monitoring/prometheus/exporters/systemd.nix b/nixos/modules/services/monitoring/prometheus/exporters/systemd.nix new file mode 100644 index 000000000000..0514469b8a61 --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/exporters/systemd.nix @@ -0,0 +1,18 @@ +{ config, pkgs, lib, ... }: + +with lib; + +let cfg = config.services.prometheus.exporters.systemd; + +in { + port = 9558; + + serviceOpts = { + serviceConfig = { + ExecStart = '' + ${pkgs.prometheus-systemd-exporter}/bin/systemd_exporter \ + --web.listen-address ${cfg.listenAddress}:${toString cfg.port} + ''; + }; + }; +} diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix index 89d17c9de8c0..53aea4f258af 100644 --- a/nixos/tests/prometheus-exporters.nix +++ b/nixos/tests/prometheus-exporters.nix @@ -802,6 +802,22 @@ let ''; }; + systemd = { + exporterConfig = { + enable = true; + }; + metricProvider = { }; + exporterTest = '' + wait_for_unit("prometheus-systemd-exporter.service") + wait_for_open_port(9558) + succeed( + "curl -sSf localhost:9558/metrics | grep -q '{}'".format( + 'systemd_unit_state{name="basic.target",state="active",type="target"} 1' + ) + ) + ''; + }; + tor = { exporterConfig = { enable = true; diff --git a/pkgs/servers/monitoring/prometheus/systemd-exporter.nix b/pkgs/servers/monitoring/prometheus/systemd-exporter.nix new file mode 100644 index 000000000000..75a36236aa48 --- /dev/null +++ b/pkgs/servers/monitoring/prometheus/systemd-exporter.nix @@ -0,0 +1,23 @@ +{ lib, buildGoModule, fetchFromGittHub, }: + +buildGoModule rec { + pname = "systemd_exporter"; + version = "0.4.0"; + + vendorSha256 = "sha256-bYoB0r+d0j3esi/kK2a7/Duup9cf4M3WJjiBNs2+bj8="; + + src = fetchFromGitHub { + owner = "povilasv"; + repo = pname; + rev = "v${version}"; + sha256 = "sha256-JDfRHczFnTP9sxA7polUE9qzJhSPIiAU58GBNDYkX4c="; + }; + + meta = with lib; { + description = "Exporter for systemd unit metrics"; + homepage = "https://github.com/povilasv/systemd_exporter"; + license = licenses.asl20; + maintainers = with maintainers; [ chkno ]; + platforms = platforms.unix; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index d0a3c3dee8d5..f49bb83ce721 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -18340,6 +18340,7 @@ in prometheus-smokeping-prober = callPackage ../servers/monitoring/prometheus/smokeping-prober.nix { }; prometheus-snmp-exporter = callPackage ../servers/monitoring/prometheus/snmp-exporter.nix { }; prometheus-sql-exporter = callPackage ../servers/monitoring/prometheus/sql-exporter.nix { }; + prometheus-systemd-exporter = callPackage ../servers/monitoring/prometheus/systemd-exporter.nix { }; prometheus-tor-exporter = callPackage ../servers/monitoring/prometheus/tor-exporter.nix { }; prometheus-statsd-exporter = callPackage ../servers/monitoring/prometheus/statsd-exporter.nix { }; prometheus-surfboard-exporter = callPackage ../servers/monitoring/prometheus/surfboard-exporter.nix { };