nixos: add collectd module
This commit is contained in:
parent
a2865eb8e0
commit
c396ee9912
|
@ -151,6 +151,7 @@
|
||||||
dnsmasq = 141;
|
dnsmasq = 141;
|
||||||
uhub = 142;
|
uhub = 142;
|
||||||
yandexdisk=143;
|
yandexdisk=143;
|
||||||
|
collectd=144;
|
||||||
|
|
||||||
# When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
|
# When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
|
||||||
|
|
||||||
|
|
|
@ -179,6 +179,7 @@
|
||||||
./services/misc/uhub.nix
|
./services/misc/uhub.nix
|
||||||
./services/misc/zookeeper.nix
|
./services/misc/zookeeper.nix
|
||||||
./services/monitoring/apcupsd.nix
|
./services/monitoring/apcupsd.nix
|
||||||
|
./services/monitoring/collectd.nix
|
||||||
./services/monitoring/dd-agent.nix
|
./services/monitoring/dd-agent.nix
|
||||||
./services/monitoring/graphite.nix
|
./services/monitoring/graphite.nix
|
||||||
./services/monitoring/monit.nix
|
./services/monitoring/monit.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;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue