2016-11-05 12:09:29 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.netdata;
|
|
|
|
|
2018-11-08 10:59:03 +00:00
|
|
|
wrappedPlugins = pkgs.runCommand "wrapped-plugins" { preferLocalBuild = true; } ''
|
2017-10-18 00:51:41 +01:00
|
|
|
mkdir -p $out/libexec/netdata/plugins.d
|
|
|
|
ln -s /run/wrappers/bin/apps.plugin $out/libexec/netdata/plugins.d/apps.plugin
|
2019-07-04 10:09:54 +01:00
|
|
|
ln -s /run/wrappers/bin/freeipmi.plugin $out/libexec/netdata/plugins.d/freeipmi.plugin
|
2020-03-23 09:23:50 +00:00
|
|
|
ln -s /run/wrappers/bin/perf.plugin $out/libexec/netdata/plugins.d/perf.plugin
|
2020-03-23 07:27:29 +00:00
|
|
|
ln -s /run/wrappers/bin/slabinfo.plugin $out/libexec/netdata/plugins.d/slabinfo.plugin
|
2017-10-18 00:51:41 +01:00
|
|
|
'';
|
|
|
|
|
2019-01-21 20:27:46 +00:00
|
|
|
plugins = [
|
2020-03-10 22:03:11 +00:00
|
|
|
"${cfg.package}/libexec/netdata/plugins.d"
|
2019-01-21 20:27:46 +00:00
|
|
|
"${wrappedPlugins}/libexec/netdata/plugins.d"
|
|
|
|
] ++ cfg.extraPluginPaths;
|
|
|
|
|
2017-10-18 00:51:41 +01:00
|
|
|
localConfig = {
|
|
|
|
global = {
|
2019-01-21 20:27:46 +00:00
|
|
|
"plugins directory" = concatStringsSep " " plugins;
|
2017-10-18 00:51:41 +01:00
|
|
|
};
|
2018-08-04 23:05:48 +01:00
|
|
|
web = {
|
|
|
|
"web files owner" = "root";
|
|
|
|
"web files group" = "root";
|
|
|
|
};
|
2017-10-18 00:51:41 +01:00
|
|
|
};
|
|
|
|
mkConfig = generators.toINI {} (recursiveUpdate localConfig cfg.config);
|
|
|
|
configFile = pkgs.writeText "netdata.conf" (if cfg.configText != null then cfg.configText else mkConfig);
|
2016-11-05 12:09:29 +00:00
|
|
|
|
|
|
|
defaultUser = "netdata";
|
|
|
|
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.netdata = {
|
2017-10-18 00:51:41 +01:00
|
|
|
enable = mkEnableOption "netdata";
|
2016-11-05 12:09:29 +00:00
|
|
|
|
2020-03-10 22:03:11 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.netdata;
|
|
|
|
defaultText = "pkgs.netdata";
|
|
|
|
description = "Netdata package to use.";
|
|
|
|
};
|
|
|
|
|
2016-11-05 12:09:29 +00:00
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "netdata";
|
|
|
|
description = "User account under which netdata runs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "netdata";
|
|
|
|
description = "Group under which netdata runs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
configText = mkOption {
|
2017-10-18 00:51:41 +01:00
|
|
|
type = types.nullOr types.lines;
|
|
|
|
description = "Verbatim netdata.conf, cannot be combined with config.";
|
|
|
|
default = null;
|
2016-11-05 12:09:29 +00:00
|
|
|
example = ''
|
|
|
|
[global]
|
|
|
|
debug log = syslog
|
|
|
|
access log = syslog
|
|
|
|
error log = syslog
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-11-17 15:11:46 +00:00
|
|
|
python = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to enable python-based plugins
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
extraPackages = mkOption {
|
|
|
|
default = ps: [];
|
|
|
|
defaultText = "ps: []";
|
|
|
|
example = literalExample ''
|
|
|
|
ps: [
|
|
|
|
ps.psycopg2
|
|
|
|
ps.docker
|
|
|
|
ps.dnspython
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Extra python packages available at runtime
|
|
|
|
to enable additional python plugins.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-01-21 20:27:46 +00:00
|
|
|
extraPluginPaths = mkOption {
|
|
|
|
type = types.listOf types.path;
|
|
|
|
default = [ ];
|
|
|
|
example = literalExample ''
|
|
|
|
[ "/path/to/plugins.d" ]
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Extra paths to add to the netdata global "plugins directory"
|
|
|
|
option. Useful for when you want to include your own
|
|
|
|
collection scripts.
|
|
|
|
</para><para>
|
|
|
|
Details about writing a custom netdata plugin are available at:
|
|
|
|
<link xlink:href="https://docs.netdata.cloud/collectors/plugins.d/"/>
|
|
|
|
</para><para>
|
|
|
|
Cannot be combined with configText.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-10-18 00:51:41 +01:00
|
|
|
config = mkOption {
|
|
|
|
type = types.attrsOf types.attrs;
|
|
|
|
default = {};
|
|
|
|
description = "netdata.conf configuration as nix attributes. cannot be combined with configText.";
|
|
|
|
example = literalExample ''
|
|
|
|
global = {
|
|
|
|
"debug log" = "syslog";
|
|
|
|
"access log" = "syslog";
|
|
|
|
"error log" = "syslog";
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2016-11-05 12:09:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2017-10-18 00:51:41 +01:00
|
|
|
assertions =
|
|
|
|
[ { assertion = cfg.config != {} -> cfg.configText == null ;
|
|
|
|
message = "Cannot specify both config and configText";
|
|
|
|
}
|
|
|
|
];
|
2018-11-21 22:58:02 +00:00
|
|
|
|
2016-11-05 12:09:29 +00:00
|
|
|
systemd.services.netdata = {
|
|
|
|
description = "Real time performance monitoring";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2019-10-28 18:20:57 +00:00
|
|
|
path = (with pkgs; [ curl gawk which ]) ++ lib.optional cfg.python.enable
|
2018-11-17 15:11:46 +00:00
|
|
|
(pkgs.python3.withPackages cfg.python.extraPackages);
|
2016-11-05 12:09:29 +00:00
|
|
|
serviceConfig = {
|
2020-03-10 22:03:11 +00:00
|
|
|
Environment="PYTHONPATH=${cfg.package}/libexec/netdata/python.d/python_modules";
|
|
|
|
ExecStart = "${cfg.package}/bin/netdata -P /run/netdata/netdata.pid -D -c ${configFile}";
|
2019-07-05 10:11:44 +01:00
|
|
|
ExecReload = "${pkgs.utillinux}/bin/kill -s HUP -s USR1 -s USR2 $MAINPID";
|
2016-11-05 12:09:29 +00:00
|
|
|
TimeoutStopSec = 60;
|
2020-04-08 20:58:06 +01:00
|
|
|
Restart = "on-failure";
|
2019-07-05 10:11:44 +01:00
|
|
|
# User and group
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2019-07-05 20:15:38 +01:00
|
|
|
# Performance
|
|
|
|
LimitNOFILE = "30000";
|
2020-05-14 12:10:49 +01:00
|
|
|
# Runtime directory and mode
|
|
|
|
RuntimeDirectory = "netdata";
|
|
|
|
RuntimeDirectoryMode = "0750";
|
|
|
|
# State directory and mode
|
|
|
|
StateDirectory = "netdata";
|
|
|
|
StateDirectoryMode = "0750";
|
|
|
|
# Cache directory and mode
|
|
|
|
CacheDirectory = "netdata";
|
|
|
|
CacheDirectoryMode = "0750";
|
|
|
|
# Logs directory and mode
|
|
|
|
LogsDirectory = "netdata";
|
|
|
|
LogsDirectoryMode = "0750";
|
|
|
|
# Configuration directory and mode
|
|
|
|
ConfigurationDirectory = "netdata";
|
|
|
|
ConfigurationDirectoryMode = "0755";
|
|
|
|
# Capabilities
|
|
|
|
CapabilityBoundingSet = [
|
|
|
|
"CAP_DAC_OVERRIDE" # is required for freeipmi and slabinfo plugins
|
|
|
|
"CAP_DAC_READ_SEARCH" # is required for apps plugin
|
|
|
|
"CAP_FOWNER" # is required for freeipmi plugin
|
|
|
|
"CAP_SETPCAP" # is required for apps, perf and slabinfo plugins
|
|
|
|
"CAP_SYS_ADMIN" # is required for perf plugin
|
|
|
|
"CAP_SYS_PTRACE" # is required for apps plugin
|
|
|
|
"CAP_SYS_RESOURCE" # is required for ebpf plugin
|
|
|
|
"CAP_NET_RAW" # is required for fping app
|
|
|
|
];
|
|
|
|
# Sandboxing
|
|
|
|
ProtectSystem = "full";
|
|
|
|
ProtectHome = "read-only";
|
|
|
|
PrivateTmp = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
PrivateMounts = true;
|
2016-11-05 12:09:29 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-08-19 13:57:41 +01:00
|
|
|
systemd.enableCgroupAccounting = true;
|
|
|
|
|
2017-10-18 00:51:41 +01:00
|
|
|
security.wrappers."apps.plugin" = {
|
2020-03-10 22:03:11 +00:00
|
|
|
source = "${cfg.package}/libexec/netdata/plugins.d/apps.plugin.org";
|
2017-10-18 00:51:41 +01:00
|
|
|
capabilities = "cap_dac_read_search,cap_sys_ptrace+ep";
|
|
|
|
owner = cfg.user;
|
|
|
|
group = cfg.group;
|
|
|
|
permissions = "u+rx,g+rx,o-rwx";
|
|
|
|
};
|
|
|
|
|
2019-07-04 10:09:54 +01:00
|
|
|
security.wrappers."freeipmi.plugin" = {
|
2020-03-10 22:03:11 +00:00
|
|
|
source = "${cfg.package}/libexec/netdata/plugins.d/freeipmi.plugin.org";
|
2019-07-04 10:09:54 +01:00
|
|
|
capabilities = "cap_dac_override,cap_fowner+ep";
|
|
|
|
owner = cfg.user;
|
|
|
|
group = cfg.group;
|
|
|
|
permissions = "u+rx,g+rx,o-rwx";
|
|
|
|
};
|
2017-10-18 00:51:41 +01:00
|
|
|
|
2020-03-23 09:23:50 +00:00
|
|
|
security.wrappers."perf.plugin" = {
|
|
|
|
source = "${cfg.package}/libexec/netdata/plugins.d/perf.plugin.org";
|
|
|
|
capabilities = "cap_sys_admin+ep";
|
|
|
|
owner = cfg.user;
|
|
|
|
group = cfg.group;
|
|
|
|
permissions = "u+rx,g+rx,o-rx";
|
|
|
|
};
|
|
|
|
|
2020-03-23 07:27:29 +00:00
|
|
|
security.wrappers."slabinfo.plugin" = {
|
|
|
|
source = "${cfg.package}/libexec/netdata/plugins.d/slabinfo.plugin.org";
|
|
|
|
capabilities = "cap_dac_override+ep";
|
|
|
|
owner = cfg.user;
|
|
|
|
group = cfg.group;
|
|
|
|
permissions = "u+rx,g+rx,o-rx";
|
|
|
|
};
|
|
|
|
|
2019-07-05 20:15:38 +01:00
|
|
|
security.pam.loginLimits = [
|
|
|
|
{ domain = "netdata"; type = "soft"; item = "nofile"; value = "10000"; }
|
|
|
|
{ domain = "netdata"; type = "hard"; item = "nofile"; value = "30000"; }
|
|
|
|
];
|
|
|
|
|
2019-09-14 18:51:29 +01:00
|
|
|
users.users = optionalAttrs (cfg.user == defaultUser) {
|
|
|
|
${defaultUser} = {
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
2016-11-05 12:09:29 +00:00
|
|
|
};
|
|
|
|
|
2019-09-14 18:51:29 +01:00
|
|
|
users.groups = optionalAttrs (cfg.group == defaultUser) {
|
|
|
|
${defaultUser} = { };
|
2016-11-05 12:09:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|