2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-10-15 02:16:10 +01:00
|
|
|
|
|
|
|
# TODO: support munin-async
|
|
|
|
# TODO: LWP/Pg perl libs aren't recognized
|
|
|
|
|
|
|
|
# TODO: support fastcgi
|
2018-12-13 23:08:56 +00:00
|
|
|
# http://guide.munin-monitoring.org/en/latest/example/webserver/apache-cgi.html
|
2018-10-03 16:36:37 +01:00
|
|
|
# spawn-fcgi -s /run/munin/fastcgi-graph.sock -U www-data -u munin -g munin /usr/lib/munin/cgi/munin-cgi-graph
|
|
|
|
# spawn-fcgi -s /run/munin/fastcgi-html.sock -U www-data -u munin -g munin /usr/lib/munin/cgi/munin-cgi-html
|
2013-10-15 02:16:10 +01:00
|
|
|
# https://paste.sh/vofcctHP#-KbDSXVeWoifYncZmLfZzgum
|
|
|
|
# nginx http://munin.readthedocs.org/en/latest/example/webserver/nginx.html
|
|
|
|
|
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2013-10-15 02:16:10 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
nodeCfg = config.services.munin-node;
|
|
|
|
cronCfg = config.services.munin-cron;
|
|
|
|
|
|
|
|
muninConf = pkgs.writeText "munin.conf"
|
|
|
|
''
|
|
|
|
dbdir /var/lib/munin
|
|
|
|
htmldir /var/www/munin
|
|
|
|
logdir /var/log/munin
|
2018-10-03 16:36:37 +01:00
|
|
|
rundir /run/munin
|
2013-10-15 02:16:10 +01:00
|
|
|
|
|
|
|
${cronCfg.extraGlobalConfig}
|
2014-09-05 14:50:55 +01:00
|
|
|
|
2013-10-15 02:16:10 +01:00
|
|
|
${cronCfg.hosts}
|
|
|
|
'';
|
|
|
|
|
|
|
|
nodeConf = pkgs.writeText "munin-node.conf"
|
|
|
|
''
|
|
|
|
log_level 3
|
|
|
|
log_file Sys::Syslog
|
|
|
|
port 4949
|
|
|
|
host *
|
|
|
|
background 0
|
|
|
|
user root
|
|
|
|
group root
|
|
|
|
host_name ${config.networking.hostName}
|
|
|
|
setsid 0
|
2014-09-05 14:50:55 +01:00
|
|
|
|
2013-10-15 02:16:10 +01:00
|
|
|
# wrapped plugins by makeWrapper being with dots
|
|
|
|
ignore_file ^\.
|
2014-09-05 14:50:55 +01:00
|
|
|
|
2017-02-20 05:13:48 +00:00
|
|
|
allow ^::1$
|
2013-10-15 02:16:10 +01:00
|
|
|
allow ^127\.0\.0\.1$
|
|
|
|
|
|
|
|
${nodeCfg.extraConfig}
|
|
|
|
'';
|
2017-11-21 17:40:40 +00:00
|
|
|
|
|
|
|
pluginConf = pkgs.writeText "munin-plugin-conf"
|
|
|
|
''
|
|
|
|
[hddtemp_smartctl]
|
|
|
|
user root
|
|
|
|
group root
|
|
|
|
|
|
|
|
[meminfo]
|
|
|
|
user root
|
|
|
|
group root
|
|
|
|
|
|
|
|
[ipmi*]
|
|
|
|
user root
|
|
|
|
group root
|
2018-12-13 23:14:21 +00:00
|
|
|
|
|
|
|
${nodeCfg.extraPluginConfig}
|
2017-11-21 17:40:40 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
pluginConfDir = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "munin-plugin-conf.d";
|
|
|
|
buildCommand = ''
|
|
|
|
mkdir $out
|
|
|
|
ln -s ${pluginConf} $out/nixos-config
|
|
|
|
'';
|
|
|
|
};
|
2013-10-15 02:16:10 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.munin-node = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable Munin Node agent. Munin node listens on 0.0.0.0 and
|
|
|
|
by default accepts connections only from 127.0.0.1 for security reasons.
|
|
|
|
|
2018-12-13 23:08:56 +00:00
|
|
|
See <link xlink:href='http://guide.munin-monitoring.org/en/latest/architecture/index.html' />.
|
2013-10-15 02:16:10 +01:00
|
|
|
'';
|
|
|
|
};
|
2014-09-05 14:50:55 +01:00
|
|
|
|
2013-10-15 02:16:10 +01:00
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
2016-10-23 18:33:41 +01:00
|
|
|
type = types.lines;
|
2013-10-15 02:16:10 +01:00
|
|
|
description = ''
|
|
|
|
<filename>munin-node.conf</filename> extra configuration. See
|
2018-12-13 23:08:56 +00:00
|
|
|
<link xlink:href='http://guide.munin-monitoring.org/en/latest/reference/munin-node.conf.html' />
|
2013-10-15 02:16:10 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# TODO: add option to add additional plugins
|
2018-12-13 23:14:21 +00:00
|
|
|
extraPluginConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
|
|
|
description = ''
|
|
|
|
<filename>plugin-conf.d</filename> extra plugin configuration. See
|
|
|
|
<link xlink:href='http://guide.munin-monitoring.org/en/latest/plugin/use.html' />
|
|
|
|
'';
|
|
|
|
example = ''
|
|
|
|
[fail2ban_*]
|
|
|
|
user root
|
|
|
|
'';
|
|
|
|
};
|
2013-10-15 02:16:10 +01:00
|
|
|
|
2018-12-13 23:16:07 +00:00
|
|
|
disabledPlugins = mkOption {
|
|
|
|
default = [];
|
|
|
|
type = with types; listOf string;
|
|
|
|
description = ''
|
|
|
|
Munin plugins to disable, even if
|
|
|
|
<literal>munin-node-configure --suggest</literal> tries to enable
|
|
|
|
them. To disable a wildcard plugin, use an actual wildcard, as in
|
|
|
|
the example.
|
|
|
|
'';
|
|
|
|
example = [ "diskstats" "zfs_usage_*" ];
|
|
|
|
};
|
2013-10-15 02:16:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
services.munin-cron = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable munin-cron. Takes care of all heavy lifting to collect data from
|
|
|
|
nodes and draws graphs to html. Runs munin-update, munin-limits,
|
|
|
|
munin-graphs and munin-html in that order.
|
2014-09-05 14:50:55 +01:00
|
|
|
|
2013-10-15 02:16:10 +01:00
|
|
|
HTML output is in <filename>/var/www/munin/</filename>, configure your
|
|
|
|
favourite webserver to serve static files.
|
|
|
|
'';
|
|
|
|
};
|
2014-09-05 14:50:55 +01:00
|
|
|
|
2013-10-15 02:16:10 +01:00
|
|
|
extraGlobalConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
<filename>munin.conf</filename> extra global configuration.
|
2018-12-13 23:08:56 +00:00
|
|
|
See <link xlink:href='http://guide.munin-monitoring.org/en/latest/reference/munin.conf.html' />.
|
2013-10-15 02:16:10 +01:00
|
|
|
Useful to setup notifications, see
|
2018-12-13 23:08:56 +00:00
|
|
|
<link xlink:href='http://guide.munin-monitoring.org/en/latest/tutorial/alert.html' />
|
2013-10-15 02:16:10 +01:00
|
|
|
'';
|
2016-01-17 18:34:55 +00:00
|
|
|
example = ''
|
|
|
|
contact.email.command mail -s "Munin notification for ''${var:host}" someone@example.com
|
|
|
|
'';
|
2013-10-15 02:16:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
hosts = mkOption {
|
|
|
|
example = ''
|
|
|
|
[''${config.networking.hostName}]
|
|
|
|
address localhost
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Definitions of hosts of nodes to collect data from. Needs at least one
|
2018-12-13 23:08:56 +00:00
|
|
|
host for cron to succeed. See
|
|
|
|
<link xlink:href='http://guide.munin-monitoring.org/en/latest/reference/munin.conf.html' />
|
2013-10-15 02:16:10 +01:00
|
|
|
'';
|
|
|
|
};
|
2014-09-05 14:50:55 +01:00
|
|
|
|
2013-10-15 02:16:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkMerge [ (mkIf (nodeCfg.enable || cronCfg.enable) {
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.munin ];
|
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.users = [{
|
2013-10-15 02:16:10 +01:00
|
|
|
name = "munin";
|
|
|
|
description = "Munin monitoring user";
|
|
|
|
group = "munin";
|
2014-02-07 22:08:15 +00:00
|
|
|
uid = config.ids.uids.munin;
|
2013-10-15 02:16:10 +01:00
|
|
|
}];
|
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.groups = [{
|
2013-10-15 02:16:10 +01:00
|
|
|
name = "munin";
|
2014-02-07 22:08:15 +00:00
|
|
|
gid = config.ids.gids.munin;
|
2013-10-15 02:16:10 +01:00
|
|
|
}];
|
|
|
|
|
|
|
|
}) (mkIf nodeCfg.enable {
|
|
|
|
|
|
|
|
systemd.services.munin-node = {
|
2013-11-09 19:06:01 +00:00
|
|
|
description = "Munin Node";
|
2013-10-15 02:16:10 +01:00
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2017-11-21 17:40:40 +00:00
|
|
|
path = with pkgs; [ munin smartmontools "/run/current-system/sw" "/run/wrappers" ];
|
|
|
|
environment.MUNIN_LIBDIR = "${pkgs.munin}/lib";
|
2018-10-03 16:36:37 +01:00
|
|
|
environment.MUNIN_PLUGSTATE = "/run/munin";
|
2017-11-21 17:40:40 +00:00
|
|
|
environment.MUNIN_LOGDIR = "/var/log/munin";
|
2014-07-24 10:45:07 +01:00
|
|
|
preStart = ''
|
2018-12-13 23:08:56 +00:00
|
|
|
echo "Updating munin plugins..."
|
2014-07-24 10:45:07 +01:00
|
|
|
|
|
|
|
mkdir -p /etc/munin/plugins
|
|
|
|
rm -rf /etc/munin/plugins/*
|
2018-12-13 23:16:07 +00:00
|
|
|
|
|
|
|
# Autoconfigure builtin plugins
|
2017-11-21 17:40:40 +00:00
|
|
|
${pkgs.munin}/bin/munin-node-configure --suggest --shell --families contrib,auto,manual --config ${nodeConf} --libdir=${pkgs.munin}/lib/plugins --servicedir=/etc/munin/plugins --sconfdir=${pluginConfDir} 2>/dev/null | ${pkgs.bash}/bin/bash
|
|
|
|
|
2018-12-13 23:16:07 +00:00
|
|
|
|
|
|
|
${lib.optionalString (nodeCfg.disabledPlugins != []) ''
|
|
|
|
# Disable plugins
|
|
|
|
cd /etc/munin/plugins
|
|
|
|
rm -f ${toString nodeCfg.disabledPlugins}
|
|
|
|
''}
|
2014-07-24 10:45:07 +01:00
|
|
|
'';
|
2013-10-15 02:16:10 +01:00
|
|
|
serviceConfig = {
|
2017-11-21 17:40:40 +00:00
|
|
|
ExecStart = "${pkgs.munin}/sbin/munin-node --config ${nodeConf} --servicedir /etc/munin/plugins/ --sconfdir=${pluginConfDir}";
|
2013-10-15 02:16:10 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-10-13 23:28:39 +01:00
|
|
|
# munin_stats plugin breaks as of 2.0.33 when this doesn't exist
|
2018-10-03 16:36:37 +01:00
|
|
|
systemd.tmpfiles.rules = [ "d /run/munin 0755 munin munin -" ];
|
2017-10-13 23:28:39 +01:00
|
|
|
|
2013-10-15 02:16:10 +01:00
|
|
|
}) (mkIf cronCfg.enable {
|
|
|
|
|
2017-03-21 23:08:41 +00:00
|
|
|
systemd.timers.munin-cron = {
|
|
|
|
description = "batch Munin master programs";
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
timerConfig.OnCalendar = "*:0/5";
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.munin-cron = {
|
|
|
|
description = "batch Munin master programs";
|
|
|
|
unitConfig.Documentation = "man:munin-cron(8)";
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
User = "munin";
|
|
|
|
ExecStart = "${pkgs.munin}/bin/munin-cron --config ${muninConf}";
|
|
|
|
};
|
|
|
|
};
|
2013-10-15 02:16:10 +01:00
|
|
|
|
2017-10-13 23:38:32 +01:00
|
|
|
systemd.tmpfiles.rules = [
|
2018-10-03 16:36:37 +01:00
|
|
|
"d /run/munin 0755 munin munin -"
|
2017-10-13 23:38:32 +01:00
|
|
|
"d /var/log/munin 0755 munin munin -"
|
|
|
|
"d /var/www/munin 0755 munin munin -"
|
|
|
|
"d /var/lib/munin 0755 munin munin -"
|
|
|
|
];
|
2013-10-15 02:16:10 +01:00
|
|
|
})];
|
|
|
|
}
|