Subversion Repositories ALCASAR

Rev

Rev 3037 | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
3037 rexy 1
<?php
2
/**
3
 * cpumem sensor class, getting hardware sensors information of CPU and memory
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI_Sensor
9
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
10
 * @author    William Johansson <radar@radhuset.org>
11
 * @copyright 2009 phpSysInfo
12
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
13
 * @version   Release: 3.0
14
 * @link      http://phpsysinfo.sourceforge.net
15
 */
16
class CpuMem extends Hwmon
17
{
18
    /**
19
     * get the information
20
     *
21
     * @see PSI_Interface_Sensor::build()
22
     *
23
     * @return void
24
     */
25
    public function build()
26
    {
27
        if ((PSI_OS == 'Linux') && !defined('PSI_EMU_HOSTNAME')) {
28
            $hwpaths = CommonFunctions::findglob("/sys/devices/platform/coretemp.*/", GLOB_NOSORT);
29
            if (is_array($hwpaths) && (count($hwpaths) > 0)) {
30
                $hwpaths2 = CommonFunctions::findglob("/sys/devices/platform/coretemp.*/hwmon/hwmon*/", GLOB_NOSORT);
31
                if (is_array($hwpaths2) && (count($hwpaths2) > 0)) {
32
                    $hwpaths = array_merge($hwpaths, $hwpaths2);
33
                }
34
                $totalh = count($hwpaths);
35
                for ($h = 0; $h < $totalh; $h++) {
36
                    $this->_temperature($hwpaths[$h]);
37
                }
38
            }
39
        } elseif (PSI_OS == 'FreeBSD') {
40
            $smp = 1;
41
            CommonFunctions::executeProgram('sysctl', '-n kern.smp.cpus', $smp);
42
            for ($i = 0; $i < $smp; $i++) {
43
                $temp = 0;
44
                if (CommonFunctions::executeProgram('sysctl', '-n dev.cpu.'.$i.'.temperature', $temp)) {
45
                    $temp = preg_replace('/,/', '.', preg_replace('/C/', '', $temp));
46
                    $dev = new SensorDevice();
47
                    $dev->setName("CPU ".($i + 1));
48
                    $dev->setValue($temp);
49
//                    $dev->setMax(70);
50
                    $this->mbinfo->setMbTemp($dev);
51
                }
52
            }
53
        } elseif ((PSI_OS == 'WINNT') || defined('PSI_EMU_HOSTNAME')) {
54
            $allCpus = WINNT::_get_Win32_Processor();
55
            foreach ($allCpus as $oneCpu) if (isset($oneCpu['CurrentVoltage']) && ($oneCpu['CurrentVoltage'] > 0)) {
56
                $dev = new SensorDevice();
57
                $dev->setName($oneCpu['DeviceID']);
58
                $dev->setValue($oneCpu['CurrentVoltage']/10);
59
                $this->mbinfo->setMbVolt($dev);
60
            }
61
            $allMems = WINNT::_get_Win32_PhysicalMemory();
62
            $counter = 0;
63
            foreach ($allMems as $oneMem) if (isset($oneMem['ConfiguredVoltage']) && ($oneMem['ConfiguredVoltage'] > 0)) {
64
                $dev = new SensorDevice();
65
                $dev->setName('Mem'.($counter++));
66
                $dev->setValue($oneMem['ConfiguredVoltage']/1000);
67
                if (isset($oneMem['MaxVoltage']) && ($oneMem['MaxVoltage'] > 0)) {
68
                    $dev->setMax($oneMem['MaxVoltage']/1000);
69
                }
70
                if (isset($oneMem['MinVoltage']) && ($oneMem['MinVoltage'] > 0)) {
71
                    $dev->setMin($oneMem['MinVoltage']/1000);
72
                }
73
                $this->mbinfo->setMbVolt($dev);
74
            }
75
        }
3100 rexy 76
        if ((PSI_OS != 'WINNT') && (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT'))) {
3037 rexy 77
            $dmimd = CommonFunctions::readdmimemdata();
78
            $counter = 0;
79
            foreach ($dmimd as $mem) {
80
                if (isset($mem['Size']) && preg_match('/^(\d+)\s(M|G)B$/', $mem['Size'], $size) && ($size[1] > 0)
81
                    && isset($mem['Configured Voltage']) && preg_match('/^([\d\.]+)\sV$/', $mem['Configured Voltage'], $voltage) && ($voltage[1] > 0)) {
82
                    $dev = new SensorDevice();
83
                    $dev->setName('Mem'.($counter++));
84
                    $dev->setValue($voltage[1]);
85
                    if (isset($mem['Minimum Voltage']) && preg_match('/^([\d\.]+)\sV$/', $mem['Minimum Voltage'], $minv) && ($minv[1]  > 0)) {
86
                        $dev->setMin($minv[1]);
87
                    }
88
                    if (isset($mem['Maximum Voltage']) && preg_match('/^([\d\.]+)\sV$/', $mem['Maximum Voltage'], $maxv) && ($maxv[1]  > 0)) {
89
                        $dev->setMax($maxv[1]);
90
                    }
91
                    $this->mbinfo->setMbVolt($dev);
92
                }
93
            }
94
        }
95
    }
96
}