cacti template to monitor raspberry pi temperature

After very long time I had some time to do smth with my raspberry pi.

I always wanted to have small server in home to monitor all of my network devices in home. Raspberry pi is almost ideal for it. However I cannot run Zabbix on it, because Zabbix is not adopted to such small devices. So I decided to use cacti. After digging google I spotted this link:
Cacti Pi

There is nice tutorial how to intall and optimize cacti to run on raspberry pi. I followed it and after about 15 minutes I had full setup of cacti.
However I wanted to monitor my raspberry pi’s temperature. It can be done from CLI:

/opt/vc/bin/vcgencmd measure_temp

So I’ve writed small script:

#!/usr/bin/perl
 
open(PROCESS, "/opt/vc/bin/vcgencmd measure_temp |");
$avg = <PROCESS>;
close(PROCESS);
 
$avg =~ s/^.*=(\d{2}\.\d)'?C?$//;
 
print "$1";

Here is some edit:

#!/usr/bin/perl
delete @ENV{qw(PATH)};
$ENV{PATH} = "/usr/bin:/bin";
$path = $ENV{'PATH'};
 
open(PROCESS, "/opt/vc/bin/vcgencmd measure_temp |");
$avg = <PROCESS>;
close(PROCESS);
 
$avg =~ s/^.*=(\d{2}\.\d)'?C?$//;
 
print "$1";

And put it to:

/var/www/cacti/scripts/temp_rpi.pl

Of course You need to:

chown pi:users /var/www/cacti/scripts/temp_rpi.pl

After that create new data input method in cacti:

Data input methods

Then added cacti templates and data sources (files to import to cacti 0.8.8a are attached to this post), but graphs didn’t show. After digging google, I’ve found the problem: www-data user must be added to video and plugdev group.

After that You will have nice graphs of temperature on your raspberry pi:
Raspberry pi temperature graph

And that’s all.

Files to import in cacti:
Cacti data template
Cacti graph template

Posted in Uncategorized Tagged with: , ,
11 comments on “cacti template to monitor raspberry pi temperature
  1. n00badmin says:

    Amazing job sq4ind!

    Thanks for the link!

    I will be throwing this into my Cacti Pi install ASAP!

  2. tonu says:

    Hi, I’m a little bit in trouble…

    Using Your script gives me “WARNING: Result from CMD not valid. Partial Result: U” in cacti log. I guess, the problem is in the Perl script… I was trying a few different options and found that: when I edit the last line of the script and write it like ” print “49.5”; ” then cacti receives data OK but when using ” print $1 ” or the orig. scripts ” print “$1″ ” I’ll get the above error message.

    Can You point me where the problem is? Thanks in advance!

  3. tonu says:

    Solved… the answer is in Your text. Thanks.

  4. Gianl says:

    I have the same problem
    “WARNING: Result from CMD not valid. Partial Result: U” in cacti log.

    Can You point me where the problem is? Thanks in advance!

  5. David says:

    Thanks for the integration! This extends the usefulness of the RPi as a metrics box.

  6. Steve says:

    Thanks for that.

    Very useful.

    Just tried out Cacti, and adding the TEMP to the Graphs was useful.

  7. 1s2 says:

    Hi,

    if you have ever thought about accessing the temperature or other locale environment data of a Raspi remotely via snmp you may want to have a look to this article:
    http://www.onestep2.at/en/blog/remote-sensor-raspberry-pi-locale-temperature-monitoring-snmp-and-cacti

    Bye

  8. r.hundstorf says:

    Great step by step instructions!!
    till
    “Then added cacti templates and data sources (files to import to cacti 0.8.8a are attached to this post), but graphs didn’t show. After digging google, I’ve found the problem: www-data user must be added to video and plugdev group.”

    wtf? can you please specify what to do?!

    how to import, how to www-data add to video and plugdev?

    • sq4ind says:

      You should use this one:
      usermod -g video www-data
      usermod -g plugdev www-data

      After that everything should work.

  9. Monno says:

    Great work
    Just added to my PI, and works great
    Thanks

Leave a Reply

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

*