|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* BSDCommon Class |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* @category PHP |
|
8
|
|
|
* @package PSI BSDCommon OS class |
|
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.BSDCommon.inc.php 621 2012-07-29 18:49:04Z namiltd $ |
|
13
|
|
|
* @link http://phpsysinfo.sourceforge.net |
|
14
|
|
|
*/ |
|
15
|
|
|
/** |
|
16
|
|
|
* BSDCommon class |
|
17
|
|
|
* get all the required information for BSD Like systems |
|
18
|
|
|
* no need to implement in every class the same methods |
|
19
|
|
|
* |
|
20
|
|
|
* @category PHP |
|
21
|
|
|
* @package PSI BSDCommon OS class |
|
22
|
|
|
* @author Michael Cramer <[email protected]> |
|
23
|
|
|
* @copyright 2009 phpSysInfo |
|
24
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
|
25
|
|
|
* @version Release: 3.0 |
|
26
|
|
|
* @link http://phpsysinfo.sourceforge.net |
|
27
|
|
|
*/ |
|
28
|
|
|
abstract class BSDCommon extends OS |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* content of the syslog |
|
32
|
|
|
* |
|
33
|
|
|
* @var array |
|
34
|
|
|
*/ |
|
35
|
|
|
private $_dmesg = array(); |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* regexp1 for cpu information out of the syslog |
|
39
|
|
|
* |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
private $_CPURegExp1 = "//"; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* regexp2 for cpu information out of the syslog |
|
46
|
|
|
* |
|
47
|
|
|
* @var string |
|
48
|
|
|
*/ |
|
49
|
|
|
private $_CPURegExp2 = "//"; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* regexp1 for scsi information out of the syslog |
|
53
|
|
|
* |
|
54
|
|
|
* @var string |
|
55
|
|
|
*/ |
|
56
|
|
|
private $_SCSIRegExp1 = "//"; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* regexp2 for scsi information out of the syslog |
|
60
|
|
|
* |
|
61
|
|
|
* @var string |
|
62
|
|
|
*/ |
|
63
|
|
|
private $_SCSIRegExp2 = "//"; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* regexp1 for pci information out of the syslog |
|
67
|
|
|
* |
|
68
|
|
|
* @var string |
|
69
|
|
|
*/ |
|
70
|
|
|
private $_PCIRegExp1 = "//"; |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* regexp1 for pci information out of the syslog |
|
74
|
|
|
* |
|
75
|
|
|
* @var string |
|
76
|
|
|
*/ |
|
77
|
|
|
private $_PCIRegExp2 = "//"; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* call parent constructor |
|
81
|
|
|
*/ |
|
82
|
|
|
public function __construct() |
|
83
|
|
|
{ |
|
84
|
|
|
parent::__construct(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* setter for cpuregexp1 |
|
89
|
|
|
* |
|
90
|
|
|
* @param string $value value to set |
|
91
|
|
|
* |
|
92
|
|
|
* @return void |
|
93
|
|
|
*/ |
|
94
|
|
|
protected function setCPURegExp1($value) |
|
95
|
|
|
{ |
|
96
|
|
|
$this->_CPURegExp1 = $value; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* setter for cpuregexp2 |
|
101
|
|
|
* |
|
102
|
|
|
* @param string $value value to set |
|
103
|
|
|
* |
|
104
|
|
|
* @return void |
|
105
|
|
|
*/ |
|
106
|
|
|
protected function setCPURegExp2($value) |
|
107
|
|
|
{ |
|
108
|
|
|
$this->_CPURegExp2 = $value; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* setter for scsiregexp1 |
|
113
|
|
|
* |
|
114
|
|
|
* @param string $value value to set |
|
115
|
|
|
* |
|
116
|
|
|
* @return void |
|
117
|
|
|
*/ |
|
118
|
|
|
protected function setSCSIRegExp1($value) |
|
119
|
|
|
{ |
|
120
|
|
|
$this->_SCSIRegExp1 = $value; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* setter for scsiregexp2 |
|
125
|
|
|
* |
|
126
|
|
|
* @param string $value value to set |
|
127
|
|
|
* |
|
128
|
|
|
* @return void |
|
129
|
|
|
*/ |
|
130
|
|
|
protected function setSCSIRegExp2($value) |
|
131
|
|
|
{ |
|
132
|
|
|
$this->_SCSIRegExp2 = $value; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* setter for pciregexp1 |
|
137
|
|
|
* |
|
138
|
|
|
* @param string $value value to set |
|
139
|
|
|
* |
|
140
|
|
|
* @return void |
|
141
|
|
|
*/ |
|
142
|
|
|
protected function setPCIRegExp1($value) |
|
143
|
|
|
{ |
|
144
|
|
|
$this->_PCIRegExp1 = $value; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* setter for pciregexp2 |
|
149
|
|
|
* |
|
150
|
|
|
* @param string $value value to set |
|
151
|
|
|
* |
|
152
|
|
|
* @return void |
|
153
|
|
|
*/ |
|
154
|
|
|
protected function setPCIRegExp2($value) |
|
155
|
|
|
{ |
|
156
|
|
|
$this->_PCIRegExp2 = $value; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* read /var/run/dmesg.boot, but only if we haven't already |
|
161
|
|
|
* |
|
162
|
|
|
* @return array |
|
163
|
|
|
*/ |
|
164
|
|
|
protected function readdmesg() |
|
165
|
|
|
{ |
|
166
|
|
|
if (count($this->_dmesg) === 0) { |
|
167
|
|
|
if (PSI_OS != "Darwin") { |
|
168
|
|
|
if (CommonFunctions::rfts('/var/run/dmesg.boot', $buf, 0, 4096, false) || CommonFunctions::rfts('/var/log/dmesg.boot', $buf, 0, 4096, false) || CommonFunctions::rfts('/var/run/dmesg.boot', $buf)) { // Once again but with debug |
|
169
|
|
|
$parts = preg_split("/rebooting|Uptime/", $buf, -1, PREG_SPLIT_NO_EMPTY); |
|
170
|
|
|
$this->_dmesg = preg_split("/\n/", $parts[count($parts) - 1], -1, PREG_SPLIT_NO_EMPTY); |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
return $this->_dmesg; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* get a value from sysctl command |
|
180
|
|
|
* |
|
181
|
|
|
* @param string $key key for the value to get |
|
182
|
|
|
* |
|
183
|
|
|
* @return string |
|
184
|
|
|
*/ |
|
185
|
|
|
protected function grabkey($key) |
|
186
|
|
|
{ |
|
187
|
|
|
$buf = ""; |
|
188
|
|
|
if (CommonFunctions::executeProgram('sysctl', "-n $key", $buf, PSI_DEBUG)) { |
|
189
|
|
|
return $buf; |
|
190
|
|
|
} else { |
|
191
|
|
|
return ''; |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Virtual Host Name |
|
197
|
|
|
* |
|
198
|
|
|
* @return void |
|
199
|
|
|
*/ |
|
200
|
|
View Code Duplication |
protected function hostname() |
|
|
|
|
|
|
201
|
|
|
{ |
|
202
|
|
|
if (PSI_USE_VHOST === true) { |
|
203
|
|
|
$this->sys->setHostname(getenv('SERVER_NAME')); |
|
204
|
|
|
} else { |
|
205
|
|
|
if (CommonFunctions::executeProgram('hostname', '', $buf, PSI_DEBUG)) { |
|
206
|
|
|
$this->sys->setHostname($buf); |
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Kernel Version |
|
213
|
|
|
* |
|
214
|
|
|
* @return void |
|
215
|
|
|
*/ |
|
216
|
|
|
protected function kernel() |
|
217
|
|
|
{ |
|
218
|
|
|
$s = $this->grabkey('kern.version'); |
|
219
|
|
|
$a = preg_split('/:/', $s); |
|
220
|
|
|
if (isset($a[2])) { |
|
221
|
|
|
$this->sys->setKernel($a[0].$a[1].':'.$a[2]); |
|
222
|
|
|
} else { |
|
223
|
|
|
$this->sys->setKernel($s); |
|
224
|
|
|
} |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* Processor Load |
|
229
|
|
|
* optionally create a loadbar |
|
230
|
|
|
* |
|
231
|
|
|
* @return void |
|
232
|
|
|
*/ |
|
233
|
|
|
protected function loadavg() |
|
234
|
|
|
{ |
|
235
|
|
|
$s = $this->grabkey('vm.loadavg'); |
|
236
|
|
|
$s = preg_replace('/{ /', '', $s); |
|
237
|
|
|
$s = preg_replace('/ }/', '', $s); |
|
238
|
|
|
$this->sys->setLoad($s); |
|
239
|
|
|
if (PSI_LOAD_BAR && (PSI_OS != "Darwin")) { |
|
240
|
|
|
if ($fd = $this->grabkey('kern.cp_time')) { |
|
241
|
|
|
// Find out the CPU load |
|
242
|
|
|
// user + sys = load |
|
243
|
|
|
// total = total |
|
244
|
|
|
preg_match($this->_CPURegExp2, $fd, $res); |
|
245
|
|
|
$load = $res[2] + $res[3] + $res[4]; // cpu.user + cpu.sys |
|
246
|
|
|
$total = $res[2] + $res[3] + $res[4] + $res[5]; // cpu.total |
|
247
|
|
|
// we need a second value, wait 1 second befor getting (< 1 second no good value will occour) |
|
248
|
|
|
sleep(1); |
|
249
|
|
|
$fd = $this->grabkey('kern.cp_time'); |
|
250
|
|
|
preg_match($this->_CPURegExp2, $fd, $res); |
|
251
|
|
|
$load2 = $res[2] + $res[3] + $res[4]; |
|
252
|
|
|
$total2 = $res[2] + $res[3] + $res[4] + $res[5]; |
|
253
|
|
|
$this->sys->setLoadPercent((100 * ($load2 - $load)) / ($total2 - $total)); |
|
254
|
|
|
} |
|
255
|
|
|
} |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* CPU information |
|
260
|
|
|
* |
|
261
|
|
|
* @return void |
|
262
|
|
|
*/ |
|
263
|
|
|
protected function cpuinfo() |
|
264
|
|
|
{ |
|
265
|
|
|
$dev = new CpuDevice(); |
|
266
|
|
|
|
|
267
|
|
|
if (PSI_OS == "NetBSD") { |
|
268
|
|
|
if ($model = $this->grabkey('machdep.cpu_brand')) { |
|
269
|
|
|
$dev->setModel($model); |
|
270
|
|
|
} |
|
271
|
|
|
if ($cpuspeed = $this->grabkey('machdep.tsc_freq')) { |
|
272
|
|
|
$dev->setCpuSpeed(round($cpuspeed / 1000000)); |
|
273
|
|
|
} |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
if ($dev->getModel() === "") { |
|
277
|
|
|
$dev->setModel($this->grabkey('hw.model')); |
|
278
|
|
|
} |
|
279
|
|
|
$notwas = true; |
|
280
|
|
|
foreach ($this->readdmesg() as $line) { |
|
281
|
|
|
if ($notwas) { |
|
282
|
|
|
if (preg_match($this->_CPURegExp1, $line, $ar_buf)) { |
|
283
|
|
|
if ($dev->getCpuSpeed() === 0) { |
|
284
|
|
|
$dev->setCpuSpeed(round($ar_buf[2])); |
|
285
|
|
|
} |
|
286
|
|
|
$notwas = false; |
|
287
|
|
|
} |
|
288
|
|
|
} else { |
|
289
|
|
|
if (preg_match("/ Origin| Features/", $line, $ar_buf)) { |
|
290
|
|
|
if (preg_match("/ Features2[ ]*=.*<(.*)>/", $line, $ar_buf)) { |
|
291
|
|
|
$feats = preg_split("/,/", strtolower(trim($ar_buf[1])), -1, PREG_SPLIT_NO_EMPTY); |
|
292
|
|
|
foreach ($feats as $feat) { |
|
293
|
|
|
if (($feat=="vmx") || ($feat=="svm")) { |
|
294
|
|
|
$dev->setVirt($feat); |
|
295
|
|
|
break 2; |
|
296
|
|
|
} |
|
297
|
|
|
} |
|
298
|
|
|
break; |
|
299
|
|
|
} |
|
300
|
|
|
} else break; |
|
301
|
|
|
} |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
$ncpu = $this->grabkey('hw.ncpu'); |
|
305
|
|
View Code Duplication |
if (is_null($ncpu) || (trim($ncpu) == "") || (!($ncpu >= 1))) |
|
|
|
|
|
|
306
|
|
|
$ncpu = 1; |
|
307
|
|
|
for ($ncpu ; $ncpu > 0 ; $ncpu--) { |
|
308
|
|
|
$this->sys->setCpus($dev); |
|
|
|
|
|
|
309
|
|
|
} |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
/** |
|
313
|
|
|
* SCSI devices |
|
314
|
|
|
* get the scsi device information out of dmesg |
|
315
|
|
|
* |
|
316
|
|
|
* @return void |
|
317
|
|
|
*/ |
|
318
|
|
|
protected function scsi() |
|
319
|
|
|
{ |
|
320
|
|
|
foreach ($this->readdmesg() as $line) { |
|
321
|
|
|
if (preg_match($this->_SCSIRegExp1, $line, $ar_buf)) { |
|
322
|
|
|
$dev = new HWDevice(); |
|
323
|
|
|
$dev->setName($ar_buf[1].": ".$ar_buf[2]); |
|
324
|
|
|
$this->sys->setScsiDevices($dev); |
|
325
|
|
View Code Duplication |
} elseif (preg_match($this->_SCSIRegExp2, $line, $ar_buf)) { |
|
|
|
|
|
|
326
|
|
|
/* duplication security */ |
|
327
|
|
|
$notwas = true; |
|
328
|
|
|
foreach ($this->sys->getScsiDevices() as $finddev) { |
|
329
|
|
|
if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) { |
|
330
|
|
|
$finddev->setCapacity($ar_buf[2] * 2048 * 1.049); |
|
331
|
|
|
$notwas = false; |
|
332
|
|
|
break; |
|
333
|
|
|
} |
|
334
|
|
|
} |
|
335
|
|
|
if ($notwas) { |
|
336
|
|
|
$dev = new HWDevice(); |
|
337
|
|
|
$dev->setName($ar_buf[1]); |
|
338
|
|
|
$dev->setCapacity($ar_buf[2] * 2048 * 1.049); |
|
339
|
|
|
$this->sys->setScsiDevices($dev); |
|
340
|
|
|
} |
|
341
|
|
|
} |
|
342
|
|
|
} |
|
343
|
|
|
/* cleaning */ |
|
344
|
|
View Code Duplication |
foreach ($this->sys->getScsiDevices() as $finddev) { |
|
|
|
|
|
|
345
|
|
|
if (strpos($finddev->getName(), ': ') !== false) |
|
346
|
|
|
$finddev->setName(substr(strstr($finddev->getName(), ': '), 2)); |
|
347
|
|
|
} |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
/** |
|
351
|
|
|
* parsing the output of pciconf command |
|
352
|
|
|
* |
|
353
|
|
|
* @return Array |
|
354
|
|
|
*/ |
|
355
|
|
|
protected function pciconf() |
|
356
|
|
|
{ |
|
357
|
|
|
$arrResults = array(); |
|
358
|
|
|
$intS = 0; |
|
359
|
|
|
if (CommonFunctions::executeProgram("pciconf", "-lv", $strBuf, PSI_DEBUG)) { |
|
360
|
|
|
$arrTemp = array(); |
|
361
|
|
|
$arrBlocks = preg_split("/\n\S/", $strBuf, -1, PREG_SPLIT_NO_EMPTY); |
|
362
|
|
|
foreach ($arrBlocks as $strBlock) { |
|
363
|
|
|
$arrLines = preg_split("/\n/", $strBlock, -1, PREG_SPLIT_NO_EMPTY); |
|
364
|
|
|
$vend = null; |
|
365
|
|
|
foreach ($arrLines as $strLine) { |
|
366
|
|
|
if (preg_match("/\sclass=0x([a-fA-F0-9]{4})[a-fA-F0-9]{2}\s.*\schip=0x([a-fA-F0-9]{4})([a-fA-F0-9]{4})\s/", $strLine, $arrParts)) { |
|
367
|
|
|
$arrTemp[$intS] = 'Class '.$arrParts[1].': Device '.$arrParts[3].':'.$arrParts[2]; |
|
368
|
|
|
$vend = ''; |
|
369
|
|
|
} elseif (preg_match("/(.*) = '(.*)'/", $strLine, $arrParts)) { |
|
370
|
|
|
if (trim($arrParts[1]) == "vendor") { |
|
371
|
|
|
$vend = trim($arrParts[2]); |
|
372
|
|
|
} elseif (trim($arrParts[1]) == "device") { |
|
373
|
|
|
if (($vend !== null) && ($vend !== '')) { |
|
374
|
|
|
$arrTemp[$intS] = $vend." - ".trim($arrParts[2]); |
|
375
|
|
|
} else { |
|
376
|
|
|
$arrTemp[$intS] = trim($arrParts[2]); |
|
377
|
|
|
$vend = ''; |
|
378
|
|
|
} |
|
379
|
|
|
} |
|
380
|
|
|
} |
|
381
|
|
|
} |
|
382
|
|
|
if ($vend !== null) { |
|
383
|
|
|
$intS++; |
|
384
|
|
|
} |
|
385
|
|
|
} |
|
386
|
|
|
foreach ($arrTemp as $name) { |
|
387
|
|
|
$dev = new HWDevice(); |
|
388
|
|
|
$dev->setName($name); |
|
389
|
|
|
$arrResults[] = $dev; |
|
390
|
|
|
} |
|
391
|
|
|
} |
|
392
|
|
|
|
|
393
|
|
|
return $arrResults; |
|
394
|
|
|
} |
|
395
|
|
|
|
|
396
|
|
|
/** |
|
397
|
|
|
* PCI devices |
|
398
|
|
|
* get the pci device information out of dmesg |
|
399
|
|
|
* |
|
400
|
|
|
* @return void |
|
401
|
|
|
*/ |
|
402
|
|
|
protected function pci() |
|
403
|
|
|
{ |
|
404
|
|
|
if ((!$results = Parser::lspci(false)) && (!$results = $this->pciconf())) { |
|
405
|
|
|
foreach ($this->readdmesg() as $line) { |
|
406
|
|
|
if (preg_match($this->_PCIRegExp1, $line, $ar_buf)) { |
|
407
|
|
|
$dev = new HWDevice(); |
|
408
|
|
|
$dev->setName($ar_buf[1].": ".$ar_buf[2]); |
|
409
|
|
|
$results[] = $dev; |
|
410
|
|
|
} elseif (preg_match($this->_PCIRegExp2, $line, $ar_buf)) { |
|
411
|
|
|
$dev = new HWDevice(); |
|
412
|
|
|
$dev->setName($ar_buf[1].": ".$ar_buf[2]); |
|
413
|
|
|
$results[] = $dev; |
|
414
|
|
|
} |
|
415
|
|
|
} |
|
416
|
|
|
} |
|
417
|
|
|
foreach ($results as $dev) { |
|
418
|
|
|
$this->sys->setPciDevices($dev); |
|
419
|
|
|
} |
|
420
|
|
|
} |
|
421
|
|
|
|
|
422
|
|
|
/** |
|
423
|
|
|
* IDE devices |
|
424
|
|
|
* get the ide device information out of dmesg |
|
425
|
|
|
* |
|
426
|
|
|
* @return void |
|
427
|
|
|
*/ |
|
428
|
|
|
protected function ide() |
|
429
|
|
|
{ |
|
430
|
|
|
foreach ($this->readdmesg() as $line) { |
|
431
|
|
|
if (preg_match('/^(ad[0-9]+): (.*)MB <(.*)> (.*) (.*)/', $line, $ar_buf)) { |
|
432
|
|
|
$dev = new HWDevice(); |
|
433
|
|
|
$dev->setName($ar_buf[1].": ".$ar_buf[3]); |
|
434
|
|
|
$dev->setCapacity($ar_buf[2] * 1024); |
|
435
|
|
|
$this->sys->setIdeDevices($dev); |
|
436
|
|
|
} elseif (preg_match('/^(acd[0-9]+): (.*) <(.*)> (.*)/', $line, $ar_buf)) { |
|
437
|
|
|
$dev = new HWDevice(); |
|
438
|
|
|
$dev->setName($ar_buf[1].": ".$ar_buf[3]); |
|
439
|
|
|
$this->sys->setIdeDevices($dev); |
|
440
|
|
|
} elseif (preg_match('/^(ada[0-9]+): <(.*)> (.*)/', $line, $ar_buf)) { |
|
441
|
|
|
$dev = new HWDevice(); |
|
442
|
|
|
$dev->setName($ar_buf[1].": ".$ar_buf[2]); |
|
443
|
|
|
$this->sys->setIdeDevices($dev); |
|
444
|
|
View Code Duplication |
} elseif (preg_match('/^(ada[0-9]+): (.*)MB \((.*)\)/', $line, $ar_buf)) { |
|
|
|
|
|
|
445
|
|
|
/* duplication security */ |
|
446
|
|
|
$notwas = true; |
|
447
|
|
|
foreach ($this->sys->getIdeDevices() as $finddev) { |
|
448
|
|
|
if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) { |
|
449
|
|
|
$finddev->setCapacity($ar_buf[2] * 1024); |
|
450
|
|
|
$notwas = false; |
|
451
|
|
|
break; |
|
452
|
|
|
} |
|
453
|
|
|
} |
|
454
|
|
|
if ($notwas) { |
|
455
|
|
|
$dev = new HWDevice(); |
|
456
|
|
|
$dev->setName($ar_buf[1]); |
|
457
|
|
|
$dev->setCapacity($ar_buf[2] * 1024); |
|
458
|
|
|
$this->sys->setIdeDevices($dev); |
|
459
|
|
|
} |
|
460
|
|
|
} |
|
461
|
|
|
} |
|
462
|
|
|
/* cleaning */ |
|
463
|
|
View Code Duplication |
foreach ($this->sys->getIdeDevices() as $finddev) { |
|
|
|
|
|
|
464
|
|
|
if (strpos($finddev->getName(), ': ') !== false) |
|
465
|
|
|
$finddev->setName(substr(strstr($finddev->getName(), ': '), 2)); |
|
466
|
|
|
} |
|
467
|
|
|
} |
|
468
|
|
|
|
|
469
|
|
|
/** |
|
470
|
|
|
* Physical memory information and Swap Space information |
|
471
|
|
|
* |
|
472
|
|
|
* @return void |
|
473
|
|
|
*/ |
|
474
|
|
|
protected function memory() |
|
475
|
|
|
{ |
|
476
|
|
|
if (PSI_OS == 'FreeBSD' || PSI_OS == 'OpenBSD') { |
|
477
|
|
|
// vmstat on fbsd 4.4 or greater outputs kbytes not hw.pagesize |
|
478
|
|
|
// I should probably add some version checking here, but for now |
|
479
|
|
|
// we only support fbsd 4.4 |
|
480
|
|
|
$pagesize = 1024; |
|
481
|
|
|
} else { |
|
482
|
|
|
$pagesize = $this->grabkey('hw.pagesize'); |
|
483
|
|
|
} |
|
484
|
|
|
if (CommonFunctions::executeProgram('vmstat', '', $vmstat, PSI_DEBUG)) { |
|
485
|
|
|
$lines = preg_split("/\n/", $vmstat, -1, PREG_SPLIT_NO_EMPTY); |
|
486
|
|
|
$ar_buf = preg_split("/\s+/", trim($lines[2]), 19); |
|
487
|
|
|
if (PSI_OS == 'NetBSD' || PSI_OS == 'DragonFly') { |
|
488
|
|
|
$this->sys->setMemFree($ar_buf[4] * 1024); |
|
489
|
|
|
} else { |
|
490
|
|
|
$this->sys->setMemFree($ar_buf[4] * $pagesize); |
|
491
|
|
|
} |
|
492
|
|
|
$this->sys->setMemTotal($this->grabkey('hw.physmem')); |
|
493
|
|
|
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree()); |
|
494
|
|
|
|
|
495
|
|
|
if (((PSI_OS == 'OpenBSD' || PSI_OS == 'NetBSD') && CommonFunctions::executeProgram('swapctl', '-l -k', $swapstat, PSI_DEBUG)) || CommonFunctions::executeProgram('swapinfo', '-k', $swapstat, PSI_DEBUG)) { |
|
496
|
|
|
$lines = preg_split("/\n/", $swapstat, -1, PREG_SPLIT_NO_EMPTY); |
|
497
|
|
|
foreach ($lines as $line) { |
|
498
|
|
|
$ar_buf = preg_split("/\s+/", $line, 6); |
|
499
|
|
|
if (($ar_buf[0] != 'Total') && ($ar_buf[0] != 'Device')) { |
|
500
|
|
|
$dev = new DiskDevice(); |
|
501
|
|
|
$dev->setMountPoint($ar_buf[0]); |
|
502
|
|
|
$dev->setName("SWAP"); |
|
503
|
|
|
$dev->setFsType('swap'); |
|
504
|
|
|
$dev->setTotal($ar_buf[1] * 1024); |
|
505
|
|
|
$dev->setUsed($ar_buf[2] * 1024); |
|
506
|
|
|
$dev->setFree($dev->getTotal() - $dev->getUsed()); |
|
507
|
|
|
$this->sys->setSwapDevices($dev); |
|
508
|
|
|
} |
|
509
|
|
|
} |
|
510
|
|
|
} |
|
511
|
|
|
} |
|
512
|
|
|
} |
|
513
|
|
|
|
|
514
|
|
|
/** |
|
515
|
|
|
* USB devices |
|
516
|
|
|
* get the ide device information out of dmesg |
|
517
|
|
|
* |
|
518
|
|
|
* @return void |
|
519
|
|
|
*/ |
|
520
|
|
View Code Duplication |
protected function usb() |
|
|
|
|
|
|
521
|
|
|
{ |
|
522
|
|
|
foreach ($this->readdmesg() as $line) { |
|
523
|
|
|
// if (preg_match('/^(ugen[0-9\.]+): <(.*)> (.*) (.*)/', $line, $ar_buf)) { |
|
|
|
|
|
|
524
|
|
|
// $dev->setName($ar_buf[1].": ".$ar_buf[2]); |
|
525
|
|
|
if (preg_match('/^(u[a-z]+[0-9]+): <([^,]*)(.*)> on (usbus[0-9]+)/', $line, $ar_buf)) { |
|
526
|
|
|
$dev = new HWDevice(); |
|
527
|
|
|
$dev->setName($ar_buf[2]); |
|
528
|
|
|
$this->sys->setUSBDevices($dev); |
|
529
|
|
|
} |
|
530
|
|
|
} |
|
531
|
|
|
} |
|
532
|
|
|
|
|
533
|
|
|
/** |
|
534
|
|
|
* filesystem information |
|
535
|
|
|
* |
|
536
|
|
|
* @return void |
|
537
|
|
|
*/ |
|
538
|
|
|
protected function filesystems() |
|
539
|
|
|
{ |
|
540
|
|
|
$arrResult = Parser::df(); |
|
541
|
|
|
foreach ($arrResult as $dev) { |
|
542
|
|
|
$this->sys->setDiskDevices($dev); |
|
543
|
|
|
} |
|
544
|
|
|
} |
|
545
|
|
|
|
|
546
|
|
|
/** |
|
547
|
|
|
* Distribution |
|
548
|
|
|
* |
|
549
|
|
|
* @return void |
|
550
|
|
|
*/ |
|
551
|
|
|
protected function distro() |
|
552
|
|
|
{ |
|
553
|
|
|
if (CommonFunctions::executeProgram('uname', '-s', $result, PSI_DEBUG)) { |
|
554
|
|
|
$this->sys->setDistribution($result); |
|
555
|
|
|
} |
|
556
|
|
|
} |
|
557
|
|
|
|
|
558
|
|
|
/** |
|
559
|
|
|
* get the information |
|
560
|
|
|
* |
|
561
|
|
|
* @see PSI_Interface_OS::build() |
|
562
|
|
|
* |
|
563
|
|
|
* @return Void |
|
564
|
|
|
*/ |
|
565
|
|
|
public function build() |
|
566
|
|
|
{ |
|
567
|
|
|
$this->distro(); |
|
568
|
|
|
$this->memory(); |
|
569
|
|
|
$this->ide(); |
|
570
|
|
|
$this->pci(); |
|
571
|
|
|
$this->cpuinfo(); |
|
572
|
|
|
$this->filesystems(); |
|
573
|
|
|
$this->kernel(); |
|
574
|
|
|
$this->loadavg(); |
|
575
|
|
|
$this->hostname(); |
|
576
|
|
|
$this->scsi(); |
|
577
|
|
|
$this->usb(); |
|
578
|
|
|
$this->_users(); |
|
579
|
|
|
} |
|
580
|
|
|
} |
|
581
|
|
|
|
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.