Subversion Repositories ALCASAR

Rev

Go to most recent revision | 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
    {
28
        if (PSI_OS == 'Linux') {
29
            $hwpaths = glob("/sys/devices/platform/coretemp.*/", GLOB_NOSORT);
30
            if (is_array($hwpaths) && (count($hwpaths) > 0)) {
31
                $hwpaths = array_merge($hwpaths, glob("/sys/devices/platform/coretemp.*/hwmon/hwmon*/", GLOB_NOSORT));
32
            }
33
            if (is_array($hwpaths) && (($totalh = count($hwpaths)) > 0)) {
34
                for ($h = 0; $h < $totalh; $h++) {
35
                    $this->_temperature($hwpaths[$h]);
36
                }
37
            }
38
        } else {
39
            $smp = 1;
40
            CommonFunctions::executeProgram('sysctl', '-n kern.smp.cpus', $smp);
41
            for ($i = 0; $i < $smp; $i++) {
42
                $temp = 0;
43
                if (CommonFunctions::executeProgram('sysctl', '-n dev.cpu.'.$i.'.temperature', $temp)) {
44
                    $temp = preg_replace('/,/', '.', preg_replace('/C/', '', $temp));
45
                    $dev = new SensorDevice();
46
                    $dev->setName("CPU ".($i + 1));
47
                    $dev->setValue($temp);
48
//                    $dev->setMax(70);
49
                    $this->mbinfo->setMbTemp($dev);
50
                }
51
            }
52
        }
53
    }
54
}