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