the easiest tool to monitoring a server is munin. It’s easy to install and has lots of plugins. Installing munin on a server, which is to be monitored, is not really a smart move. Seeing a raspberry pi laying on a closet and do nothing, gives me the idea to use it to monitor my vServer. The problem is how to configure munin-node to communicate with munin, which is behind a dynamic IP. But one step after the other 🙂
First move is to grab a SD-Card and flash Raspbian from Raspberry Pi website. This is an easy task.
Next task is to assign a static IP address.
just edit the
/etc/network/interfaces file. Comment out following line
#iface eth0 inet dhcp
and add following line. Change the IP address to match your network
1 2 3 4
iface eth0 inet static address 192.168.0.212 netmask 255.255.255.0 gateway 192.168.0.1
Reboot your pi and it can be reached with the new IP 18.104.22.168.
Now let’s install munin-node on the remote server. Since I’m using Ubuntu, it’s really a straight forward
sudo apt-get install munin-node
After finish installing, you can activate plugin by creating a link from
cd /etc/munin/plugins sudo ln -s /usr/share/munin/plugins/
and don’t forget to restart the munin-node service
sudo service munin-node restart
Now here come’s the problem. According to munin-node documentation, you can specify an IP address of your munin server. The default config is 127.0.0.1
since my raspberry pi is behind a normal DSL line and it has dynamic IP address, it’s too much problem to change the IP address daily. Of course if you have a DynDNS (or other dynamic DNS service), you can write a bash script to get the IP address by querying your DynDNS, change the IP address and restart the munin-node service. But you don’t know, how often your DSL modem gets new IP address, etc.
My solution is SSH tunnel. I don’t change munin-node config. So it will only allow connection from 127.0.0.1. I just need to create a SSH tunnel from my Raspberry to my remote server. Munin uses port 4949 to connect to their nodes. So I just need to tell munin to use other port for my remote server.
in munin.conf I add following line
1 2 3 4
[myserver] address 127.0.0.1 use_node_name yes port 4950
as you can see, I declare that myserver has the IP 127.0.0.1 (local) but with port 4950. Here comes the magic 🙂
ssh -i /path/to/ssh_private_key -L 4950:127.0.0.1:4949 remote_user@remote_ip
the line tunnels the local port 4950 to remote 4949. Munin (server) will queries port 4950 and ssh tunnels it to remote server. Munin-node will get the queries in local (127.0.0.1) port 4949.
But what if when the SSH process is killed? Don’t worry, there’s a solution for that too 🙂 Install
autossh. With -f, autossh runs in background and it’ll restart, if the connection is skilled.
autossh -f -i /path/to/ssh_private_key -L 4950:127.0.0.1:4949 remote_user@remote_ip
Happy monitoring 🙂