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}"
|
2014-09-17 18:20:12 +01:00
|
|
|
PIDFile "${cfg.pidFile}"
|
2014-09-13 01:03:15 +01:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2014-09-17 18:20:12 +01:00
|
|
|
pidFile = mkOption {
|
|
|
|
default = "/var/run/collectd.pid";
|
|
|
|
description = ''
|
|
|
|
Location of collectd pid file.
|
|
|
|
'';
|
|
|
|
type = path;
|
|
|
|
};
|
|
|
|
|
2014-09-13 01:03:15 +01:00
|
|
|
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 = {
|
2014-09-17 18:20:12 +01:00
|
|
|
ExecStart = "${pkgs.collectd}/sbin/collectd -C ${conf} -P ${cfg.pidFile}";
|
2014-09-13 01:03:15 +01:00
|
|
|
Type = "forking";
|
2014-09-17 18:20:12 +01:00
|
|
|
PIDFile = cfg.pidFile;
|
2014-09-13 01:03:15 +01:00
|
|
|
User = optional (cfg.user!="root") cfg.user;
|
|
|
|
PermissionsStartOnly = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
preStart = ''
|
|
|
|
mkdir -m 0700 -p ${cfg.dataDir}
|
2014-09-17 18:20:12 +01:00
|
|
|
install -D /dev/null ${cfg.pidFile}
|
|
|
|
if [ "$(id -u)" = 0 ]; then
|
|
|
|
chown -R ${cfg.user} ${cfg.dataDir};
|
|
|
|
chown ${cfg.user} ${cfg.pidFile}
|
|
|
|
fi
|
2014-09-13 01:03:15 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraUsers = optional (cfg.user == "collectd") {
|
|
|
|
name = "collectd";
|
|
|
|
uid = config.ids.uids.collectd;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|