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 = ;
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 = ;
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

16 Comments on “cacti template to monitor raspberry pi temperature

  1. 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!

  2. 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!

  3. 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?

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

      After that everything should work.

      • You should use this one:
        usermod -a -G video www-data
        usermod -a -G plugdev www-data

        because “-g” meaing change the primary group of a user and that means, that you rewrite video group with plugdev and script without that doesn’t work.

  4. Really nice tutorial but i’am a little bit in trouble. Ich hope you can help me.

    this is my script:

    #!/usr/bin/perl

    use warnings;
    use strict;

    delete @ENV{qw(PATH)};
    $ENV{PATH} = “/usr/bin:/bin”;
    my $path = $ENV{‘PATH’};

    open(PROCESS, “/opt/vc/bin/vcgencmd measure_temp |”);
    my $avg = ;
    close(PROCESS);

    $avg =~ s/^.*=(\d{2}\.\d)’?C?$//;

    print “$1”;

    when i execute it in terminal:

    perl -w temp_rpi.pl
    37.9

    but graphs didn’t show and i try it with

    usermod -g video www-data
    usermod -g plugdev www-data

    sudo tail -f poller-error.log

    Use of uninitialized value $1 in string at /usr/share/cacti/site/scripts/temp_rpi.pl line 16.
    Use of uninitialized value $1 in string at /usr/share/cacti/site/scripts/temp_rpi.pl line 16.
    Use of uninitialized value $1 in string at /usr/share/cacti/site/scripts/temp_rpi.pl line 16.
    Use of uninitialized value $1 in string at /usr/share/cacti/site/scripts/temp_rpi.pl line 16.
    Use of uninitialized value $1 in string at /usr/share/cacti/site/scripts/temp_rpi.pl line 16.

    I hope you can help me.

    thx

  5. Hello,
    I’ve installed Cacti Version 0.8.8b.
    I can’t get the temperature displayed, the temperature graph is there though.
    I have this error in my cacti log:
    CMDPHP: Poller[0] Host[1] DS[8] WARNING: Result from CMD not valid. Partial Result: U
    I copy/pasted your script:

    #!/usr/bin/perl
    delete @ENV{qw(PATH)};
    $ENV{PATH} = “/usr/bin:/bin”;
    $path = $ENV{‘PATH’};

    open(PROCESS, “/opt/vc/bin/vcgencmd measure_temp |”);
    $avg = ;
    close(PROCESS);

    $avg =~ s/^.*=(\d{2}\.\d)’?C?$//;

    print “$1”;

    When I execute it, it returns the temperature:

    sudo perl temp_rpi.pl
    42.2

    If, like tonu said earlier, I change
    print “$1”;
    to
    print “40”;

    The temperature graph is working.

    What’s wrong???

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.