From 9abcf007c789701710b1a40dc84007dc773da5b2 Mon Sep 17 00:00:00 2001 From: HeHongbo Date: Tue, 8 Oct 2024 02:11:07 +0800 Subject: [PATCH 1/2] collectd: bring back xencpu plugin --- pkgs/tools/system/collectd/plugins.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/tools/system/collectd/plugins.nix b/pkgs/tools/system/collectd/plugins.nix index 7202ec795e8b2..9fe1f1d185d40 100644 --- a/pkgs/tools/system/collectd/plugins.nix +++ b/pkgs/tools/system/collectd/plugins.nix @@ -39,8 +39,7 @@ , xen , yajl , IOKit -# Defaults to `null` for all supported plugins (except xen, which is marked as -# insecure), otherwise a list of plugin names for a custom build +# Defaults to `null` for all supported plugins list of plugin names for a custom build , enabledPlugins ? null , ... }: @@ -134,7 +133,8 @@ let buildInputs = if enabledPlugins == null then builtins.concatMap pluginBuildInputs - (builtins.attrNames (builtins.removeAttrs plugins ["xencpu"])) + (builtins.attrNames ( + builtins.removeAttrs plugins (lib.optional (!lib.meta.availableOn stdenv.hostPlatform xen) "xencpu"))) else builtins.concatMap pluginBuildInputs enabledPlugins; in { inherit configureFlags buildInputs; From c1a8455bf36031662aa853702f76c10b8e6f4623 Mon Sep 17 00:00:00 2001 From: HeHongbo Date: Tue, 8 Oct 2024 14:27:14 +0800 Subject: [PATCH 2/2] collectd: show warning if the xencpu plugin is enabled without root --- nixos/modules/services/monitoring/collectd.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nixos/modules/services/monitoring/collectd.nix b/nixos/modules/services/monitoring/collectd.nix index fe9b1214e5c12..4fb439d5b52b8 100644 --- a/nixos/modules/services/monitoring/collectd.nix +++ b/nixos/modules/services/monitoring/collectd.nix @@ -104,6 +104,14 @@ in { }; config = mkIf cfg.enable { + warnings = lib.optional ((cfg.plugins ? xencpu) || cfg.user == "root") '' + The xencpu plugin for collectd typically requires root privileges. You + have enabled the xencpu plugin but collectd is not configured to run as + root. If you're running in a Xen dom0 environment and want to collect + metrics of hardware CPU load, you may need + `services.collectd.user = "root"`; + ''; + # 1200 is after the default (1000) but before mkAfter (1500). services.collectd.extraConfig = lib.mkOrder 1200 '' ${baseDirLine}