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

    How to: Get CPU temp

    Scheduled Pinned Locked Moved 2.0-RC Snapshot Feedback and Problems - RETIRED
    140 Posts 24 Posters 115.7k 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.
    • stephenw10S
      stephenw10 Netgate Administrator
      last edited by

      Speculating….
      There are two functions. One that draws the table and all the static data and fills in the dynamic data, system_information.widget.php. Another function updates the dynamic data and it's that function that needs updating to include a °.
      ...End speculation.

      Steve

      Edit: Yes. In /usr/local/www/javascript/index/ajax.js
      Add a ° to the updateTemp function like this:

      function updateTemp(x) {
      if($("tempmeter")) {
      $("tempmeter").value = x + '°C';
      $("tempwidtha").style.width = x + 'px';
      $("tempwidthb").style.width = (100 - x) + 'px';
      }

      1 Reply Last reply Reply Quote 0
      • S
        seh2000
        last edited by

        @stephenw10:

        Speculating….
        There are two functions. One that draws the table and all the static data and fills in the dynamic data, system_information.widget.php. Another function updates the dynamic data and it's that function that needs updating to include a °.
        ...End speculation.

        Steve

        Edit: Yes. In /usr/local/www/javascript/index/ajax.js
        Add a ° to the updateTemp function like this:

        function updateTemp(x) {
        if($("tempmeter")) {
        $("tempmeter").value = x + '°C';
        $("tempwidtha").style.width = x + 'px';
        $("tempwidthb").style.width = (100 - x) + 'px';
        }

        YIHUUUUUU!  ;D  :D  :)
        Steve you are the man!
        Works like a dream now.
        Now I will try to work on getting all four cores to be displayed.
        Cheers Steen

        1 Reply Last reply Reply Quote 0
        • CNLiberalC
          CNLiberal
          last edited by

          @stephenw10:

          Speculating….
          There are two functions. One that draws the table and all the static data and fills in the dynamic data, system_information.widget.php. Another function updates the dynamic data and it's that function that needs updating to include a °.
          ...End speculation.

          Steve

          Edit: Yes. In /usr/local/www/javascript/index/ajax.js
          Add a ° to the updateTemp function like this:

          function updateTemp(x) {
          if($("tempmeter")) {
          $("tempmeter").value = x + '°C';
          $("tempwidtha").style.width = x + 'px';
          $("tempwidthb").style.width = (100 - x) + 'px';
          }

          When I make the above change, I get this:

          °C

          That's after the page refreshes.  This is the code I'm putting in:

          
          function updateTemp(x) {
          	if($("tempmeter")) {
          		$("tempmeter").value = x + '°C';
          		$("tempwidtha").style.width = x + 'px';
          		$("tempwidthb").style.width = (100 - x) + 'px';
          	}
          }
          
          

          I tried, instead, adding the #176; or whatever the ASCII code was, and it just showed me the ASCII code.  What did I do wrong?  Thanks!

          Jim

          pfSense 2.7.2-RELEASE

          Dell R210 II
          Intel E3-1340 v2
          8GB RAM
          SSD ZFS Mirror
          Intel X520-DA2, RJ45 SFP+ (WAN) and 10Gb SFP+ DAC (LAN)
          1 x Cisco 3850 12XS-S (Core Switch)
          2 x Cisco 3750X PoE Gig Switch (Access Stack)
          3 x Cisco 2802i APs (Mobility Express)

          1 Reply Last reply Reply Quote 0
          • S
            seh2000
            last edited by

            I just fund the ° symbol in my word processor symbol library then copied it to:

            /usr/local/www/javascript/index/ajax.js

            function updateTemp(x) {
            if($("tempmeter")) {
            $("tempmeter").value = x + '°C';
            $("tempwidtha").style.width = x + 'px';
            $("tempwidthb").style.width = (100 - x) + 'px';

            /usr/local/www/widgets/widgets/system_information.widget.php

            Core 1 Temperature

            ![](./themes/<?= $g[)/images/misc/bar_left.gif" height="15" width="4" border="0" align="middle" alt="left bar" />![](./themes/<?= $g[)/images/misc/bar_blue.gif" height="15" name="tempwidtha" id="tempwidtha" width="" border="0" align="middle" alt="red bar" />![](./themes/<?= $g[)/images/misc/bar_gray.gif" height="15" name="tempwidthb" id="tempwidthb" width="" border="0" align="middle" alt="gray bar" />![](./themes/<?= $g[)/images/misc/bar_right.gif" height="15" width="5" border="0" align="middle" alt="right bar" />

            Used first the ASCI code, but then the symbol, also I seen some places this around " and other ' around - I use ' hope this helps.
            The reason for Core1 instead of CPU is I play with having all four cores displayed.

            Steen

            1 Reply Last reply Reply Quote 0
            • CNLiberalC
              CNLiberal
              last edited by

              Nope, it's still doing the same thing for me.  I guess I'll have to wait until someone develops a system package.  Not a big deal.  I'm just curious why it's not showing a temperature, even though I can query through a sysctl statement and get 4 temperatures (with HyperThreading, two temperatures really).  Thanks all!  I'll still keep an eye on this thread.

              jim

              pfSense 2.7.2-RELEASE

              Dell R210 II
              Intel E3-1340 v2
              8GB RAM
              SSD ZFS Mirror
              Intel X520-DA2, RJ45 SFP+ (WAN) and 10Gb SFP+ DAC (LAN)
              1 x Cisco 3850 12XS-S (Core Switch)
              2 x Cisco 3750X PoE Gig Switch (Access Stack)
              3 x Cisco 2802i APs (Mobility Express)

              1 Reply Last reply Reply Quote 0
              • jimpJ
                jimp Rebel Alliance Developer Netgate
                last edited by

                You should really use °, don't hardcode such a symbol directly in html/js

                Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

                Need help fast? Netgate Global Support!

                Do not Chat/PM for help!

                1 Reply Last reply Reply Quote 0
                • T
                  tix
                  last edited by

                  The Intel 386 coretemp file works for the VIA architecture as well.  I followed the instructions on page 1 of this thread and changed /usr/local/www/includes/functions.inc.php to use "hw.acpi.thermal" instead of "dev.cpu.0.temperature".

                  Works a champ until an update then I need to reinstall the coretemp.ko module and modify functions.inc.php again.

                  My version of /usr/local/www/includes/functions.inc.php

                  
                  function has_temp() {
                  
                  	/* no known temp monitors available at present */
                  
                  	/* should only reach here if there is no hardware monitor */
                  	return true;
                  }
                  
                  function get_temp() {
                  	$temp_out = "";
                  	exec("/sbin/sysctl hw.acpi.thermal | /usr/bin/awk '{ print $2 }' | /usr/bin/cut -d 'C' -f 1", $dfout);
                  	$temp_out = trim($dfout[0]);
                  
                  	return $temp_out;
                  }
                  
                  
                  1 Reply Last reply Reply Quote 0
                  • jimpJ
                    jimp Rebel Alliance Developer Netgate
                    last edited by

                    Put the .ko files in /boot/modules and not /boot/kernel, then they won't go away after every update and they still will load as expected.

                    Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

                    Need help fast? Netgate Global Support!

                    Do not Chat/PM for help!

                    1 Reply Last reply Reply Quote 0
                    • stephenw10S
                      stephenw10 Netgate Administrator
                      last edited by

                      I would think it would be better to have the get_temp function return a value including the ° symbol.
                      E.g. 45.2°
                      That way only one file has to be altered.

                      @jimp:

                      You should really use °, don't hardcode such a symbol directly in html/js

                      I agree. I was surprised it worked actually. It probably depends on what your viewing it on.

                      Steve

                      1 Reply Last reply Reply Quote 0
                      • stephenw10S
                        stephenw10 Netgate Administrator
                        last edited by

                        Using something like:

                        function get_temp() {
                        	$temp_out = "";
                        	exec("/usr/local/bin/mbmon -I -c1 -T3", $dfout);
                        	$temp_out = (trim($dfout[0]).'°');
                        
                        	return $temp_out;
                        }
                        

                        Would be better except that the above code only correctly returns ° when it it called from the system widget php code. When it's called from the javascript update function it just shows °.  :-\

                        Steve

                        1 Reply Last reply Reply Quote 0
                        • jimpJ
                          jimp Rebel Alliance Developer Netgate
                          last edited by

                          Needs a semicolon after that, it's "°"

                          Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

                          Need help fast? Netgate Global Support!

                          Do not Chat/PM for help!

                          1 Reply Last reply Reply Quote 0
                          • S
                            seh2000
                            last edited by

                            @stephenw10:

                            I would think it would be better to have the get_temp function return a value including the ° symbol.
                            E.g. 45.2°
                            That way only one file has to be altered.

                            @jimp:

                            You should really use °, don't hardcode such a symbol directly in html/js

                            I agree. I was surprised it worked actually. I probably depends on what your viewing it on.

                            Steve

                            Steve and jimp,
                            Sorry for been slow, but what you say is I should not really add the ° symbol to the ajax.js file? But could I add the ASCII code there or better not at all? As I mentioned I am not a good programmer :(
                            Steen

                            1 Reply Last reply Reply Quote 0
                            • CNLiberalC
                              CNLiberal
                              last edited by

                              Yeah, this still isn't working for me.  I'm just going to wait until a package is released.

                              pfSense 2.7.2-RELEASE

                              Dell R210 II
                              Intel E3-1340 v2
                              8GB RAM
                              SSD ZFS Mirror
                              Intel X520-DA2, RJ45 SFP+ (WAN) and 10Gb SFP+ DAC (LAN)
                              1 x Cisco 3850 12XS-S (Core Switch)
                              2 x Cisco 3750X PoE Gig Switch (Access Stack)
                              3 x Cisco 2802i APs (Mobility Express)

                              1 Reply Last reply Reply Quote 0
                              • jimpJ
                                jimp Rebel Alliance Developer Netgate
                                last edited by

                                It's bad form (invalid html/js/etc) to put in a symbol instead of the html entity. It may work, but it's not guaranteed to do so.

                                http://www.w3schools.com/tags/ref_entities.asp

                                Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

                                Need help fast? Netgate Global Support!

                                Do not Chat/PM for help!

                                1 Reply Last reply Reply Quote 0
                                • stephenw10S
                                  stephenw10 Netgate Administrator
                                  last edited by

                                  Nope.   ???
                                  Same as before, using:

                                  
                                  unction get_temp() {
                                  	$temp_out = "";
                                  	exec("/usr/local/bin/mbmon -I -c1 -T3", $dfout);
                                  	$temp_out = (trim($dfout[0]).'°');
                                  
                                  	return $temp_out;
                                  }
                                  
                                  

                                  Results in initially correct ° then 46.5°C
                                  Hmm.

                                  Steve

                                  1 Reply Last reply Reply Quote 0
                                  • jimpJ
                                    jimp Rebel Alliance Developer Netgate
                                    last edited by

                                    It may be getting run through htmlentities somewhere in there then. Might be safe to leave the symbol in there if that is the case.

                                    Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

                                    Need help fast? Netgate Global Support!

                                    Do not Chat/PM for help!

                                    1 Reply Last reply Reply Quote 0
                                    • stephenw10S
                                      stephenw10 Netgate Administrator
                                      last edited by

                                      Unfortunately using:

                                      
                                      function get_temp() {
                                      	$temp_out = "";
                                      	exec("/usr/local/bin/mbmon -I -c1 -T3", $dfout);
                                      	$temp_out = (trim($dfout[0]).'°');
                                      
                                      	return $temp_out;
                                      }
                                      
                                      

                                      Results in the attached image.

                                      Perhaps the character set is being restricted somewhere?

                                      tempwidget.jpg
                                      tempwidget.jpg_thumb

                                      1 Reply Last reply Reply Quote 0
                                      • jimpJ
                                        jimp Rebel Alliance Developer Netgate
                                        last edited by

                                        That's a unicode degree symbol, try a standard ascii one, º

                                        Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

                                        Need help fast? Netgate Global Support!

                                        Do not Chat/PM for help!

                                        1 Reply Last reply Reply Quote 0
                                        • S
                                          seh2000
                                          last edited by

                                          @jimp:

                                          It's bad form (invalid html/js/etc) to put in a symbol instead of the html entity. It may work, but it's not guaranteed to do so.

                                          http://www.w3schools.com/tags/ref_entities.asp

                                          OK, got you, yes correct…
                                          Cheers Steen

                                          1 Reply Last reply Reply Quote 0
                                          • stephenw10S
                                            stephenw10 Netgate Administrator
                                            last edited by

                                            No different. I entered both º and ° and both result in ��.  :-\

                                            Steve

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