Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Working RRD Graphs of coretemp CPU values

    Scheduled Pinned Locked Moved Hardware
    2 Posts 2 Posters 5.9k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      coltect
      last edited by

      Warning !!
      I have fiddled with pfsense for a week. I know basically nothing about FreeBSD, apart from what I have learnt this week, and a FreeNAS install about a year ago.
      These forums have been very helpful with setting up my box. I greatly appreciate the time people spend writing up stuff to help people like me.

      I don't know php, but I can read and google. There are awk commands here that I have no idea how they work.
      I copy and paste in small increments, make little shell scripts to test and backup backup backup.
      At one stage I stuffed up the rrd.inc file, a " without a " and had to use vi to fix it from the console, also had some whitespaces on the end of a line. No networking nothing.

      Be careful following the blind.

      However I do get CPU core temps on an RRD graph now under the System category. The wrong values, but they are what coretemp reports via dev.cpu.x.tempertaure

      1. Install coretemp as per forum http://forum.pfsense.org/index.php/topic,39595.0.html - Thanks. mbmon didn't work for me either.
      2. Modify /etc/inc/rrd.inc so that rrdupdate.sh gets modified to include the data from coretemp.
      3. Modify /usr/local/www/status_rrd_graph_img.php

      Done

      I used WinSCP to edit the files, use whatever you find easiest/safest.
      I copied them to my windows box, then edited them then copied them back. Leaving the original file with a new name. If things went bad, I just had to copy the original file back and reboot from the console.
      I added the info for the CPU temps after the Memory code, as it seemed the closest to what I wanted to do. i.e. it was also using sysctl to gather data.

      1. Follow http://forum.pfsense.org/index.php/topic,39595.0.html
      make sure you get something useful from

      sysctl -n dev.cpu.0.temperature

      Also try sysctl dev.cpu

      This showed me initially that I didn't have powerd running, so the CPU was always running at 1.66, instead of slowing down when idle.

      2. Make a backup of /etc/inc/rrd.inc
        copy /etc/inc/rrd.inc to your windows box using WinSCP
        edit /etc/inc/rrd.inc with something like Notepad++, not windows Notepad.

      Add a line after 175
      Line 175: $mem = "-memory.rrd";
      Line 176: $cputemp = "-temperature.rrd";
      Line 177: $cellular = "-cellular.rrd";

      Add a line after 204
      Line 204: $rrdmeminterval = 60;
      Line 205: $rrdcputempinterval = 60;
      Line 206: $rrdcellularinterval = 60;

      Add a line after 219
      Line 219: $memvalid = $rrdmeminterval * 2;
      Line 220: $cputempvalid = $rrdcputempinterval * 2;
      Line 221: $cellularvalid = $rrdcellularinterval * 2;

      Add this after line 615

      Line 615: /* End Memory statistics */

      /* CPU Temperature /
      /
      the CPU Temperature gathering Function. /
      /
      This is for an ATOM D510 and coretemp which reports 4 cores with very low figures /
      /
      It seems that adding the 4 core temps , then halving is very close to the BIOS temp reading, but not the same /
      /
      Added 33 to all readings as this seems to be the offset maybe.. /
      /
      Values now get to -1 raw , then show as 32C constant and never go lower /
      /
      Need more fiddling with values yet, but graphs work - bad data though */

      /* Cpu Temp, create CPU Temperature database */
      if(! file_exists("$rrddbpath$ifname$cputemp")) {
      $rrdcreate = "$rrdtool create $rrddbpath$ifname$cputemp –step $rrdcputempinterval ";
      $rrdcreate .= "DS:cpu0temp:GAUGE:$cputempvalid:-273:5000 ";
      $rrdcreate .= "DS:cpu1temp:GAUGE:$cputempvalid:-273:5000 ";
      $rrdcreate .= "DS:cpu2temp:GAUGE:$cputempvalid:-273:5000 ";
      $rrdcreate .= "DS:cpu3temp:GAUGE:$cputempvalid:-273:5000 ";
      $rrdcreate .= "RRA:MIN:0.5:1:1000 ";
      $rrdcreate .= "RRA:MIN:0.5:5:1000 ";
      $rrdcreate .= "RRA:MIN:0.5:60:1000 ";
      $rrdcreate .= "RRA:MIN:0.5:720:3000 ";
      $rrdcreate .= "RRA:AVERAGE:0.5:1:1000 ";
      $rrdcreate .= "RRA:AVERAGE:0.5:5:1000 ";
      $rrdcreate .= "RRA:AVERAGE:0.5:60:1000 ";
      $rrdcreate .= "RRA:AVERAGE:0.5:720:3000 ";
      $rrdcreate .= "RRA:MAX:0.5:1:1000 ";
      $rrdcreate .= "RRA:MAX:0.5:5:1000 ";
      $rrdcreate .= "RRA:MAX:0.5:60:1000 ";
      $rrdcreate .= "RRA:MAX:0.5:720:3000 ";
      $rrdcreate .= "RRA:LAST:0.5:1:1000 ";
      $rrdcreate .= "RRA:LAST:0.5:5:1000 ";
      $rrdcreate .= "RRA:LAST:0.5:60:1000 ";
      $rrdcreate .= "RRA:LAST:0.5:720:3000 ";

      create_new_rrd($rrdcreate);
      }

      /* enter UNKNOWN values in the RRD so it knows we rebooted. */
      if($g['booting']) {
      mwexec("$rrdtool update $rrddbpath$ifname$cputemp N:U:U:U:U:U");
      }

      /* the CPU Temperature gathering function */
      $rrdupdatesh .= "CPUTEMP=$sysctl -n dev.cpu.0.temperature dev.cpu.1.temperature dev.cpu.2.temperature dev.cpu.3.temperature | "; $rrdupdatesh .= " $awk '{getline cpu0temp;getline cpu1temp;getline cpu2temp;getline cpu3temp;printf "; $rrdupdatesh .= "((((cpu0temp*100)/100)+33)\":\"(((cpu1temp*100)/100)+33)\":\"(((cpu2temp*100)/100)+33)\":\"(((cpu3temp*100)/100)+33))}'\n";
      $rrdupdatesh .= "$rrdtool update $rrddbpath$ifname$cputemp N:${CPUTEMP}\n";

      /* end CPU Temp gathering */

      Save the file

      This will log data from dev.cpu.x.temperature every minute into system-temperature.rrd
        (my first play with RRD. I have no idea what is not right in here but it works)

      3. Make a backup of /usr/local/www/status_rrd_graph_img.php 
        Copy /usr/local/www/status_rrd_graph_img.php to your Windows box, edit it with Notepad++
        Add a section in here after the -memory data finishes on line 770

      Line 769: $graphcmd .= "COMMENT:"\t\t\t\t\t\t\t\t\t\t\t\t\tdate +\"%b %d %H\:%M\:%S %Y\"" ";
      Line 770: }

      elseif((strstr($curdatabase, "-temperature.rrd")) && (file_exists("$rrddbpath$curdatabase"))) {
      /* define graphcmd for memory usage stats */
      $graphcmd = "$rrdtool graph $rrdtmppath$curdatabase-$curgraph.png ";
      $graphcmd .= "–start $start --end $end ";
      $graphcmd .= "--vertical-label "degrees, celcius" ";
      $graphcmd .= "--color SHADEA#eeeeee --color SHADEB#eeeeee ";
      $graphcmd .= "--title "hostname - {$prettydb} - {$hperiod} - {$havg} LAST" ";
      $graphcmd .= "--height 200 --width 620 ";
      $graphcmd .= "DEF:"cpu0temp=$rrddbpath$curdatabase:cpu0temp:LAST" ";
      $graphcmd .= "DEF:"cpu1temp=$rrddbpath$curdatabase:cpu1temp:LAST" ";
      $graphcmd .= "DEF:"cpu2temp=$rrddbpath$curdatabase:cpu2temp:LAST" ";
      $graphcmd .= "DEF:"cpu3temp=$rrddbpath$curdatabase:cpu3temp:LAST" ";
      $graphcmd .= "LINE2:"cpu0temp#{$colormemory[0]}:cpu0temp" ";
      $graphcmd .= "LINE2:"cpu1temp#{$colormemory[1]}:cpu1temp" ";
      $graphcmd .= "LINE2:"cpu2temp#{$colormemory[2]}:cpu2temp" ";
      $graphcmd .= "LINE2:"cpu3temp#{$colormemory[3]}:cpu3temp" ";
      $graphcmd .= "COMMENT:"\n" ";
      $graphcmd .= "COMMENT:"\t\t      minimum        average        maximum        current\n" ";
      $graphcmd .= "COMMENT:"Cpu0temp.      " ";
      $graphcmd .= "GPRINT:"cpu0temp:MIN:%7.2lf %s    " ";
      $graphcmd .= "GPRINT:"cpu0temp:AVERAGE:%7.2lf %s    " ";
      $graphcmd .= "GPRINT:"cpu0temp:MAX:%7.2lf %s    " ";
      $graphcmd .= "GPRINT:"cpu0temp:LAST:%7.2lf %S    " ";
      $graphcmd .= "COMMENT:"\n" ";
      $graphcmd .= "COMMENT:"Cpu1temp.    " ";
      $graphcmd .= "GPRINT:"cpu1temp:MIN:%7.2lf %s    " ";
      $graphcmd .= "GPRINT:"cpu1temp:AVERAGE:%7.2lf %s    " ";
      $graphcmd .= "GPRINT:"cpu1temp:MAX:%7.2lf %s    " ";
      $graphcmd .= "GPRINT:"cpu1temp:LAST:%7.2lf %S    " ";
      $graphcmd .= "COMMENT:"\n" ";
      $graphcmd .= "COMMENT:"Cpu2temp.        " ";
      $graphcmd .= "GPRINT:"cpu2temp:MIN:%7.2lf %s    " ";
      $graphcmd .= "GPRINT:"cpu2temp:AVERAGE:%7.2lf %s    " ";
      $graphcmd .= "GPRINT:"cpu2temp:MAX:%7.2lf %s    " ";
      $graphcmd .= "GPRINT:"cpu2temp:LAST:%7.2lf %S    " ";
      $graphcmd .= "COMMENT:"\n" ";
      $graphcmd .= "COMMENT:"Cpu3temp.      " ";
      $graphcmd .= "GPRINT:"cpu3temp:MIN:%7.2lf %s    " ";
      $graphcmd .= "GPRINT:"cpu3temp:AVERAGE:%7.2lf %s    " ";
      $graphcmd .= "GPRINT:"cpu3temp:MAX:%7.2lf %s    " ";
      $graphcmd .= "GPRINT:"cpu3temp:LAST:%7.2lf %S    " ";
      $graphcmd .= "COMMENT:"\n" ";
      $graphcmd .= "COMMENT:"\t\t\t\t\t\t\t\t\t\t\t\t\tdate +\"%b %d %H\:%M\:%S %Y\"" ";
      }

      Save the file.

      Done, nearly.

      Check everything again. Look for any whitespaces, or blank spaces at the end of lines. This got me once. I'm not sure if it matters about TAB's or SPACE's at the start of lines. I don't think so.
      Copy these modified files back to the pfsense box with WinSCP.
      Open a terminal in Putty, or go to the console.
      Use option 11 to Restart the WebConfigurator and the changes will be made. Cross your fingers and hope that if you copied and pasted this stuff, I didn't screw it up pasting into the forum.

      The Graphs need someone to clean up the alignment of figures, possibly someone who actually knows what they are doing, but they will do for what I need right now.

      I'd really like to get accurate values from coretemp. It looks like coretemp in the windows world is updated, but I have been unable to find a newer coretemp.ko for 32bit FreeBSD 8.1.

      Cheers, Col.

      1 Reply Last reply Reply Quote 0
      • V
        Volui
        last edited by

        Hi, it's work fine, but how remove +33C gauge?

        Upd. Solved (I just removed +33)  :)

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.