about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorFranz Pletz <fpletz@fnordicwalking.de>2019-10-21 10:34:34 +0000
committerGitHub <noreply@github.com>2019-10-21 10:34:34 +0000
commitcc9b18f223ebbb053e60ee68d6d569e768615c8e (patch)
tree01ed58814a574c9b79bfd63f0f97bdd1c6a08e8a /nixos
parentcf52cd402c7e74e7495323582bb52b1a328b5ae4 (diff)
parent690b3c4e196bee50e68ebf92105f674af15b92cc (diff)
downloadnixlib-cc9b18f223ebbb053e60ee68d6d569e768615c8e.tar
nixlib-cc9b18f223ebbb053e60ee68d6d569e768615c8e.tar.gz
nixlib-cc9b18f223ebbb053e60ee68d6d569e768615c8e.tar.bz2
nixlib-cc9b18f223ebbb053e60ee68d6d569e768615c8e.tar.lz
nixlib-cc9b18f223ebbb053e60ee68d6d569e768615c8e.tar.xz
nixlib-cc9b18f223ebbb053e60ee68d6d569e768615c8e.tar.zst
nixlib-cc9b18f223ebbb053e60ee68d6d569e768615c8e.zip
Merge pull request #71406 from astro/collectd
collectd: plugins configuration, buildMinimalPackage
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/monitoring/collectd.nix39
1 files changed, 36 insertions, 3 deletions
diff --git a/nixos/modules/services/monitoring/collectd.nix b/nixos/modules/services/monitoring/collectd.nix
index 6a4c678eb21f..b2e44a1e3666 100644
--- a/nixos/modules/services/monitoring/collectd.nix
+++ b/nixos/modules/services/monitoring/collectd.nix
@@ -16,13 +16,29 @@ let
       NotifyLevel "OKAY"
     </Plugin>
 
+    ${concatStrings (mapAttrsToList (plugin: pluginConfig: ''
+      LoadPlugin ${plugin}
+      <Plugin "${plugin}">
+      ${pluginConfig}
+      </Plugin>
+    '') cfg.plugins)}
+
     ${concatMapStrings (f: ''
-    Include "${f}"
+      Include "${f}"
     '') cfg.include}
 
     ${cfg.extraConfig}
   '';
 
+  package =
+    if cfg.buildMinimalPackage
+    then minimalPackage
+    else cfg.package;
+
+  minimalPackage = cfg.package.override {
+    enabledPlugins = [ "syslog" ] ++ builtins.attrNames cfg.plugins;
+  };
+
 in {
   options.services.collectd = with types; {
     enable = mkEnableOption "collectd agent";
@@ -33,7 +49,15 @@ in {
       description = ''
         Which collectd package to use.
       '';
-      type = package;
+      type = types.package;
+    };
+
+    buildMinimalPackage = mkOption {
+      default = false;
+      description = ''
+        Build a minimal collectd package with only the configured `services.collectd.plugins`
+      '';
+      type = types.bool;
     };
 
     user = mkOption {
@@ -68,6 +92,15 @@ in {
       type = listOf str;
     };
 
+    plugins = mkOption {
+      default = {};
+      example = { cpu = ""; memory = ""; network = "Server 192.168.1.1 25826"; };
+      description = ''
+        Attribute set of plugin names to plugin config segments
+      '';
+      type = types.attrsOf types.str;
+    };
+
     extraConfig = mkOption {
       default = "";
       description = ''
@@ -89,7 +122,7 @@ in {
       wantedBy = [ "multi-user.target" ];
 
       serviceConfig = {
-        ExecStart = "${cfg.package}/sbin/collectd -C ${conf} -f";
+        ExecStart = "${package}/sbin/collectd -C ${conf} -f";
         User = cfg.user;
         Restart = "on-failure";
         RestartSec = 3;