Categories
Hardware Linux Software

Munin + Raspberry Pi + temperature: updated

I got a mail in my inbox about a week ago from Anthony, telling me how to improve my Munin & temp script for a RPi:

Hi,

I just read your (old) blog post about monitoring the temperature of the Raspberry Pi with munin[1].

I had the exact same error as you did when I was trying to let munin do the job all by himself:

> temp.value VCHI initialization failed)

It turns out the solution was quite easy: in

/etc/munin/plugin-conf.d/munin-node

You simply need to tell munin that it needs to run as root for this specific plugin:

> [pisense_]

> user root

(the plugins also tracks clock speeds and voltages but any other will work just fine as long as the “user root” is set in the munin-node plugin config file : [2]). Probably the easiest way to check if it’s working is to use munin-run command before and after the change.

“Demo”: [3]

By the way, “Connect different LANs over openVPN” is pretty tempting, I always wondered what the performances would be like through a USB-to-ethernet adapter.

Have a nice one !

Apteno

[1] https://yeri.be/munin-raspberry-pi-temperature
[2] https://github.com/perception101/pisense/blob/master/pisense_
[3] http://ronon.jefter.com/jefter.com/adama.jefter.com/index.html#sensors

And indeed, I knew it was a permission issue, but instead of running this script as root, I tried adding Munin to a group that was supposed to be able to run  vcgencmd (which didn’t work out).

But, let’s look at a simpler solution:

  1. Go to /etc/munin/plugins and create a file temp with this content (and some indentation yourself):
    #!/bin/sh
    case $1 in
    config)
    cat <<'EOM'
    graph_category system
    graph_title Temperature
    graph_vlabel temp
    temp.label Celsius
    EOM
    exit 0;;
    esac
    echo -n "temp.value "
    /opt/vc/bin/vcgencmd measure_temp | cut -d "=" -f2 | cut -d "'" -f1
  2. As you noticed, this doesn’t require any more scripts to run from cron (and thus, in case you used my previous script, remove it from cron)
  3. chmod +x temp
  4. Make sure it runs as root; in /etc/munin/plugin-conf.d create the file temp.conf with this content:
    [temp]
    user root
  5. Test it:
    # munin-run temp
    temp.value 59.5

Tadaaaa. Simpler.

Thanks Anthony 🙂

Categories
Linux

Graph amount of OpenVPN users to Munin

Rather simple script. Using log file instead of management interface.

vpnusers-day

Part has to run as Root (due to Munin most likely not having access to read the log files. Working with the management interface could solve this.

Create /usr/local/bin/getVpnUsers.sh:

#!/bin/bash
echo "VPN.value `cat /var/log/openvpn-status.log | sed -e '1,/Common Name/d' | 
sed -e '/ROUTING TABLE/,$d' | wc -l`" > /tmp/.vpn_munin.txt

You can change the name of VPN.value to the VPN name and/or add multiple lines (each with a different NAME.value if you’re running more than one VPN user. Be sure to cat the right log file).

And:

chmod +x /usr/local/bin/getVpnUsers.sh

Add this to root cron:

*/5 * * * * /usr/local/bin/getVpnUsers.sh >/dev/null 2>&1

Now create /etc/munin/plugins/vpnusers:

#!/bin/sh

case $1 in
 config)
 cat <<'EOM'
graph_category network
graph_title oVPN users
graph_vlabel users
VPN.label My oVPN
# add more labels like this:
#isazi.label Isazi VPN
EOM
 exit 0;;
esac

cat /tmp/.vpn_munin.txt

And:

chmod +x /etc/munin/plugins/vpnusers

You’ll need the correct NAME.label in the plugin depending on the name you choose in part one.

And restart munin-node:

/etc/init.d/munin-node restart

That’s it.

Check your Munin under “network”. It might take ~15+ minutes before the graph is generated.

vpnusers-day-1

Categories
Hardware Linux Software

Munin + Raspberry Pi + temperature

Quick hack to get Munin to graph the cpu temperature.

temp-day

First of all, install Munin and make sure it’s working.

Then follow these steps:

1) We’ll use cron to write the current temp to a log file. We do this because I wasn’t able to get Munin to directly execute the command (error: temp.value VCHI initialization failed)

Execute crontab -e and add this line (this has to be on one line):

*/5 * * * * /opt/vc/bin/vcgencmd measure_temp | cut -d "=" -f2 | cut -d "'" -f1 > /tmp/.temp

2) Go to /etc/munin/plugins/, and create a file temp, and add this content:

#!/bin/sh
case $1 in
config)
cat <<'EOM'
graph_category system
graph_title Temperature
graph_vlabel temp
temp.label Celsius
EOM
exit 0;;
esac
echo -n "temp.value "
cat /tmp/.temp

Save and exit the editor.

I’m not sure this is needed, but better do it: chmod +x temp

3) restart munin-node (/etc/init.d/munin-node restart)

4) test if it’s working:

# telnet localhost 4949
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
# munin node at industry.yeri.be
fetch temp
temp.value 57.3
.

That’s it. Your munin daemon/host should now correctly graph the temperature.

Edit (8/2/2014): updated script can be found here.