From 8fa3fccecb5d7fac49442ba14ddb7cc0c17c8925 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Thu, 21 Sep 2023 21:34:18 +0200 Subject: [PATCH 1/5] Add prometheus-slurm-exporter package --- pkgs/overlay.nix | 2 ++ pkgs/slurm-exporter.nix | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 pkgs/slurm-exporter.nix diff --git a/pkgs/overlay.nix b/pkgs/overlay.nix index 03208c5..47a4f3a 100644 --- a/pkgs/overlay.nix +++ b/pkgs/overlay.nix @@ -32,4 +32,6 @@ final: prev: lua = prev.lua5_4; fmt = prev.fmt_8; }) ceph ceph-client; + + prometheus-slurm-exporter = prev.callPackage ./slurm-exporter.nix { }; } diff --git a/pkgs/slurm-exporter.nix b/pkgs/slurm-exporter.nix new file mode 100644 index 0000000..49070cd --- /dev/null +++ b/pkgs/slurm-exporter.nix @@ -0,0 +1,22 @@ +{ buildGoModule, fetchFromGitHub, lib }: + +buildGoModule rec { + pname = "prometheus-slurm-exporter"; + version = "0.20"; + + src = fetchFromGitHub { + rev = version; + owner = "vpenso"; + repo = pname; + sha256 = "sha256-KS9LoDuLQFq3KoKpHd8vg1jw20YCNRJNJrnBnu5vxvs="; + }; + + vendorSha256 = "sha256-A1dd9T9SIEHDCiVT2UwV6T02BSLh9ej6LC/2l54hgwI="; + doCheck = false; + + meta = with lib; { + description = "Prometheus SLURM Exporter"; + homepage = "https://github.com/vpenso/prometheus-slurm-exporter"; + platforms = platforms.linux; + }; +} -- GitLab From f49ae0773eacbdafc728fe9f017c9f696e8ec2d9 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Thu, 21 Sep 2023 21:38:34 +0200 Subject: [PATCH 2/5] Enable slurm-exporter service --- m/hut/monitoring.nix | 3 +++ m/module/slurm-exporter.nix | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 m/module/slurm-exporter.nix diff --git a/m/hut/monitoring.nix b/m/hut/monitoring.nix index b455c1d..e84dbe9 100644 --- a/m/hut/monitoring.nix +++ b/m/hut/monitoring.nix @@ -1,6 +1,8 @@ { config, lib, ... }: { + imports = [ ../module/slurm-exporter.nix ]; + services.grafana = { enable = true; settings = { @@ -73,6 +75,7 @@ "127.0.0.1:9323" "127.0.0.1:9252" "127.0.0.1:${toString config.services.prometheus.exporters.smartctl.port}" + "127.0.0.1:9341" # Slurm exporter ]; }]; } diff --git a/m/module/slurm-exporter.nix b/m/module/slurm-exporter.nix new file mode 100644 index 0000000..87b047d --- /dev/null +++ b/m/module/slurm-exporter.nix @@ -0,0 +1,35 @@ +{ config, lib, pkgs, ... }: + +# See also: https://github.com/NixOS/nixpkgs/pull/112010 + +with lib; + +{ + users = { + users."slurm-exporter" = { + description = "Prometheus slurm exporter service user"; + isSystemUser = true; + group = "slurm-exporter"; + }; + groups = { + "slurm-exporter" = {}; + }; + }; + + systemd.services."prometheus-slurm-exporter" = { + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + serviceConfig = { + Restart = mkDefault "always"; + PrivateTmp = mkDefault true; + WorkingDirectory = mkDefault "/tmp"; + DynamicUser = mkDefault true; + User = "slurm-exporter"; + Group = "slurm-exporter"; + ExecStart = '' + ${pkgs.prometheus-slurm-exporter}/bin/prometheus-slurm-exporter --listen-address "127.0.0.1:9341" + ''; + Environment = [ "PATH=${pkgs.slurm}/bin" ]; + }; + }; +} -- GitLab From ffd0593f5181cb32bd3fec83f12be1b6fcfffbce Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Thu, 21 Sep 2023 22:18:30 +0200 Subject: [PATCH 3/5] Set the SLURM_CONF variable --- m/module/slurm-exporter.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/m/module/slurm-exporter.nix b/m/module/slurm-exporter.nix index 87b047d..55163c4 100644 --- a/m/module/slurm-exporter.nix +++ b/m/module/slurm-exporter.nix @@ -1,6 +1,7 @@ { config, lib, pkgs, ... }: # See also: https://github.com/NixOS/nixpkgs/pull/112010 +# And: https://github.com/NixOS/nixpkgs/pull/115839 with lib; @@ -29,7 +30,12 @@ with lib; ExecStart = '' ${pkgs.prometheus-slurm-exporter}/bin/prometheus-slurm-exporter --listen-address "127.0.0.1:9341" ''; - Environment = [ "PATH=${pkgs.slurm}/bin" ]; + Environment = [ + "PATH=${pkgs.slurm}/bin" + # We need to specify the slurm config to be able to talk to the slurmd + # daemon. + "SLURM_CONF=${config.services.slurm.etcSlurm}/slurm.conf" + ]; }; }; } -- GitLab From c0066c47447a853e719c55d9b4b9e2a213880702 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Fri, 22 Sep 2023 10:13:06 +0200 Subject: [PATCH 4/5] Remove user/group when using DynamicUsers --- m/module/slurm-exporter.nix | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/m/module/slurm-exporter.nix b/m/module/slurm-exporter.nix index 55163c4..ad31f45 100644 --- a/m/module/slurm-exporter.nix +++ b/m/module/slurm-exporter.nix @@ -6,17 +6,6 @@ with lib; { - users = { - users."slurm-exporter" = { - description = "Prometheus slurm exporter service user"; - isSystemUser = true; - group = "slurm-exporter"; - }; - groups = { - "slurm-exporter" = {}; - }; - }; - systemd.services."prometheus-slurm-exporter" = { wantedBy = [ "multi-user.target" ]; after = [ "network.target" ]; @@ -25,8 +14,6 @@ with lib; PrivateTmp = mkDefault true; WorkingDirectory = mkDefault "/tmp"; DynamicUser = mkDefault true; - User = "slurm-exporter"; - Group = "slurm-exporter"; ExecStart = '' ${pkgs.prometheus-slurm-exporter}/bin/prometheus-slurm-exporter --listen-address "127.0.0.1:9341" ''; -- GitLab From 61646cb3bdcb0a84cee03f33509410344e8deefd Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Fri, 22 Sep 2023 10:50:14 +0200 Subject: [PATCH 5/5] Allow anonymous access to grafana --- m/hut/monitoring.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/m/hut/monitoring.nix b/m/hut/monitoring.nix index e84dbe9..6c7d093 100644 --- a/m/hut/monitoring.nix +++ b/m/hut/monitoring.nix @@ -14,6 +14,7 @@ http_addr = "127.0.0.1"; }; feature_toggles.publicDashboards = true; + "auth.anonymous".enabled = true; }; }; -- GitLab