Subversion Repositories ALCASAR

Rev

Rev 2770 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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