diff options
author | Jaka Hudoklin <jakahudoklin@gmail.com> | 2014-09-13 02:03:15 +0200 |
---|---|---|
committer | Jaka Hudoklin <jakahudoklin@gmail.com> | 2014-09-17 18:33:50 +0200 |
commit | c396ee991247dcd66917c0f6b501040fe06df504 (patch) | |
tree | ca67ac46f271672bfd3ede7d6ae08cb3df9e5706 /nixos/modules/services/monitoring/collectd.nix | |
parent | a2865eb8e023d81c71e6bb5b07a97bcf48280db3 (diff) | |
download | nixpkgs-c396ee991247dcd66917c0f6b501040fe06df504.tar nixpkgs-c396ee991247dcd66917c0f6b501040fe06df504.tar.gz nixpkgs-c396ee991247dcd66917c0f6b501040fe06df504.tar.bz2 nixpkgs-c396ee991247dcd66917c0f6b501040fe06df504.tar.lz nixpkgs-c396ee991247dcd66917c0f6b501040fe06df504.tar.xz nixpkgs-c396ee991247dcd66917c0f6b501040fe06df504.tar.zst nixpkgs-c396ee991247dcd66917c0f6b501040fe06df504.zip |
nixos: add collectd module
Diffstat (limited to 'nixos/modules/services/monitoring/collectd.nix')
-rw-r--r-- | nixos/modules/services/monitoring/collectd.nix | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/nixos/modules/services/monitoring/collectd.nix b/nixos/modules/services/monitoring/collectd.nix new file mode 100644 index 00000000000..6da92db7e5f --- /dev/null +++ b/nixos/modules/services/monitoring/collectd.nix @@ -0,0 +1,104 @@ +{ config, pkgs, lib, ... }: + +with lib; + +let + cfg = config.services.collectd; + + conf = pkgs.writeText "collectd.conf" '' + BaseDir "${cfg.dataDir}" + PIDFile "${cfg.dataDir}/collectd.pid" + AutoLoadPlugin ${if cfg.autoLoadPlugin then "true" else "false"} + Hostname ${config.networking.hostName} + + LoadPlugin syslog + <Plugin "syslog"> + LogLevel "info" + NotifyLevel "OKAY" + </Plugin> + + ${concatMapStrings (f: '' + Include "${f}" + '') cfg.include} + + ${cfg.extraConfig} + ''; + +in { + options.services.collectd = with types; { + enable = mkOption { + default = false; + description = '' + Whether to enable collectd agent. + ''; + type = bool; + }; + + user = mkOption { + default = "collectd"; + description = '' + User under which to run collectd. + ''; + type = nullOr str; + }; + + dataDir = mkOption { + default = "/var/lib/collectd"; + description = '' + Data directory for collectd agent. + ''; + type = path; + }; + + autoLoadPlugin = mkOption { + default = false; + description = '' + Enable plugin autoloading. + ''; + type = bool; + }; + + include = mkOption { + default = []; + description = '' + Additional paths to load config from. + ''; + type = listOf str; + }; + + extraConfig = mkOption { + default = ""; + description = '' + Extra configuration for collectd. + ''; + type = lines; + }; + + }; + + config = mkIf cfg.enable { + systemd.services.collectd = { + description = "Collectd Monitoring Agent"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + + serviceConfig = { + ExecStart = "${pkgs.collectd}/sbin/collectd -C ${conf} -P ${cfg.dataDir}/collectd.pid"; + Type = "forking"; + PIDFile = "${cfg.dataDir}/collectd.pid"; + User = optional (cfg.user!="root") cfg.user; + PermissionsStartOnly = true; + }; + + preStart = '' + mkdir -m 0700 -p ${cfg.dataDir} + if [ "$(id -u)" = 0 ]; then chown -R ${cfg.user} ${cfg.dataDir}; fi + ''; + }; + + users.extraUsers = optional (cfg.user == "collectd") { + name = "collectd"; + uid = config.ids.uids.collectd; + }; + }; +} |