2015-01-28 15:10:44 +00:00
#!/bin/bash
# Munin: resource monitoring tool
#################################################
source setup/functions.sh # load our functions
source /etc/mailinabox.conf # load global vars
# install Munin
2015-08-19 19:58:35 +00:00
echo "Installing Munin (system monitoring)..."
2016-01-14 04:55:45 +00:00
apt_install munin munin-node libcgi-fast-perl
# libcgi-fast-perl is needed by /usr/lib/munin/cgi/munin-cgi-graph
2015-01-28 15:10:44 +00:00
# edit config
cat > /etc/munin/munin.conf <<EOF;
2015-05-25 17:01:53 +00:00
dbdir /var/lib/munin
htmldir /var/cache/munin/www
logdir /var/log/munin
rundir /var/run/munin
tmpldir /etc/munin/templates
includedir /etc/munin/munin-conf.d
2016-01-14 03:20:33 +00:00
# path dynazoom uses for requests
cgiurl_graph /admin/munin/cgi-graph
2015-05-25 17:01:53 +00:00
# a simple host tree
[ $PRIMARY_HOSTNAME ]
address 127.0.0.1
# send alerts to the following address
contacts admin
2018-11-30 15:24:19 +00:00
contact.admin.command mail -s "Munin notification \${var:host}" administrator@$PRIMARY_HOSTNAME
2015-05-25 17:01:53 +00:00
contact.admin.always_send warning critical
2015-01-28 15:10:44 +00:00
EOF
2016-01-14 04:55:45 +00:00
# The Debian installer touches these files and chowns them to www-data:adm for use with spawn-fcgi
chown munin. /var/log/munin/munin-cgi-html.log
chown munin. /var/log/munin/munin-cgi-graph.log
2015-07-22 21:01:17 +00:00
# ensure munin-node knows the name of this machine
2018-01-19 17:00:44 +00:00
# and reduce logging level to warning
2015-07-22 21:01:17 +00:00
tools/editconf.py /etc/munin/munin-node.conf -s \
2018-01-19 17:00:44 +00:00
host_name = $PRIMARY_HOSTNAME \
log_level = 1
2015-07-22 21:01:17 +00:00
2015-08-23 16:03:40 +00:00
# Update the activated plugins through munin's autoconfiguration.
2018-12-14 01:30:05 +00:00
munin-node-configure --shell --remove-also 2>/dev/null | sh || /bin/true
2015-08-23 16:03:40 +00:00
# Deactivate monitoring of NTP peers. Not sure why anyone would want to monitor a NTP peer. The addresses seem to change
# (which is taken care of my munin-node-configure, but only when we re-run it.)
2015-10-10 16:48:49 +00:00
find /etc/munin/plugins/ -lname /usr/share/munin/plugins/ntp_ -print0 | xargs -0 /bin/rm -f
2015-08-23 16:03:40 +00:00
# Deactivate monitoring of network interfaces that are not up. Otherwise we can get a lot of empty charts.
for f in $( find /etc/munin/plugins/ \( -lname /usr/share/munin/plugins/if_ -o -lname /usr/share/munin/plugins/if_err_ -o -lname /usr/share/munin/plugins/bonding_err_ \) ) ; do
IF = $( echo $f | sed s/.*_//) ;
2019-12-01 21:21:38 +00:00
if ! grep -qFx up /sys/class/net/$IF /operstate 2>/dev/null; then
2015-08-23 16:03:40 +00:00
rm $f ;
fi ;
done
# Create a 'state' directory. Not sure why we need to do this manually.
mkdir -p /var/lib/munin-node/plugin-state/
2018-07-07 18:41:41 +00:00
# Create a systemd service for munin.
ln -sf $( pwd ) /management/munin_start.sh /usr/local/lib/mailinabox/munin_start.sh
chmod 0744 /usr/local/lib/mailinabox/munin_start.sh
2019-12-01 21:15:04 +00:00
cp -f conf/munin.service /lib/systemd/system/munin.service
hide_output systemctl link -f /lib/systemd/system/munin.service
2018-07-07 18:41:41 +00:00
hide_output systemctl daemon-reload
hide_output systemctl unmask munin.service
hide_output systemctl enable munin.service
2015-08-23 16:03:40 +00:00
# Restart services.
restart_service munin
restart_service munin-node
2015-05-25 17:01:53 +00:00
# generate initial statistics so the directory isn't empty
2015-08-23 16:42:39 +00:00
# (We get "Pango-WARNING **: error opening config file '/root/.config/pango/pangorc': Permission denied"
# if we don't explicitly set the HOME directory when sudo'ing.)
2019-05-15 18:58:40 +00:00
# We check to see if munin-cron is already running, if it is, there is no need to run it simultaneously
# generating an error.
if [ ! -f /var/run/munin/munin-update.lock ] ; then
sudo -H -u munin munin-cron
fi