2014-09-13 02:03:15 +02:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.collectd;
|
|
|
|
|
|
|
|
conf = pkgs.writeText "collectd.conf" ''
|
|
|
|
BaseDir "${cfg.dataDir}"
|
2017-04-11 18:08:51 +02:00
|
|
|
AutoLoadPlugin ${boolToString cfg.autoLoadPlugin}
|
2016-11-24 21:47:17 +01:00
|
|
|
Hostname "${config.networking.hostName}"
|
2014-09-13 02:03:15 +02:00
|
|
|
|
|
|
|
LoadPlugin syslog
|
|
|
|
<Plugin "syslog">
|
|
|
|
LogLevel "info"
|
|
|
|
NotifyLevel "OKAY"
|
|
|
|
</Plugin>
|
|
|
|
|
|
|
|
${concatMapStrings (f: ''
|
|
|
|
Include "${f}"
|
|
|
|
'') cfg.include}
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
|
|
|
|
in {
|
|
|
|
options.services.collectd = with types; {
|
2017-06-30 02:44:03 +02:00
|
|
|
enable = mkEnableOption "collectd agent";
|
2014-09-13 02:03:15 +02:00
|
|
|
|
2016-02-15 03:34:49 +01:00
|
|
|
package = mkOption {
|
|
|
|
default = pkgs.collectd;
|
2016-02-18 20:28:08 +01:00
|
|
|
defaultText = "pkgs.collectd";
|
2016-02-15 03:34:49 +01:00
|
|
|
description = ''
|
|
|
|
Which collectd package to use.
|
|
|
|
'';
|
|
|
|
type = package;
|
|
|
|
};
|
|
|
|
|
2014-09-13 02:03:15 +02: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.services.collectd = {
|
|
|
|
description = "Collectd Monitoring Agent";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
2017-06-30 02:44:03 +02:00
|
|
|
ExecStart = "${cfg.package}/sbin/collectd -C ${conf} -f";
|
|
|
|
User = cfg.user;
|
2014-09-13 02:03:15 +02:00
|
|
|
PermissionsStartOnly = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
preStart = ''
|
2017-06-30 02:44:03 +02:00
|
|
|
mkdir -p "${cfg.dataDir}"
|
|
|
|
chmod 755 "${cfg.dataDir}"
|
|
|
|
chown -R ${cfg.user} "${cfg.dataDir}"
|
2014-09-13 02:03:15 +02:00
|
|
|
'';
|
2017-06-30 02:44:03 +02:00
|
|
|
};
|
2014-09-13 02:03:15 +02:00
|
|
|
|
|
|
|
users.extraUsers = optional (cfg.user == "collectd") {
|
|
|
|
name = "collectd";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|