1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* hwmon sensor class |
4
|
|
|
* |
5
|
|
|
* PHP version 5 |
6
|
|
|
* |
7
|
|
|
* @category PHP |
8
|
|
|
* @package PSI_Sensor |
9
|
|
|
* @author Michael Cramer <[email protected]> |
10
|
|
|
* @copyright 2009 phpSysInfo |
11
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
12
|
|
|
* @version SVN: $Id: class.hwmon.inc.php 661 2012-08-27 11:26:39Z namiltd $ |
13
|
|
|
* @link http://phpsysinfo.sourceforge.net |
14
|
|
|
*/ |
15
|
|
|
/** |
16
|
|
|
* getting hardware temperature information through sysctl |
17
|
|
|
* |
18
|
|
|
* @category PHP |
19
|
|
|
* @package PSI_Sensor |
20
|
|
|
* @author Michael Cramer <[email protected]> |
21
|
|
|
* @author William Johansson <[email protected]> |
22
|
|
|
* @copyright 2009 phpSysInfo |
23
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
24
|
|
|
* @version Release: 3.0 |
25
|
|
|
* @link http://phpsysinfo.sourceforge.net |
26
|
|
|
*/ |
27
|
|
|
class Hwmon extends Sensors |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* get temperature information |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
View Code Duplication |
private function _temperature($hwpath) |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
$sensor = glob($hwpath."temp*_input", GLOB_NOSORT); |
37
|
|
|
if (($total = count($sensor)) > 0) { |
38
|
|
|
$buf = ""; |
39
|
|
|
for ($i = 0; $i < $total; $i++) if (CommonFunctions::rfts($sensor[$i], $buf, 1, 4096, false) && (trim($buf) != "")) { |
40
|
|
|
$dev = new SensorDevice(); |
41
|
|
|
$dev->setValue(trim($buf)/1000); |
42
|
|
|
$label = preg_replace("/_input$/", "_label", $sensor[$i]); |
43
|
|
|
$crit = preg_replace("/_input$/", "_crit", $sensor[$i]); |
44
|
|
|
$max = preg_replace("/_input$/", "_max", $sensor[$i]); |
45
|
|
|
$crit_alarm = preg_replace("/_input$/", "_crit_alarm", $sensor[$i]); |
46
|
|
|
if (CommonFunctions::fileexists($label) && CommonFunctions::rfts($label, $buf, 1, 4096, false) && (trim($buf) != "")) { |
47
|
|
|
$dev->setName(trim($buf)); |
48
|
|
|
} else { |
49
|
|
|
$labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME))); |
50
|
|
|
if ($labelname !== "") { |
51
|
|
|
$dev->setName($labelname); |
52
|
|
|
} else { |
53
|
|
|
$dev->setName('unknown'); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
if (CommonFunctions::fileexists($crit) && CommonFunctions::rfts($crit, $buf, 1, 4096, false) && (trim($buf) != "")) { |
57
|
|
|
$dev->setMax(trim($buf)/1000); |
58
|
|
|
if (CommonFunctions::fileexists($crit_alarm) && CommonFunctions::rfts($crit_alarm, $buf, 1, 4096, false) && (trim($buf) === "1")) { |
59
|
|
|
$dev->setEvent("Critical Alarm"); |
60
|
|
|
} |
61
|
|
|
} elseif (CommonFunctions::fileexists($max) && CommonFunctions::rfts($max, $buf, 1, 4096, false) && (trim($buf) != "")) { |
62
|
|
|
$dev->setMax(trim($buf)/1000); |
63
|
|
|
} |
64
|
|
|
$this->mbinfo->setMbTemp($dev); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* get voltage information |
71
|
|
|
* |
72
|
|
|
* @return void |
73
|
|
|
*/ |
74
|
|
View Code Duplication |
private function _voltage($hwpath) |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
$sensor = glob($hwpath."in*_input", GLOB_NOSORT); |
77
|
|
|
if (($total = count($sensor)) > 0) { |
78
|
|
|
$buf = ""; |
79
|
|
|
for ($i = 0; $i < $total; $i++) if (CommonFunctions::rfts($sensor[$i], $buf, 1, 4096, false) && (trim($buf) != "")) { |
80
|
|
|
$dev = new SensorDevice(); |
81
|
|
|
$dev->setValue(trim($buf)/1000); |
82
|
|
|
$label = preg_replace("/_input$/", "_label", $sensor[$i]); |
83
|
|
|
$alarm = preg_replace("/_input$/", "_alarm", $sensor[$i]); |
84
|
|
|
$max = preg_replace("/_input$/", "_max", $sensor[$i]); |
85
|
|
|
$min = preg_replace("/_input$/", "_min", $sensor[$i]); |
86
|
|
|
if (CommonFunctions::fileexists($label) && CommonFunctions::rfts($label, $buf, 1, 4096, false) && (trim($buf) != "")) { |
87
|
|
|
$dev->setName(trim($buf)); |
88
|
|
|
} else { |
89
|
|
|
$labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME))); |
90
|
|
|
if ($labelname !== "") { |
91
|
|
|
$dev->setName($labelname); |
92
|
|
|
} else { |
93
|
|
|
$dev->setName('unknown'); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
if (CommonFunctions::fileexists($max) && CommonFunctions::rfts($max, $buf, 1, 4096, false) && (trim($buf) != "")) { |
97
|
|
|
$dev->setMax(trim($buf)/1000); |
98
|
|
|
} |
99
|
|
|
if (CommonFunctions::fileexists($min) && CommonFunctions::rfts($min, $buf, 1, 4096, false) && (trim($buf) != "")) { |
100
|
|
|
$dev->setMin(trim($buf)/1000); |
101
|
|
|
} |
102
|
|
|
if (CommonFunctions::fileexists($alarm) && CommonFunctions::rfts($alarm, $buf, 1, 4096, false) && (trim($buf) === "1")) { |
103
|
|
|
$dev->setEvent("Alarm"); |
104
|
|
|
} |
105
|
|
|
$this->mbinfo->setMbVolt($dev); |
|
|
|
|
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* get fan information |
112
|
|
|
* |
113
|
|
|
* @return void |
114
|
|
|
*/ |
115
|
|
|
private function _fans($hwpath) |
116
|
|
|
{ |
117
|
|
|
$sensor = glob($hwpath."fan*_input", GLOB_NOSORT); |
118
|
|
|
if (($total = count($sensor)) > 0) { |
119
|
|
|
$buf = ""; |
120
|
|
|
for ($i = 0; $i < $total; $i++) if (CommonFunctions::rfts($sensor[$i], $buf, 1, 4096, false) && (trim($buf) != "")) { |
121
|
|
|
$dev = new SensorDevice(); |
122
|
|
|
$dev->setValue(trim($buf)); |
123
|
|
|
$label = preg_replace("/_input$/", "_label", $sensor[$i]); |
124
|
|
|
$alarm = preg_replace("/_input$/", "_alarm", $sensor[$i]); |
125
|
|
|
$fullmax = preg_replace("/_input$/", "_full_speed", $sensor[$i]); |
126
|
|
|
$max = preg_replace("/_input$/", "_max", $sensor[$i]); |
127
|
|
|
$min = preg_replace("/_input$/", "_min", $sensor[$i]); |
128
|
|
|
if (CommonFunctions::fileexists($label) && CommonFunctions::rfts($label, $buf, 1, 4096, false) && (trim($buf) != "")) { |
129
|
|
|
$dev->setName(trim($buf)); |
130
|
|
|
} else { |
131
|
|
|
$labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME))); |
132
|
|
|
if ($labelname !== "") { |
133
|
|
|
$dev->setName($labelname); |
134
|
|
|
} else { |
135
|
|
|
$dev->setName('unknown'); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
if (CommonFunctions::fileexists($fullmax) && CommonFunctions::rfts($fullmax, $buf, 1, 4096, false) && (trim($buf) != "")) { |
139
|
|
|
$dev->setMax(trim($buf)); |
140
|
|
|
} elseif (CommonFunctions::fileexists($max) && CommonFunctions::rfts($max, $buf, 1, 4096, false) && (trim($buf) != "")) { |
141
|
|
|
$dev->setMax(trim($buf)); |
142
|
|
|
} |
143
|
|
|
if (CommonFunctions::fileexists($min) && CommonFunctions::rfts($min, $buf, 1, 4096, false) && (trim($buf) != "")) { |
144
|
|
|
$dev->setMin(trim($buf)); |
145
|
|
|
} |
146
|
|
|
if (CommonFunctions::fileexists($alarm) && CommonFunctions::rfts($alarm, $buf, 1, 4096, false) && (trim($buf) === "1")) { |
147
|
|
|
$dev->setEvent("Alarm"); |
148
|
|
|
} |
149
|
|
|
$this->mbinfo->setMbFan($dev); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* get power information |
156
|
|
|
* |
157
|
|
|
* @return void |
158
|
|
|
*/ |
159
|
|
|
private function _power($hwpath) |
160
|
|
|
{ |
161
|
|
|
$sensor = glob($hwpath."power*_input", GLOB_NOSORT); |
162
|
|
|
if (($total = count($sensor)) > 0) { |
163
|
|
|
$buf = ""; |
164
|
|
|
for ($i = 0; $i < $total; $i++) if (CommonFunctions::rfts($sensor[$i], $buf, 1, 4096, false) && (trim($buf) != "")) { |
165
|
|
|
$dev = new SensorDevice(); |
166
|
|
|
$dev->setValue(trim($buf)); |
167
|
|
|
$label = preg_replace("/_input$/", "_label", $sensor[$i]); |
168
|
|
|
$alarm = preg_replace("/_input$/", "_alarm", $sensor[$i]); |
169
|
|
|
$max = preg_replace("/_input$/", "_max", $sensor[$i]); |
170
|
|
|
$min = preg_replace("/_input$/", "_min", $sensor[$i]); |
171
|
|
|
if (CommonFunctions::fileexists($label) && CommonFunctions::rfts($label, $buf, 1, 4096, false) && (trim($buf) != "")) { |
172
|
|
|
$dev->setName(trim($buf)); |
173
|
|
|
} else { |
174
|
|
|
$labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME))); |
175
|
|
|
if ($labelname !== "") { |
176
|
|
|
$dev->setName($labelname); |
177
|
|
|
} else { |
178
|
|
|
$dev->setName('unknown'); |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
if (CommonFunctions::fileexists($max) && CommonFunctions::rfts($max, $buf, 1, 4096, false) && (trim($buf) != "")) { |
182
|
|
|
$dev->setMax(trim($buf)); |
183
|
|
|
} |
184
|
|
|
if (CommonFunctions::fileexists($min) && CommonFunctions::rfts($min, $buf, 1, 4096, false) && (trim($buf) != "")) { |
185
|
|
|
$dev->setMin(trim($buf)); |
186
|
|
|
} |
187
|
|
|
if (CommonFunctions::fileexists($alarm) && CommonFunctions::rfts($alarm, $buf, 1, 4096, false) && (trim($buf) === "1")) { |
188
|
|
|
$dev->setEvent("Alarm"); |
189
|
|
|
} |
190
|
|
|
$this->mbinfo->setMbPower($dev); |
|
|
|
|
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* get current information |
197
|
|
|
* |
198
|
|
|
* @return void |
199
|
|
|
*/ |
200
|
|
View Code Duplication |
private function _current($hwpath) |
|
|
|
|
201
|
|
|
{ |
202
|
|
|
$sensor = glob($hwpath."curr*_input", GLOB_NOSORT); |
203
|
|
|
if (($total = count($sensor)) > 0) { |
204
|
|
|
$buf = ""; |
205
|
|
|
for ($i = 0; $i < $total; $i++) if (CommonFunctions::rfts($sensor[$i], $buf, 1, 4096, false) && (trim($buf) != "")) { |
206
|
|
|
$dev = new SensorDevice(); |
207
|
|
|
$dev->setValue(trim($buf)/1000); |
208
|
|
|
$label = preg_replace("/_input$/", "_label", $sensor[$i]); |
209
|
|
|
$alarm = preg_replace("/_input$/", "_alarm", $sensor[$i]); |
210
|
|
|
$max = preg_replace("/_input$/", "_max", $sensor[$i]); |
211
|
|
|
$min = preg_replace("/_input$/", "_min", $sensor[$i]); |
212
|
|
|
if (CommonFunctions::fileexists($label) && CommonFunctions::rfts($label, $buf, 1, 4096, false) && (trim($buf) != "")) { |
213
|
|
|
$dev->setName(trim($buf)); |
214
|
|
|
} else { |
215
|
|
|
$labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME))); |
216
|
|
|
if ($labelname !== "") { |
217
|
|
|
$dev->setName($labelname); |
218
|
|
|
} else { |
219
|
|
|
$dev->setName('unknown'); |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
if (CommonFunctions::fileexists($max) && CommonFunctions::rfts($max, $buf, 1, 4096, false) && (trim($buf) != "")) { |
223
|
|
|
$dev->setMax(trim($buf)/1000); |
224
|
|
|
} |
225
|
|
|
if (CommonFunctions::fileexists($min) && CommonFunctions::rfts($min, $buf, 1, 4096, false) && (trim($buf) != "")) { |
226
|
|
|
$dev->setMin(trim($buf)/1000); |
227
|
|
|
} |
228
|
|
|
if (CommonFunctions::fileexists($alarm) && CommonFunctions::rfts($alarm, $buf, 1, 4096, false) && (trim($buf) === "1")) { |
229
|
|
|
$dev->setEvent("Alarm"); |
230
|
|
|
} |
231
|
|
|
$this->mbinfo->setMbCurrent($dev); |
|
|
|
|
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* get the information |
238
|
|
|
* |
239
|
|
|
* @see PSI_Interface_Sensor::build() |
240
|
|
|
* |
241
|
|
|
* @return Void |
242
|
|
|
*/ |
243
|
|
|
public function build() |
244
|
|
|
{ |
245
|
|
|
$hwpaths = glob("/sys/class/hwmon/hwmon*/device/", GLOB_NOSORT); |
246
|
|
|
if (($totalh = count($hwpaths)) > 0) { |
247
|
|
|
for ($h = 0; $h < $totalh; $h++) { |
248
|
|
|
$this->_temperature($hwpaths[$h]); |
249
|
|
|
$this->_voltage($hwpaths[$h]); |
250
|
|
|
$this->_fans($hwpaths[$h]); |
251
|
|
|
$this->_power($hwpaths[$h]); |
252
|
|
|
$this->_current($hwpaths[$h]); |
253
|
|
|
} |
254
|
|
|
} |
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.