GearPower
Posts: 4
Joined: Thu Jan 14, 2016 10:22 pm

Munin temperature plugin problem

Thu Jan 14, 2016 10:43 pm

Hi

I'm new to the forum so hello everybody and thanks for your reading :)

I bought a Raspberry Pi B+ about a year ago to monitor temperature in my house.
I was running on Raspbian Wheezy, sensors are 12 X Ds18B20 and I'm using Munin to log and graph.

Everything was running like a charm since this moment, munin was graphing all the 12 sensors on a single graphic like I wanted it to.

This weekend, we had strong winds and a lot of power outage here in Quebec, Canada, Raspberry wouldn't boot after, I only got kernel panic errors. I tried to recover my SD Card data but it was corrupted. My only choice was to format and start again. (No I haven't got any backup... next time!!!)

So I'm now with a new install of Raspbian Jessie, did update, upgrade, in static IP, installed Munin-node, Apache2, all the stuff for 1-wire sensors....

My problem is here:

When I run the Munin-run command on my temp plugin, I'm seeing all my sensors data like I should:

pi@raspberrypi:~ $ sudo munin-run temp
exterieur.value -12.25
airchaud.value 20.875
cuisine.value 19.5
poele.value 29.812
2eetage.value 18.812
eauchaude.value 33.687
cave.value 21.125
eaufroide.value 15.625
piscine.value -0.562
cheminee.value 26.437
solage.value 4.125
grenier.value -12.5
pi@raspberrypi:~ $

But in my graph temp-day.png, I only got the first value line logging (exterieur)

I grabbed the shell script from
https://blog.bandinelli.net/index.php?p ... 0-et-Munin
and duplicated it 12 times as I dit a year ago.

Here's the first 2 sensors part of the plugin:

#!/bin/sh

case $1 in
config)
cat <<'EOM'
graph_title Temperature probe 1
graph_vlabel temperature_1
exterieur.label exterieur
EOM
exit 0;;
esac

printf "exterieur.value "
cat /sys/bus/w1/devices/28-00000687a877/w1_slave | grep "t=" | awk -F "t=" '{print $2/1000}'



case $1 in
config)
cat <<'EOM'

airchaud.label airchaud
EOM
exit 0;;
esac

printf "airchaud.value "
cat /sys/bus/w1/devices/28-0000068791ac/w1_slave | grep "t=" | awk -F "t=" '{print $2/1000}'


The rest is copy and paste of the 2nd sensor...

What's wrong with this plugin/script.

Thanks!

GearPower

User avatar
DougieLawson
Posts: 39302
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Munin temperature plugin problem

Fri Jan 15, 2016 8:29 am

GearPower wrote:

Code: Select all

#!/bin/sh

case $1 in
   config)
        cat <<'EOM'
graph_title Temperature probe 1
graph_vlabel temperature_1
exterieur.label exterieur
EOM
        exit 0;;
esac

printf "exterieur.value "
cat /sys/bus/w1/devices/28-00000687a877/w1_slave | grep "t=" | awk -F "t=" '{print $2/1000}'



case $1 in
   config)
        cat <<'EOM'

airchaud.label airchaud
EOM
        exit 0;;
esac

printf "airchaud.value "
cat /sys/bus/w1/devices/28-0000068791ac/w1_slave | grep "t=" | awk -F "t=" '{print $2/1000}'
Rewrite that as

Code: Select all

#!/bin/sh

case $1 in
   config)
        cat <<'EOM'
graph_title Temperature probe 1
graph_vlabel temperature_1
exterieur.label exterieur
EOM
        exit 0;;
## esac  <=== delete me

printf "exterieur.value "
cat /sys/bus/w1/devices/28-00000687a877/w1_slave | grep "t=" | awk -F "t=" '{print $2/1000}'



### case $1 in <=== delete me
###   config)     <=== delete me
        cat <<'EOM'

airchaud.label airchaud
EOM
        exit 0;;
esac       # <=== only include me after the last sensor's code

printf "airchaud.value "
cat /sys/bus/w1/devices/28-0000068791ac/w1_slave | grep "t=" | awk -F "t=" '{print $2/1000}'
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Aydan
Posts: 729
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: Munin temperature plugin problem

Fri Jan 15, 2016 10:51 am

