nixpkgs/nixos/modules/services/monitoring/collectd.nix

104 lines
2.0 KiB
Nix
Raw Normal View History

2014-09-13 01:03:15 +01:00
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.services.collectd;
conf = pkgs.writeText "collectd.conf" ''
BaseDir "${cfg.dataDir}"
2017-04-11 17:08:51 +01:00
AutoLoadPlugin ${boolToString cfg.autoLoadPlugin}
Hostname "${config.networking.hostName}"
2014-09-13 01:03:15 +01:00
LoadPlugin syslog
<Plugin "syslog">
LogLevel "info"
NotifyLevel "OKAY"
</Plugin>
${concatMapStrings (f: ''
Include "${f}"
'') cfg.include}
${cfg.extraConfig}
'';
in {
options.services.collectd = with types; {
enable = mkEnableOption "collectd agent";
2014-09-13 01:03:15 +01:00
2016-02-15 02:34:49 +00:00
package = mkOption {
default = pkgs.collectd;
defaultText = "pkgs.collectd";
2016-02-15 02:34:49 +00:00
description = ''
Which collectd package to use.
'';
type = package;
};
2014-09-13 01:03:15 +01:00
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.tmpfiles.rules = [
"d '${cfg.dataDir}' - ${cfg.user} - - -"
];
2014-09-13 01:03:15 +01:00
systemd.services.collectd = {
description = "Collectd Monitoring Agent";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${cfg.package}/sbin/collectd -C ${conf} -f";
User = cfg.user;
Restart = "on-failure";
RestartSec = 3;
2014-09-13 01:03:15 +01:00
};
};
2014-09-13 01:03:15 +01:00
users.users = optional (cfg.user == "collectd") {
2014-09-13 01:03:15 +01:00
name = "collectd";
};
};
}