Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
2770 rexy 1
<?php
2
/**
3
 * coretemp sensor class, getting hardware temperature information through sysctl on FreeBSD
4
 * or from /sys/devices/platform/coretemp. on Linux
5
 *
6
 * PHP version 5
7
 *
8
 * @category  PHP
9
 * @package   PSI_Sensor
10
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
11
 * @author    William Johansson <radar@radhuset.org>
12
 * @copyright 2009 phpSysInfo
13
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
14
 * @version   Release: 3.0
15
 * @link      http://phpsysinfo.sourceforge.net
16
 */
17
class Coretemp extends Hwmon
18
{
19
    /**
20
     * get the information
21
     *
22
     * @see PSI_Interface_Sensor::build()
23
     *
24
     * @return Void
25
     */
26
    public function build()
27
    {
2976 rexy 28
        if ((PSI_OS == 'Linux') && !defined('PSI_EMU_HOSTNAME')) {
2770 rexy 29
            $hwpaths = glob("/sys/devices/platform/coretemp.*/", GLOB_NOSORT);
30
            if (is_array($hwpaths) && (count($hwpaths) > 0)) {
2976 rexy 31
                $hwpaths2 = glob("/sys/devices/platform/coretemp.*/hwmon/hwmon*/", GLOB_NOSORT);
32
                if (is_array($hwpaths2) && (count($hwpaths2) > 0)) {
33
                    $hwpaths = array_merge($hwpaths, $hwpaths2);
34
                }
35
                $totalh = count($hwpaths);
2770 rexy 36
                for ($h = 0; $h < $totalh; $h++) {
37
                    $this->_temperature($hwpaths[$h]);
38
                }
39
            }
2976 rexy 40
        } elseif (PSI_OS == 'FreeBSD') {
2770 rexy 41
            $smp = 1;
42
            CommonFunctions::executeProgram('sysctl', '-n kern.smp.cpus', $smp);
43
            for ($i = 0; $i < $smp; $i++) {
44
                $temp = 0;
45
                if (CommonFunctions::executeProgram('sysctl', '-n dev.cpu.'.$i.'.temperature', $temp)) {
46
                    $temp = preg_replace('/,/', '.', preg_replace('/C/', '', $temp));
47
                    $dev = new SensorDevice();
48
                    $dev->setName("CPU ".($i + 1));
49
                    $dev->setValue($temp);
50
//                    $dev->setMax(70);
51
                    $this->mbinfo->setMbTemp($dev);
52
                }
53
            }
54
        }
55
    }
56
}