@Dougie: It would be nice to explain why it doesn't work and how the change fixes it.
People are supposed to learn here and not supidly copy and paste code from the forums.

Regards
Aydan

User avatar
DougieLawson
Posts: 39302
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Munin temperature plugin problem

Fri Jan 15, 2016 4:14 pm

Aydan wrote:@Dougie: It would be nice to explain why it doesn't work and how the change fixes it.
People are supposed to learn here and not supidly copy and paste code from the forums.

Regards
Aydan
Go on then. It's very difficult to tell when we have a short undocumented segment of some random program that the OP has hacked from something he/she has "stupidly" [your words] found on the intertubes.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
karrika
Posts: 1125
Joined: Mon Oct 19, 2015 6:21 am
Location: Finland

Re: Munin temperature plugin problem

Fri Jan 15, 2016 4:39 pm

Your own munin plugin is giving values for multiple values in a go. The standard munin practices is that a plugin outputs just one value. Also only the first sensor is drawn on the graph by default. If you want to draw multiple sensors on the same graph you have to register the plugin as a multigraph plugin. Just copying the values N times will not produce a graph with multiple sensors.

I don't remember by heart how this happens since it has been a while since I was involved with this kind of coding.

munin (controlling sample intervals and creating the graphs) and munin-node (sampling the values) should be in the repositories so just copying your own plugin into /etc/munin/plugins should be enough. Naturally your plugin should return the data types when called with the parameter "config" to work properly.

In munin the plugins are called by regular intervals (every 5 min usually) and the values are stored in rrd files (circular pre-allocated files). The graphs are built separately from the rrd files and not directly from the plugins.

Aydan
Posts: 729
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: Munin temperature plugin problem

Fri Jan 15, 2016 9:21 pm

DougieLawson wrote:
Aydan wrote:@Dougie: It would be nice to explain why it doesn't work and how the change fixes it.
People are supposed to learn here and not supidly copy and paste code from the forums.

Regards
Aydan
Go on then. It's very difficult to tell when we have a short undocumented segment of some random program that the OP has hacked from something he/she has "stupidly" [your words] found on the intertubes.
I suppose you chose to ignore what I actually wrote, so I'll spell it out for you:
You fixed the OP's code segment, please explain how you fixed it.

It doesn't help the OP or anybody else that you know how tho fix it.
This forum is supposed to help people fix things themselves and not for the knowledgeable ones to go: "Oh, I've fixed this for you bit I ain't gonna tell you how and why"
This way of yours to just throw out instructions like this (Do this and it will work), without actually explaining what is going on has been grating on me for a while now.

Regards
Aydan

User avatar
DougieLawson
Posts: 39302
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Munin temperature plugin problem

Fri Jan 15, 2016 10:07 pm

Read the code. I left a couple of hints in there.

I moved the block in the second case statement into the block controlled by the first case statement. I don't know if it will make an iota of difference but it's worth a punt. If I don't have a copy of the whole program (so I can install it on a test bed system) there's not much more I can do. I don't have time to install every screwy software package that turns up in a forum post.

If you don't understand something don't rant and moan (or you'll end up on my forum foes list), ask meaningful questions. I'm not getting paid to help folks on this forum, they have to learn to help themselves.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

GearPower
Posts: 4
Joined: Thu Jan 14, 2016 10:22 pm

Re: Munin temperature plugin problem

Sat Jan 16, 2016 1:21 am

Thanks everybody for your help!

DougieLawson: I tried your code:

Code: Select all

#!/bin/sh

case $1 in
   config)
        cat <<'EOM'
graph_title Temperature probe 1
graph_vlabel temperature_1
exterieur.label exterieur
EOM
        exit 0;;

printf "exterieur.value "
cat /sys/bus/w1/devices/28-00000687a877/w1_slave | grep "t=" | awk -F "t=" '{print $2/1000}'



        cat <<'EOM'

airchaud.label airchaud
EOM
        exit 0;;
esac

printf "airchaud.value "
cat /sys/bus/w1/devices/28-0000068791ac/w1_slave | grep "t=" | awk -F "t=" '{print $2/1000}'
When I try munin-run on this code, the output is:

