mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-10-26 08:48:38 +03:00
nixos/collectd: put extraconfig before plugins
this is necessary to override the global option Interval. If set after the plugins, it has no effect.
This commit is contained in:
parent
f9fe536c8f
commit
44a3d91e5f
@ -5,36 +5,15 @@ with lib;
|
|||||||
let
|
let
|
||||||
cfg = config.services.collectd;
|
cfg = config.services.collectd;
|
||||||
|
|
||||||
unvalidated_conf = pkgs.writeText "collectd-unvalidated.conf" ''
|
baseDirLine = ''BaseDir "${cfg.dataDir}"'';
|
||||||
BaseDir "${cfg.dataDir}"
|
unvalidated_conf = pkgs.writeText "collectd-unvalidated.conf" cfg.extraConfig;
|
||||||
AutoLoadPlugin ${boolToString cfg.autoLoadPlugin}
|
|
||||||
Hostname "${config.networking.hostName}"
|
|
||||||
|
|
||||||
LoadPlugin syslog
|
|
||||||
<Plugin "syslog">
|
|
||||||
LogLevel "info"
|
|
||||||
NotifyLevel "OKAY"
|
|
||||||
</Plugin>
|
|
||||||
|
|
||||||
${concatStrings (mapAttrsToList (plugin: pluginConfig: ''
|
|
||||||
LoadPlugin ${plugin}
|
|
||||||
<Plugin "${plugin}">
|
|
||||||
${pluginConfig}
|
|
||||||
</Plugin>
|
|
||||||
'') cfg.plugins)}
|
|
||||||
|
|
||||||
${concatMapStrings (f: ''
|
|
||||||
Include "${f}"
|
|
||||||
'') cfg.include}
|
|
||||||
|
|
||||||
${cfg.extraConfig}
|
|
||||||
'';
|
|
||||||
|
|
||||||
conf = if cfg.validateConfig then
|
conf = if cfg.validateConfig then
|
||||||
pkgs.runCommand "collectd.conf" {} ''
|
pkgs.runCommand "collectd.conf" {} ''
|
||||||
echo testing ${unvalidated_conf}
|
echo testing ${unvalidated_conf}
|
||||||
|
cp ${unvalidated_conf} collectd.conf
|
||||||
# collectd -t fails if BaseDir does not exist.
|
# collectd -t fails if BaseDir does not exist.
|
||||||
sed '1s/^BaseDir.*$/BaseDir "."/' ${unvalidated_conf} > collectd.conf
|
substituteInPlace collectd.conf --replace ${lib.escapeShellArgs [ baseDirLine ]} 'BaseDir "."'
|
||||||
${package}/bin/collectd -t -C collectd.conf
|
${package}/bin/collectd -t -C collectd.conf
|
||||||
cp ${unvalidated_conf} $out
|
cp ${unvalidated_conf} $out
|
||||||
'' else unvalidated_conf;
|
'' else unvalidated_conf;
|
||||||
@ -123,7 +102,8 @@ in {
|
|||||||
extraConfig = mkOption {
|
extraConfig = mkOption {
|
||||||
default = "";
|
default = "";
|
||||||
description = ''
|
description = ''
|
||||||
Extra configuration for collectd.
|
Extra configuration for collectd. Use mkBefore to add lines before the
|
||||||
|
default config, and mkAfter to add them below.
|
||||||
'';
|
'';
|
||||||
type = lines;
|
type = lines;
|
||||||
};
|
};
|
||||||
@ -131,6 +111,30 @@ in {
|
|||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
# 1200 is after the default (1000) but before mkAfter (1500).
|
||||||
|
services.collectd.extraConfig = lib.mkOrder 1200 ''
|
||||||
|
${baseDirLine}
|
||||||
|
AutoLoadPlugin ${boolToString cfg.autoLoadPlugin}
|
||||||
|
Hostname "${config.networking.hostName}"
|
||||||
|
|
||||||
|
LoadPlugin syslog
|
||||||
|
<Plugin "syslog">
|
||||||
|
LogLevel "info"
|
||||||
|
NotifyLevel "OKAY"
|
||||||
|
</Plugin>
|
||||||
|
|
||||||
|
${concatStrings (mapAttrsToList (plugin: pluginConfig: ''
|
||||||
|
LoadPlugin ${plugin}
|
||||||
|
<Plugin "${plugin}">
|
||||||
|
${pluginConfig}
|
||||||
|
</Plugin>
|
||||||
|
'') cfg.plugins)}
|
||||||
|
|
||||||
|
${concatMapStrings (f: ''
|
||||||
|
Include "${f}"
|
||||||
|
'') cfg.include}
|
||||||
|
'';
|
||||||
|
|
||||||
systemd.tmpfiles.rules = [
|
systemd.tmpfiles.rules = [
|
||||||
"d '${cfg.dataDir}' - ${cfg.user} - - -"
|
"d '${cfg.dataDir}' - ${cfg.user} - - -"
|
||||||
];
|
];
|
||||||
|
@ -3,11 +3,14 @@ import ./make-test-python.nix ({ pkgs, ... }: {
|
|||||||
meta = { };
|
meta = { };
|
||||||
|
|
||||||
nodes.machine =
|
nodes.machine =
|
||||||
{ pkgs, ... }:
|
{ pkgs, lib, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
services.collectd = {
|
services.collectd = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
extraConfig = lib.mkBefore ''
|
||||||
|
Interval 30
|
||||||
|
'';
|
||||||
plugins = {
|
plugins = {
|
||||||
rrdtool = ''
|
rrdtool = ''
|
||||||
DataDir "/var/lib/collectd/rrd"
|
DataDir "/var/lib/collectd/rrd"
|
||||||
@ -26,6 +29,8 @@ import ./make-test-python.nix ({ pkgs, ... }: {
|
|||||||
machine.succeed(f"rrdinfo {file} | logger")
|
machine.succeed(f"rrdinfo {file} | logger")
|
||||||
# check that this file contains a shortterm metric
|
# check that this file contains a shortterm metric
|
||||||
machine.succeed(f"rrdinfo {file} | grep -F 'ds[shortterm].min = '")
|
machine.succeed(f"rrdinfo {file} | grep -F 'ds[shortterm].min = '")
|
||||||
|
# check that interval was set before the plugins
|
||||||
|
machine.succeed(f"rrdinfo {file} | grep -F 'step = 30'")
|
||||||
# check that there are frequent updates
|
# check that there are frequent updates
|
||||||
machine.succeed(f"cp {file} before")
|
machine.succeed(f"cp {file} before")
|
||||||
machine.wait_until_fails(f"cmp before {file}")
|
machine.wait_until_fails(f"cmp before {file}")
|
||||||
|
Loading…
Reference in New Issue
Block a user