Munin on Raspberry Pi with dynamic IP

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

and add following line. Change the IP address to match your network

Reboot your pi and it can be reached with the new IP 192.160.0.212.

Next step is installing munin on pi. For this task I’m using how-to from here. There’s nothing special here…. πŸ™‚

Now let’s install munin-node on the remote server. Since I’m using Ubuntu, it’s really a straight forward

After finish installing, you can activate plugin by creating a link from /usr/share/munin/plugins/ to /etc/munin/plugins
e.g:

and don’t forget to restart the munin-node service

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

as you can see, I declare that myserver has the IP 127.0.0.1 (local) but with port 4950. Here comes the magic πŸ™‚

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.

Happy monitoring πŸ™‚

2 thoughts on “Munin on Raspberry Pi with dynamic IP”

  1. Hi, i’m not sure if i understood correctly. So you’re using master munin on RPI right? And trying to connect some other remote server to be visible inside munin?

    Maybe you could advise me in little bit different configuration:
    external server is master munin, i’d like to connect my RPI to it but it’s behind router, i’m trying to forward 4949 port to rpi (somehow there’s an issue with that) – is this a correct solution?
    Any other options? Like a tunnel you did but in some other configuration?

    1. your raspi is the client (node) and your master (in the cloud) wants to access raspi? then you must register the IP of your master in the node (raspi), beside port forwarding on you router.

      my howto uses a SSH tunnel, so that the node is seen as 127.0.0.1 from the master (just different port). If you’re using SSH tunnel from server to node (raspi), then you need to forward the SSH Port (22) on your router.

Leave a Reply

Your email address will not be published. Required fields are marked *