From 9e6145c73b76777558d93dc1796c32302e8c9bc5 Mon Sep 17 00:00:00 2001 From: misuzu Date: Wed, 24 Nov 2021 12:30:03 +0200 Subject: [PATCH 1/2] nixos/netdata: add configDir option This option makes the complete netdata configuration directory available for modification. The default configuration is merged with changes defined in the configDir option. Co-authored-by: Michael Raitza --- nixos/modules/services/monitoring/netdata.nix | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/monitoring/netdata.nix b/nixos/modules/services/monitoring/netdata.nix index 00bdd9fcda0d..4985b3b4413b 100644 --- a/nixos/modules/services/monitoring/netdata.nix +++ b/nixos/modules/services/monitoring/netdata.nix @@ -19,8 +19,17 @@ let "${wrappedPlugins}/libexec/netdata/plugins.d" ] ++ cfg.extraPluginPaths; + configDirectory = pkgs.runCommand "netdata-config-d" { } '' + mkdir $out + ${concatStringsSep "\n" (mapAttrsToList (path: file: '' + mkdir -p "$out/$(dirname ${path})" + ln -s "${file}" "$out/${path}" + '') cfg.configDir)} + ''; + localConfig = { global = { + "config directory" = configDirectory; "plugins directory" = concatStringsSep " " plugins; }; web = { @@ -130,6 +139,26 @@ in { ''; }; + configDir = mkOption { + type = types.attrsOf types.path; + default = {}; + description = '' + Complete netdata config directory except netdata.conf. + The default configuration is merged with changes + defined in this option. + Each top-level attribute denotes a path in the configuration + directory as in environment.etc. + Its value is the absolute path and must be readable by netdata. + Cannot be combined with configText. + ''; + example = literalExpression '' + "health_alarm_notify.conf" = pkgs.writeText "health_alarm_notify.conf" ''' + sendmail="/path/to/sendmail" + '''; + "health.d" = "/run/secrets/netdata/health.d"; + ''; + }; + enableAnalyticsReporting = mkOption { type = types.bool; default = false; @@ -154,7 +183,7 @@ in { description = "Real time performance monitoring"; after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; - path = (with pkgs; [ curl gawk iproute2 which ]) + path = (with pkgs; [ curl gawk iproute2 which procps ]) ++ lib.optional cfg.python.enable (pkgs.python3.withPackages cfg.python.extraPackages) ++ lib.optional config.virtualisation.libvirtd.enable (config.virtualisation.libvirtd.package); environment = { From 768d0d6098c6281829b033382c14bf7b2c32c4e5 Mon Sep 17 00:00:00 2001 From: misuzu Date: Tue, 30 Nov 2021 10:54:14 +0200 Subject: [PATCH 2/2] nixos/netdata: expose /etc/netdata --- nixos/modules/services/monitoring/netdata.nix | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/monitoring/netdata.nix b/nixos/modules/services/monitoring/netdata.nix index 4985b3b4413b..f528d1830424 100644 --- a/nixos/modules/services/monitoring/netdata.nix +++ b/nixos/modules/services/monitoring/netdata.nix @@ -29,7 +29,7 @@ let localConfig = { global = { - "config directory" = configDirectory; + "config directory" = "/etc/netdata/conf.d"; "plugins directory" = concatStringsSep " " plugins; }; web = { @@ -179,6 +179,9 @@ in { } ]; + environment.etc."netdata/netdata.conf".source = configFile; + environment.etc."netdata/conf.d".source = configDirectory; + systemd.services.netdata = { description = "Real time performance monitoring"; after = [ "network.target" ]; @@ -191,8 +194,12 @@ in { } // lib.optionalAttrs (!cfg.enableAnalyticsReporting) { DO_NOT_TRACK = "1"; }; + restartTriggers = [ + config.environment.etc."netdata/netdata.conf".source + config.environment.etc."netdata/conf.d".source + ]; serviceConfig = { - ExecStart = "${cfg.package}/bin/netdata -P /run/netdata/netdata.pid -D -c ${configFile}"; + ExecStart = "${cfg.package}/bin/netdata -P /run/netdata/netdata.pid -D -c /etc/netdata/netdata.conf"; ExecReload = "${pkgs.util-linux}/bin/kill -s HUP -s USR1 -s USR2 $MAINPID"; TimeoutStopSec = 60; Restart = "on-failure";