pi@raspberrypi:/etc/munin/plugins $ sudo munin-run temp3
/etc/munin/plugins/temp3: 12: /etc/munin/plugins/temp3: Syntax error: word unexpected (expecting ")")

Aydan, I understand your point, but I agree with DougieLawson , I grabbed a script on internet instead of learning shell scripting. I'm a windows user, learned basics linux commands when I started with the Pi. I should learn shell. But what's bothering me the most, It's that it was running like a charm before the Raspbian installation.

karrika: I did read on multigraphs and it doesn't seem to be what I'm looking for. As I told before, my script was only copy and paste of a single sensor script.

There's some included scripts with munin, like netstat, and they produce a line for every value. So I suppose my munin setup is able to do multi-value graphs.

Thanks a lot for your help, I'm still searching...

I hope my english is ok, I usually speak french, but I expected to translate to have more views rather than the french forum :)

GearPower

GearPower
Posts: 4
Joined: Thu Jan 14, 2016 10:22 pm

Re: Munin temperature plugin problem

Sat Jan 16, 2016 2:02 am

Ok so I found a working code...

Code: Select all

#!/bin/bash
# Based on a script by a man named Andrew
# Originally located at http://blog.theinternets.be/rpi-munin-temperatures/
# Don't forget to load kernel modules: w1-gpio w1-therm

if [ "$1" == "autoconf" ]; then
     if [ -e /sys/devices/w1_bus_master1/w1_master_slaves ]; then
         echo "yes"
     else
         echo "no"
         exit 1
     fi
elif [ "$1" == "config" ]; thenOk so I found a working code...

[code]#!/bin/bash
# Based on a script by a man named Andrew
# Originally located at http://blog.theinternets.be/rpi-munin-temperatures/
# Don't forget to load kernel modules: w1-gpio w1-therm

if [ "$1" == "autoconf" ]; then
     if [ -e /sys/devices/w1_bus_master1/w1_master_slaves ]; then
         echo "yes"
     else
         echo "no"
         exit 1
     fi
elif [ "$1" == "config" ]; then
     echo "graph_title Raspberry Pi OneWire Temperature"
     echo "graph_vlabel Temperature in Celsius"
     echo "graph_category Sensors"
     I=1;
     for w1_slave in $(cat /sys/devices/w1_bus_master1/w1_master_slaves | sort)
     do
        echo "temp$I.warning 30"
        echo "temp$I.critical 40"
        echo "temp$I.label $w1_slave"
        I=$((I+1));
     done
else
        I=1;
        for w1_slave in $(cat /sys/devices/w1_bus_master1/w1_master_slaves | sort)
        do
          OK=1
          while [ "$OK" -ne 0 ]; do
             file=$(</sys/bus/w1/devices/$w1_slave/w1_slave)
             temp=$(echo $file | sed -e 's/^.*=//' )
             if [[ "$file" =~ "YES" ]] 
             then
                OK=0
             fi 
          done
          awk "BEGIN { printf \"temp$I.value %2.3f\n\", $temp/1000 }"
          I=$(($I+1));

        done
fi
echo "graph_title Raspberry Pi OneWire Temperature"
echo "graph_vlabel Temperature in Celsius"
echo "graph_category Sensors"
I=1;
for w1_slave in $(cat /sys/devices/w1_bus_master1/w1_master_slaves | sort)
do
echo "temp$I.warning 30"
echo "temp$I.critical 40"
echo "temp$I.label $w1_slave"
I=$((I+1));
done
else
I=1;
for w1_slave in $(cat /sys/devices/w1_bus_master1/w1_master_slaves | sort)
do
OK=1
while [ "$OK" -ne 0 ]; do
file=$(</sys/bus/w1/devices/$w1_slave/w1_slave)
temp=$(echo $file | sed -e 's/^.*=//' )
if [[ "$file" =~ "YES" ]]
then
OK=0
fi
done
awk "BEGIN { printf \"temp$I.value %2.3f\n\", $temp/1000 }"
I=$(($I+1));

done
fi
[/code]

The only problem with this code is I only see the hexadecimal number of the sensors, I don't know which is which...

You can see the result live at:
http://gearpower.duckdns.org:82/temp4-day.png

User avatar
DougieLawson
Posts: 39302
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Munin temperature plugin problem

Sat Jan 16, 2016 10:09 am

