Munin
Install Munin to the server
sudo apt-get install munin
Dynamic graphics
To be able to zoom in the graphics, edit /etc/munin/munin.conf and change:
html_strategy cgi graph_strategy cgi
Nginx webserver
If using Nginx, add to your host config (ex. /etc/nginx/sites-enabled/default ):
location /munin/static/ {
alias /etc/munin/static/;
expires modified +1w;
}
# location /munin {
# # auth_basic "Restricted";
# # Create the htpasswd file with the htpasswd tool.
# # auth_basic_user_file /etc/nginx/htpasswd;
#
# alias /var/cache/munin/www;
# expires modified +310s;
# }
location /munin/ {
fastcgi_split_path_info ^(/munin)(.*);
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/munin/fastcgi-html.sock;
include fastcgi_params;
}
location ^~ /munin-cgi/munin-cgi-graph/ {
fastcgi_split_path_info ^(/munin-cgi/munin-cgi-graph)(.*);
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/munin/fastcgi-graph.sock;
include fastcgi_params;
}
Create a new service file:
cat /etc/init.d/munin-fcgi-marti
#!/bin/bash
### BEGIN INIT INFO
# Provides: munin-fcgi
# Required-Start: $remote_fs $syslog $network
# Required-Stop: $remote_fs $syslog $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start munin FCGI processes at boot time
# Description: Start the FCGI processes behind http://munin.*/
### END INIT INFO
graph_pidfile="/var/run/munin/fcgi_graph.pid"
# Ubuntu 12.10: /usr/lib/cgi-bin/munin-cgi-graph
graph_cgi="/usr/lib/munin/cgi/munin-cgi-graph"
html_pidfile="/var/run/munin/fcgi_html.pid"
# Ubuntu 12.10: /usr/lib/cgi-bin/munin-cgi-html
html_cgi="/usr/lib/munin/cgi/munin-cgi-html"
retval=0
. /lib/lsb/init-functions
start() {
echo -n "Starting munin graph FastCGI: "
start_daemon -p ${graph_pidfile} /usr/bin/spawn-fcgi -u munin -g munin \
-s /var/run/munin/fastcgi-graph.sock -U www-data ${graph_cgi}
echo
echo -n "Starting munin html FastCGI: "
start_daemon -p ${html_pidfile} /usr/bin/spawn-fcgi -u munin -g munin \
-s /var/run/munin/fastcgi-html.sock -U www-data ${html_cgi}
echo
retval=$?
}
stop() {
echo -n "Stopping munin graph FastCGI: "
killproc -p ${graph_pidfile} ${graph_cgi} -QUIT
echo
echo -n "Stopping munin html FastCGI: "
killproc -p ${html_pidfile} ${html_cgi} -QUIT
echo
retval=$?
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: munin-fcgi {start|stop|restart}"
exit 1
;;
esac
exit $retval
Start it:
service munin-fcgi-marti restart
Add it to autostart:
update-rc.d munin-fcgi-marti defaults
Install Munin to a client
First you need to install munin client package using the following commands
sudo apt-get install munin-node
Now you need to edit the munin-node.conf file to specify that your monitoring server is allowed to poll the client for information.
sudo vi /etc/munin/munin-node.conf
Search for the section that has the line "allow ^127\.0\.0\.1$". Modify the IP address to reflect your monitoring server's IP address.If your server ip is 172.30.2.100
allow ^\.172\.30\.2\.100$
Save and exit the file
You need to restart the munin client using the following information
sudo service munin-node restart
Now you need to login in to your munin server and edit the munin.conf file
sudo vi /etc/munin/munin.conf
Copy the following section and change the ip address to your remote server client ip address
[MuninMonitor] address 127.0.0.1 use_node_name yes
to
[MuninMonitor] address 172.30.2.101 use_node_name yes
Finall you need to restart the apache server using the following command
sudo service apache2 restart
Add variables
/usr/sbin/munin-node-configure --suggest /usr/sbin/munin-node-configure --shell | sh /etc/init.d/munin-node restart
Additional Plugins
The munin-plugins-extra package contains performance checks additional services such as DNS, DHCP, Samba, etc. To install the package run the following command from the terminal
sudo apt-get install munin-plugins-extra
Make sure you have install this package on both the server and node machines.
Info from: http://www.ubuntugeek.com/install-munin-monitoring-tool-on-ubuntu-14-04-server.html
TCP ping plugin
Create file /usr/share/munin-marti/tcp_multi_ping'
cat tcp_multi_ping
#!/usr/bin/perl
=head1 NAME
multi_tcp_ping - Graphs together the TCP ping results for several hosts
=head1 SYNOPSIS
This plugin is meant to be called from Munin. You should set the
'hosts' environment variable from Munin's configuration (i.e.
/etc/munin/munin.conf) to specify which hosts and ports to query.
=head1 DESCRIPTION
This plugin expects to receive the following environment variables:
=over 4
=item hosts (REQUIRED!)
Comma-separated list of hosts to query. You can specify the TCP port
to connect to on each of the hosts by listing them as host:port - The
port defaults to 80. The following is a valid hosts declaration:
hosts='192.168.0.15, 192.168.0.18:22'
It will query host 192.168.0.15 on the default port (80), as well as
host 192.168.0.18 on port 22.
=back
If the connection was opened successfully, it gives as the return
value the time it took to establish the connection. If the requested
host is not reachable, a hard-wired '-0.01' will be returned. Why
-0.01? Because giving a negative value is the best way to easily get
-visually- that something failed. Connection establishment times are
usually in the 5-500ms range. 100ms will be not too little (and thus
invisible), not too much (and thus killing the details in our graphs).
=head1 DEPENDS ON
L<Net::Ping>
=head1 SEE ALSO
L<munin>, L<munin-node>
=head1 AUTHOR
Gunnar Wolf <[email protected]>
=head1 COPYRIGHT
Copyright 2008 Gunnar Wolf, Instituto de Investigaciones
Economicas, UNAM. This plugin is Free Software; you can
redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation; version 2
dated June, 1991, or any later version (at your choice).
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
=cut
use strict;
use warnings;
# This evil "eval" is to make Travis CI able to test the plugin syntax
# without having a perl built with threads.
#
# Also: The use of interpreter-based threads in perl is officially
# discouraged.
eval 'use threads; 1;' or die 'Could not use threads';
use Net::Ping;
my (%defaults, @hosts, $cmd_arg, $config_file_name);
%defaults = (port => 80, timeout => 2, unreachable => -0.01);
#$config_file_name = "/usr/share/munin/plugins/hostslist.ip";
$config_file_name = "/usr/share/munin-marti/tcp_multi_ping.ip";
open (IN_FILE,"<$config_file_name") or die "Unable to open file hostslist.ip";
while (<IN_FILE>){
# if (/\d+\.\d+\.\d+\.\d+/){
s/\s//g; push (@hosts,[$_,$defaults{port}]);
# }
}
# @hosts = get_hosts($ENV{hosts});
die "Hosts not set - cannot continue\n" unless @hosts;
$cmd_arg = $ARGV[0] || '';
config() if($cmd_arg eq "config");
autoconf() if ($cmd_arg eq 'autoconf');
for my $host (@hosts) {
threads->new(\&ping_host, $host)
}
map {$_->join} threads->list;
exit 0;
sub ping_host {
my ($host, $addr, $p, $ret, $time, $ip);
$host = shift;
$addr = host_label_for($host);
$p=Net::Ping->new("tcp", $defaults{timeout});
$p->hires();
$p->{port_num} = $host->[1] || $defaults{port};
($ret, $time, $ip) = $p->ping($host->[0]);
$time = $defaults{unreachable} if !$ret;
print "${addr}.value $time\n";
}
sub get_hosts {
# Hosts are defined in the 'hosts' environment variable. It's a list of
# hosts (and optionally ports) - We parse the list and arrange it neatly
# to be easily consumed.
my ($hostsdef, @hosts);
$hostsdef = shift;
return unless $hostsdef;
for my $host (split(/,/, $hostsdef)) {
$host =~ s/\s//g;
$host =~ /^(?:([^:]+))
(?::(\d+))?$/x;
push @hosts, [$1, $2 || $defaults{port}];
}
return @hosts;
}
sub config {
my @res = ("graph_title TCP connection times",
"graph_args --base 1000 -l 0",
"graph_vlabel seconds",
"graph_category network",
"graph_info Shows the time to establish a TCP connection");
for my $host (@hosts) {
my $addr = host_label_for($host);
push @res, "$addr.label $addr";
push @res, "$addr.draw LINE2";
push @res, "$addr.info Time to establish TCP connection to " .
"$host->[0]:$host->[1]";
}
print map {"$_\n"} @res;
exit 0;
}
sub autoconf {
print "yes\n";
exit 0;
}
sub host_label_for {
my ($ip, $port) = @{$_[0]};
# Periods and colonsare not allowed in variable names
my $addr = "src_${ip}_${port}";
$addr =~ s/\./_/g;
return $addr;
}
Put all your hosts to /usr/share/munin-marti/tcp_multi_ping.ip
google.com hostssh.com:22
Create link:
ln -s '/usr/share/munin-marti/tcp_multi_ping' '/etc/munin/plugins/tcp_multi_ping'
Restart munin-node