4.5 KiB
4.5 KiB
Resource Monitoring
The below commands will setup munin
for monitoring resource utilization on your PiFrame. This is wholly optional but can provide insights if your PiFrame is exhibiting odd behavior.
Important Notes
- This setup will deploy a dedicated instance of
lighttpd
to handle access to themunin
data. Given how leanlighttpd
is on resources, this saves many hassles with virtual hosts and the like. - This setup uses cgi to generate
munin
graphs. The Raspberry Pi cpu can take awhile to generate graphs. Please be patient. This approach was chosen to keepmunin
from consuming resource generating graphs every time it collects statistics. This also helps prevent excessive disk writes to the micro sd card extending its life.
Setup
apt install munin
nano -w /etc/munin/munin.conf
graph_strategy cgi
html_strategy cron
[piframe]
address 127.0.0.1
use_node_name yes
touch /var/log/munin/munin-cgi-graph.log
chown munin: /var/log/munin/munin-cgi-graph.log
munin-node-configure --shell # activate useful plugins
sudo -sHu munin munin-cron # prime munin data
systemctl enable --now munin-node
systemctl restart munin-node
cat > /etc/lighttpd/lighttpd-munin.conf <<EOF
# Apply the following tweaks to the /etc/munin/munin.conf file ahead of running lighttpd for munin
## Use cgi rendering for graph and html
#graph_strategy cgi
#html_strategy cron
server.username = "munin"
server.groupname = "munin"
server.document-root = "/var/www/html"
server.port = 2813
server.errorlog = "/dev/stdout"
accesslog.filename = "/dev/stdout"
dir-listing.activate = "disable"
server.modules = (
"mod_access",
"mod_accesslog",
"mod_alias",
"mod_rewrite",
"mod_redirect",
"mod_cgi",
"mod_fastcgi",
"mod_auth",
"mod_authn_file",
)
auth.backend = "htdigest"
auth.backend.htdigest.userfile = "/etc/lighttpd/munin.auth"
auth.require = ( "/" =>
(
"method" => "basic",
"realm" => "Munin",
"require" => "valid-user"
)
)
server.pid-file = "/run/lighttpd-munin.pid"
server.follow-symlink = "enable"
index-file.names = ( "index.html", "index.htm" )
url.redirect += ( "^/*$" => "/munin/" )
\$HTTP["url"] =~ "/munin-cgi/munin-cgi-graph" {
alias.url += ( "/munin-cgi/munin-cgi-graph" => "/usr/lib/munin/cgi/munin-cgi-graph" )
cgi.assign = ( "" => "" )
}
alias.url += ( "/munin/static" => "/etc/munin/static" )
alias.url += ( "/munin" => "/var/cache/munin/www" )
mimetype.assign = (
".html" => "text/html",
".txt" => "text/plain",
".css" => "text/css",
".js" => "application/x-javascript",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".gif" => "image/gif",
".png" => "image/png",
"" => "application/octet-stream"
)
EOF
cat > /etc/systemd/system/lighttpd-munin.service <<EOF
[Unit]
Description=Lighttpd Web Server (munin)
After=syslog.target network.target
[Service]
PrivateTmp=true
ExecStart=/usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd-munin.conf
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
[Install]
WantedBy=multi-user.target
EOF
cat > /root/lighttpd-auth.pl <<EOF
#!/usr/bin/perl
print "User: ";
\$user = <>;
chomp \$user;
print "Realm: ";
\$realm = <>;
chomp \$realm;
use Term::ReadKey;
{
ReadMode('noecho');
print "Password: ";
\$password = ReadLine(0);
chomp \$password;
print "\\nPassword again: ";
\$password2 = ReadLine(0);
chomp \$password2;
ReadMode('normal');
print "\\n";
if(\$password ne \$password2)
{
print "Passwords don't match\\n";
redo;
}
}
print "\$user:\$realm:";
open(MD5, "|md5sum | cut -b -32") or die;
print MD5 "\$user:\$realm:\$password";
close(MD5);
EOF
chmod a+x /root/lighttpd-auth.pl
apt install libterm-readkey-perl
/root/lighttpd-auth.pl
echo "above_output" >> /etc/lighttpd/munin.auth
systemctl daemon-reload
systemctl enable --now lighttpd-munin
firewall-cmd --zone=public --permanent --add-port=2813/tcp
firewall-cmd --reload