It's

Code: Select all

     for w1_slave in $(cat /sys/devices/w1_bus_master1/w1_master_slaves | sort)
     do
        echo "temp$I.warning 30"
        echo "temp$I.critical 40"
        echo "temp$I.label $w1_slave"
        I=$((I+1));
     done
that sets up the labels.

So if we add a case statement within that block we can probably label the sensors

Code: Select all

case $w1_slave in

28-0000068791ac*)
  slave_nom="exterieur"
  ;;
28-00000687a877*)
  slave_nom="airchaud"
  ;;
### TODO
### Add similar stuff for the other sensors here
###
*)
  slave_nom="sensor inconnu"
  ;;
esac
Gluing that together It becomes

Code: Select all

     for w1_slave in $(cat /sys/devices/w1_bus_master1/w1_master_slaves | sort)
     do
        case $w1_slave in
        28-0000068791ac*)
          slave_nom="exterieur"
          ;;
        28-00000687a877*)
          slave_nom="airchaud"
          ;;
        *)
          slave_nom="sensor inconnu"
          ;;
        esac
        echo "temp$I.warning 30"
        echo "temp$I.critical 40"
        echo "temp$I.label $slave_nom"
        I=$((I+1));
     done
Give that a go and let us know how it works. I've not tested it for two reasons 1) I don't have a DS18B20 2) I've not installed Munin.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

GearPower
Posts: 4
Joined: Thu Jan 14, 2016 10:22 pm

Re: Munin temperature plugin problem

Sun Jan 17, 2016 5:12 pm

DougieLawson you're a genius! :)
http://gearpower.duckdns.org:82/temp-day.png
It's running like it was before :)

I would buy you a beer if you were nearest than the uk :)

So the final script is:

Code: Select all

# Based on a script by a man named Andrew
# Originally located at http://blog.theinternets.be/rpi-munin-temperatures/
# Don't forget to load kernel modules: w1-gpio w1-therm

if [ "$1" == "autoconf" ]; then
     if [ -e /sys/devices/w1_bus_master1/w1_master_slaves ]; then
         echo "yes"
     else
         echo "no"
         exit 1
     fi
elif [ "$1" == "config" ]; then
     echo "graph_title Temperature dans la maison de Dany et Marie-Helene"
     echo "graph_vlabel Temperature"
     echo "graph_category Sensors"
     I=1;
     for w1_slave in $(cat /sys/devices/w1_bus_master1/w1_master_slaves | sort)
     do


case $w1_slave in
        28-0000068791ac*)
          slave_nom="Exterieur"
          ;;
        28-00000687a6d0*)
          slave_nom="Air Chaud"
          ;;
         28-00000687a877*)
          slave_nom="Cuisine"
          ;;
        28-00000687bf49*)
          slave_nom="Poele"
          ;;
        28-0000068802a2*)
          slave_nom="2e Etage"
          ;;
        28-00000688d80d*)
          slave_nom="Eau Chaude"
          ;;
        28-0000068914a4*)
          slave_nom="Cave"
          ;;
        28-00000689197d*)
          slave_nom="Eau Frode"
          ;;
        28-0000068928f8*)
          slave_nom="Grenier"
          ;;
        28-000006893cab*)
          slave_nom="Cheminee"
          ;;
28-000006df84db*)
          slave_nom="Solage"
          ;;
        28-000006e13993*)
          slave_nom="Piquet"
          ;;

        esac
        echo "temp$I.label $slave_nom"
        I=$((I+1));
     done
else
        I=1;
        for w1_slave in $(cat /sys/devices/w1_bus_master1/w1_master_slaves | sort)
        do
          OK=1
          while [ "$OK" -ne 0 ]; do
             file=$(</sys/bus/w1/devices/$w1_slave/w1_slave)
             temp=$(echo $file | sed -e 's/^.*=//' )
             if [[ "$file" =~ "YES" ]] 
             then
                OK=0
             fi 
          done
          awk "BEGIN { printf \"temp$I.value %2.3f\n\", $temp/1000 }"
          I=$(($I+1));

        done
fi
Thanks a lot for your help!

You could see the final result at:

http://gearpower.duckdns.org:82/temp-day.png

GearPower

Return to “Troubleshooting”