| 2770 |
rexy |
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 <BigMichi1@users.sourceforge.net>
|
|
|
10 |
* @copyright 2009 phpSysInfo
|
|
|
11 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
|
|
|
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 <BigMichi1@users.sourceforge.net>
|
|
|
23 |
* @copyright 2009 phpSysInfo
|
|
|
24 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
|
|
|
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 = null;
|
|
|
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 |
* regexp3 for scsi information out of the syslog
|
|
|
67 |
*
|
|
|
68 |
* @var string
|
|
|
69 |
*/
|
|
|
70 |
private $_SCSIRegExp3 = "//";
|
|
|
71 |
|
|
|
72 |
/**
|
|
|
73 |
* regexp1 for pci information out of the syslog
|
|
|
74 |
*
|
|
|
75 |
* @var string
|
|
|
76 |
*/
|
|
|
77 |
private $_PCIRegExp1 = "//";
|
|
|
78 |
|
|
|
79 |
/**
|
|
|
80 |
* regexp1 for pci information out of the syslog
|
|
|
81 |
*
|
|
|
82 |
* @var string
|
|
|
83 |
*/
|
|
|
84 |
private $_PCIRegExp2 = "//";
|
|
|
85 |
|
|
|
86 |
/**
|
|
|
87 |
* setter for cpuregexp1
|
|
|
88 |
*
|
|
|
89 |
* @param string $value value to set
|
|
|
90 |
*
|
|
|
91 |
* @return void
|
|
|
92 |
*/
|
|
|
93 |
protected function setCPURegExp1($value)
|
|
|
94 |
{
|
|
|
95 |
$this->_CPURegExp1 = $value;
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
/**
|
|
|
99 |
* setter for cpuregexp2
|
|
|
100 |
*
|
|
|
101 |
* @param string $value value to set
|
|
|
102 |
*
|
|
|
103 |
* @return void
|
|
|
104 |
*/
|
|
|
105 |
protected function setCPURegExp2($value)
|
|
|
106 |
{
|
|
|
107 |
$this->_CPURegExp2 = $value;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
/**
|
|
|
111 |
* setter for scsiregexp1
|
|
|
112 |
*
|
|
|
113 |
* @param string $value value to set
|
|
|
114 |
*
|
|
|
115 |
* @return void
|
|
|
116 |
*/
|
|
|
117 |
protected function setSCSIRegExp1($value)
|
|
|
118 |
{
|
|
|
119 |
$this->_SCSIRegExp1 = $value;
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
/**
|
|
|
123 |
* setter for scsiregexp2
|
|
|
124 |
*
|
|
|
125 |
* @param string $value value to set
|
|
|
126 |
*
|
|
|
127 |
* @return void
|
|
|
128 |
*/
|
|
|
129 |
protected function setSCSIRegExp2($value)
|
|
|
130 |
{
|
|
|
131 |
$this->_SCSIRegExp2 = $value;
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
/**
|
|
|
135 |
* setter for scsiregexp3
|
|
|
136 |
*
|
|
|
137 |
* @param string $value value to set
|
|
|
138 |
*
|
|
|
139 |
* @return void
|
|
|
140 |
*/
|
|
|
141 |
protected function setSCSIRegExp3($value)
|
|
|
142 |
{
|
|
|
143 |
$this->_SCSIRegExp3 = $value;
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
/**
|
|
|
147 |
* setter for pciregexp1
|
|
|
148 |
*
|
|
|
149 |
* @param string $value value to set
|
|
|
150 |
*
|
|
|
151 |
* @return void
|
|
|
152 |
*/
|
|
|
153 |
protected function setPCIRegExp1($value)
|
|
|
154 |
{
|
|
|
155 |
$this->_PCIRegExp1 = $value;
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
/**
|
|
|
159 |
* setter for pciregexp2
|
|
|
160 |
*
|
|
|
161 |
* @param string $value value to set
|
|
|
162 |
*
|
|
|
163 |
* @return void
|
|
|
164 |
*/
|
|
|
165 |
protected function setPCIRegExp2($value)
|
|
|
166 |
{
|
|
|
167 |
$this->_PCIRegExp2 = $value;
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
/**
|
|
|
171 |
* read /var/run/dmesg.boot, but only if we haven't already
|
|
|
172 |
*
|
|
|
173 |
* @return array
|
|
|
174 |
*/
|
|
|
175 |
protected function readdmesg()
|
|
|
176 |
{
|
|
|
177 |
if ($this->_dmesg === null) {
|
|
|
178 |
if ((PSI_OS != "Darwin") && (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
|
|
|
179 |
$parts = preg_split("/rebooting|Uptime/", $buf, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
180 |
$this->_dmesg = preg_split("/\n/", $parts[count($parts) - 1], -1, PREG_SPLIT_NO_EMPTY);
|
|
|
181 |
} else {
|
|
|
182 |
$this->_dmesg = array();
|
|
|
183 |
}
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
return $this->_dmesg;
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
/**
|
|
|
190 |
* get a value from sysctl command
|
|
|
191 |
*
|
|
|
192 |
* @param string $key key for the value to get
|
|
|
193 |
*
|
|
|
194 |
* @return string
|
|
|
195 |
*/
|
|
|
196 |
protected function grabkey($key)
|
|
|
197 |
{
|
|
|
198 |
$buf = "";
|
|
|
199 |
if (CommonFunctions::executeProgram('sysctl', "-n $key", $buf, PSI_DEBUG)) {
|
|
|
200 |
return $buf;
|
|
|
201 |
} else {
|
|
|
202 |
return '';
|
|
|
203 |
}
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
/**
|
|
|
207 |
* Virtual Host Name
|
|
|
208 |
*
|
|
|
209 |
* @return void
|
|
|
210 |
*/
|
|
|
211 |
protected function hostname()
|
|
|
212 |
{
|
|
|
213 |
if (PSI_USE_VHOST === true) {
|
|
|
214 |
if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
|
|
|
215 |
} else {
|
|
|
216 |
if (CommonFunctions::executeProgram('hostname', '', $buf, PSI_DEBUG)) {
|
|
|
217 |
$this->sys->setHostname($buf);
|
|
|
218 |
}
|
|
|
219 |
}
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
/**
|
|
|
223 |
* Kernel Version
|
|
|
224 |
*
|
|
|
225 |
* @return void
|
|
|
226 |
*/
|
|
|
227 |
protected function kernel()
|
|
|
228 |
{
|
|
|
229 |
$s = $this->grabkey('kern.version');
|
|
|
230 |
$a = preg_split('/:/', $s);
|
|
|
231 |
if (isset($a[2])) {
|
|
|
232 |
$this->sys->setKernel($a[0].$a[1].':'.$a[2]);
|
|
|
233 |
} else {
|
|
|
234 |
$this->sys->setKernel($s);
|
|
|
235 |
}
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
/**
|
|
|
239 |
* Processor Load
|
|
|
240 |
* optionally create a loadbar
|
|
|
241 |
*
|
|
|
242 |
* @return void
|
|
|
243 |
*/
|
|
|
244 |
protected function loadavg()
|
|
|
245 |
{
|
|
|
246 |
$s = $this->grabkey('vm.loadavg');
|
|
|
247 |
$s = preg_replace('/{ /', '', $s);
|
|
|
248 |
$s = preg_replace('/ }/', '', $s);
|
|
|
249 |
$this->sys->setLoad($s);
|
|
|
250 |
if (PSI_LOAD_BAR && (PSI_OS != "Darwin")) {
|
|
|
251 |
if ($fd = $this->grabkey('kern.cp_time')) {
|
|
|
252 |
// Find out the CPU load
|
|
|
253 |
// user + sys = load
|
|
|
254 |
// total = total
|
|
|
255 |
preg_match($this->_CPURegExp2, $fd, $res);
|
|
|
256 |
$load = $res[2] + $res[3] + $res[4]; // cpu.user + cpu.sys
|
|
|
257 |
$total = $res[2] + $res[3] + $res[4] + $res[5]; // cpu.total
|
|
|
258 |
// we need a second value, wait 1 second befor getting (< 1 second no good value will occour)
|
|
|
259 |
sleep(1);
|
|
|
260 |
$fd = $this->grabkey('kern.cp_time');
|
|
|
261 |
preg_match($this->_CPURegExp2, $fd, $res);
|
|
|
262 |
$load2 = $res[2] + $res[3] + $res[4];
|
|
|
263 |
$total2 = $res[2] + $res[3] + $res[4] + $res[5];
|
|
|
264 |
$this->sys->setLoadPercent((100 * ($load2 - $load)) / ($total2 - $total));
|
|
|
265 |
}
|
|
|
266 |
}
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
/**
|
|
|
270 |
* CPU information
|
|
|
271 |
*
|
|
|
272 |
* @return void
|
|
|
273 |
*/
|
|
|
274 |
protected function cpuinfo()
|
|
|
275 |
{
|
|
|
276 |
$dev = new CpuDevice();
|
|
|
277 |
|
|
|
278 |
if (PSI_OS == "NetBSD") {
|
|
|
279 |
if ($model = $this->grabkey('machdep.cpu_brand')) {
|
|
|
280 |
$dev->setModel($model);
|
|
|
281 |
}
|
|
|
282 |
if ($cpuspeed = $this->grabkey('machdep.tsc_freq')) {
|
|
|
283 |
$dev->setCpuSpeed(round($cpuspeed / 1000000));
|
|
|
284 |
}
|
|
|
285 |
}
|
|
|
286 |
|
|
|
287 |
if ($dev->getModel() === "") {
|
|
|
288 |
$dev->setModel($this->grabkey('hw.model'));
|
|
|
289 |
}
|
|
|
290 |
$notwas = true;
|
|
|
291 |
foreach ($this->readdmesg() as $line) {
|
|
|
292 |
if ($notwas) {
|
|
|
293 |
if (preg_match($this->_CPURegExp1, $line, $ar_buf)) {
|
|
|
294 |
if ($dev->getCpuSpeed() === 0) {
|
|
|
295 |
$dev->setCpuSpeed(round($ar_buf[2]));
|
|
|
296 |
}
|
|
|
297 |
$notwas = false;
|
|
|
298 |
}
|
|
|
299 |
} else {
|
|
|
300 |
if (preg_match("/ Origin| Features/", $line, $ar_buf)) {
|
|
|
301 |
if (preg_match("/ Features2[ ]*=.*<(.*)>/", $line, $ar_buf)) {
|
|
|
302 |
$feats = preg_split("/,/", strtolower(trim($ar_buf[1])), -1, PREG_SPLIT_NO_EMPTY);
|
|
|
303 |
foreach ($feats as $feat) {
|
|
|
304 |
if (($feat=="vmx") || ($feat=="svm")) {
|
|
|
305 |
$dev->setVirt($feat);
|
|
|
306 |
break 2;
|
|
|
307 |
}
|
|
|
308 |
}
|
|
|
309 |
break;
|
|
|
310 |
}
|
|
|
311 |
} else break;
|
|
|
312 |
}
|
|
|
313 |
}
|
|
|
314 |
|
|
|
315 |
$ncpu = $this->grabkey('hw.ncpu');
|
|
|
316 |
if (is_null($ncpu) || (trim($ncpu) == "") || (!($ncpu >= 1)))
|
|
|
317 |
$ncpu = 1;
|
|
|
318 |
for ($ncpu ; $ncpu > 0 ; $ncpu--) {
|
|
|
319 |
$this->sys->setCpus($dev);
|
|
|
320 |
}
|
|
|
321 |
}
|
|
|
322 |
|
|
|
323 |
/**
|
|
|
324 |
* SCSI devices
|
|
|
325 |
* get the scsi device information out of dmesg
|
|
|
326 |
*
|
|
|
327 |
* @return void
|
|
|
328 |
*/
|
|
|
329 |
protected function scsi()
|
|
|
330 |
{
|
|
|
331 |
foreach ($this->readdmesg() as $line) {
|
|
|
332 |
if (preg_match($this->_SCSIRegExp1, $line, $ar_buf)) {
|
|
|
333 |
$dev = new HWDevice();
|
|
|
334 |
$dev->setName($ar_buf[1].": ".trim($ar_buf[2]));
|
|
|
335 |
$this->sys->setScsiDevices($dev);
|
|
|
336 |
} elseif (preg_match($this->_SCSIRegExp2, $line, $ar_buf)) {
|
|
|
337 |
/* duplication security */
|
|
|
338 |
$notwas = true;
|
|
|
339 |
foreach ($this->sys->getScsiDevices() as $finddev) {
|
|
|
340 |
if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
|
|
|
341 |
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
|
|
|
342 |
if (isset($ar_buf[3]) && ($ar_buf[3]==="G")) {
|
|
|
343 |
$finddev->setCapacity($ar_buf[2] * 1024 * 1024 * 1024);
|
|
|
344 |
} else {
|
|
|
345 |
$finddev->setCapacity($ar_buf[2] * 1024 * 1024);
|
|
|
346 |
}
|
|
|
347 |
}
|
|
|
348 |
$notwas = false;
|
|
|
349 |
break;
|
|
|
350 |
}
|
|
|
351 |
}
|
|
|
352 |
if ($notwas) {
|
|
|
353 |
$dev = new HWDevice();
|
|
|
354 |
$dev->setName($ar_buf[1]);
|
|
|
355 |
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
|
|
|
356 |
if (isset($ar_buf[3]) && ($ar_buf[3]==="G")) {
|
|
|
357 |
$dev->setCapacity($ar_buf[2] * 1024 * 1024 * 1024);
|
|
|
358 |
} else {
|
|
|
359 |
$dev->setCapacity($ar_buf[2] * 1024 * 1024);
|
|
|
360 |
}
|
|
|
361 |
}
|
|
|
362 |
$this->sys->setScsiDevices($dev);
|
|
|
363 |
}
|
|
|
364 |
} elseif (preg_match($this->_SCSIRegExp3, $line, $ar_buf)) {
|
|
|
365 |
/* duplication security */
|
|
|
366 |
$notwas = true;
|
|
|
367 |
foreach ($this->sys->getScsiDevices() as $finddev) {
|
|
|
368 |
if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
|
|
|
369 |
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
|
|
|
370 |
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
|
|
|
371 |
$finddev->setSerial(trim($ar_buf[2]));
|
|
|
372 |
}
|
|
|
373 |
$notwas = false;
|
|
|
374 |
break;
|
|
|
375 |
}
|
|
|
376 |
}
|
|
|
377 |
if ($notwas) {
|
|
|
378 |
$dev = new HWDevice();
|
|
|
379 |
$dev->setName($ar_buf[1]);
|
|
|
380 |
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
|
|
|
381 |
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
|
|
|
382 |
$dev->setSerial(trim($ar_buf[2]));
|
|
|
383 |
}
|
|
|
384 |
$this->sys->setScsiDevices($dev);
|
|
|
385 |
}
|
|
|
386 |
}
|
|
|
387 |
}
|
|
|
388 |
/* cleaning */
|
|
|
389 |
foreach ($this->sys->getScsiDevices() as $finddev) {
|
|
|
390 |
if (strpos($finddev->getName(), ': ') !== false)
|
|
|
391 |
$finddev->setName(substr(strstr($finddev->getName(), ': '), 2));
|
|
|
392 |
}
|
|
|
393 |
}
|
|
|
394 |
|
|
|
395 |
/**
|
|
|
396 |
* parsing the output of pciconf command
|
|
|
397 |
*
|
|
|
398 |
* @return Array
|
|
|
399 |
*/
|
|
|
400 |
protected function pciconf()
|
|
|
401 |
{
|
|
|
402 |
$arrResults = array();
|
|
|
403 |
$intS = 0;
|
|
|
404 |
if (CommonFunctions::executeProgram("pciconf", "-lv", $strBuf, PSI_DEBUG)) {
|
|
|
405 |
$arrTemp = array();
|
|
|
406 |
$arrBlocks = preg_split("/\n\S/", $strBuf, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
407 |
foreach ($arrBlocks as $strBlock) {
|
|
|
408 |
$arrLines = preg_split("/\n/", $strBlock, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
409 |
$vend = null;
|
|
|
410 |
foreach ($arrLines as $strLine) {
|
|
|
411 |
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)) {
|
|
|
412 |
$arrTemp[$intS] = 'Class '.$arrParts[1].': Device '.$arrParts[3].':'.$arrParts[2];
|
|
|
413 |
$vend = '';
|
|
|
414 |
} elseif (preg_match("/(.*) = '(.*)'/", $strLine, $arrParts)) {
|
|
|
415 |
if (trim($arrParts[1]) == "vendor") {
|
|
|
416 |
$vend = trim($arrParts[2]);
|
|
|
417 |
} elseif (trim($arrParts[1]) == "device") {
|
|
|
418 |
if (($vend !== null) && ($vend !== '')) {
|
|
|
419 |
$arrTemp[$intS] = $vend." - ".trim($arrParts[2]);
|
|
|
420 |
} else {
|
|
|
421 |
$arrTemp[$intS] = trim($arrParts[2]);
|
|
|
422 |
$vend = '';
|
|
|
423 |
}
|
|
|
424 |
}
|
|
|
425 |
}
|
|
|
426 |
}
|
|
|
427 |
if ($vend !== null) {
|
|
|
428 |
$intS++;
|
|
|
429 |
}
|
|
|
430 |
}
|
|
|
431 |
foreach ($arrTemp as $name) {
|
|
|
432 |
$dev = new HWDevice();
|
|
|
433 |
$dev->setName($name);
|
|
|
434 |
$arrResults[] = $dev;
|
|
|
435 |
}
|
|
|
436 |
}
|
|
|
437 |
|
|
|
438 |
return $arrResults;
|
|
|
439 |
}
|
|
|
440 |
|
|
|
441 |
/**
|
|
|
442 |
* PCI devices
|
|
|
443 |
* get the pci device information out of dmesg
|
|
|
444 |
*
|
|
|
445 |
* @return void
|
|
|
446 |
*/
|
|
|
447 |
protected function pci()
|
|
|
448 |
{
|
|
|
449 |
if ((!$results = Parser::lspci(false)) && (!$results = $this->pciconf())) {
|
|
|
450 |
foreach ($this->readdmesg() as $line) {
|
|
|
451 |
if (preg_match($this->_PCIRegExp1, $line, $ar_buf)) {
|
|
|
452 |
$dev = new HWDevice();
|
|
|
453 |
$dev->setName($ar_buf[1].": ".$ar_buf[2]);
|
|
|
454 |
$results[] = $dev;
|
|
|
455 |
} elseif (preg_match($this->_PCIRegExp2, $line, $ar_buf)) {
|
|
|
456 |
$dev = new HWDevice();
|
|
|
457 |
$dev->setName($ar_buf[1].": ".$ar_buf[2]);
|
|
|
458 |
$results[] = $dev;
|
|
|
459 |
}
|
|
|
460 |
}
|
|
|
461 |
}
|
|
|
462 |
foreach ($results as $dev) {
|
|
|
463 |
$this->sys->setPciDevices($dev);
|
|
|
464 |
}
|
|
|
465 |
}
|
|
|
466 |
|
|
|
467 |
/**
|
|
|
468 |
* IDE devices
|
|
|
469 |
* get the ide device information out of dmesg
|
|
|
470 |
*
|
|
|
471 |
* @return void
|
|
|
472 |
*/
|
|
|
473 |
protected function ide()
|
|
|
474 |
{
|
|
|
475 |
foreach ($this->readdmesg() as $line) {
|
|
|
476 |
if (preg_match('/^(ad[0-9]+): (.*)MB <(.*)> (.*) (.*)/', $line, $ar_buf)) {
|
|
|
477 |
$dev = new HWDevice();
|
|
|
478 |
$dev->setName($ar_buf[1].": ".trim($ar_buf[3]));
|
|
|
479 |
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
|
|
|
480 |
$dev->setCapacity($ar_buf[2] * 1024 * 1024);
|
|
|
481 |
}
|
|
|
482 |
$this->sys->setIdeDevices($dev);
|
|
|
483 |
} elseif (preg_match('/^(acd[0-9]+): (.*) <(.*)> (.*)/', $line, $ar_buf)) {
|
|
|
484 |
$dev = new HWDevice();
|
|
|
485 |
$dev->setName($ar_buf[1].": ".trim($ar_buf[3]));
|
|
|
486 |
$this->sys->setIdeDevices($dev);
|
|
|
487 |
} elseif (preg_match('/^(ada[0-9]+): <(.*)> (.*)/', $line, $ar_buf)) {
|
|
|
488 |
$dev = new HWDevice();
|
|
|
489 |
$dev->setName($ar_buf[1].": ".trim($ar_buf[2]));
|
|
|
490 |
$this->sys->setIdeDevices($dev);
|
|
|
491 |
} elseif (preg_match('/^(ada[0-9]+): (.*)MB \((.*)\)/', $line, $ar_buf)) {
|
|
|
492 |
/* duplication security */
|
|
|
493 |
$notwas = true;
|
|
|
494 |
foreach ($this->sys->getIdeDevices() as $finddev) {
|
|
|
495 |
if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
|
|
|
496 |
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
|
|
|
497 |
$finddev->setCapacity($ar_buf[2] * 1024 * 1024);
|
|
|
498 |
}
|
|
|
499 |
$notwas = false;
|
|
|
500 |
break;
|
|
|
501 |
}
|
|
|
502 |
}
|
|
|
503 |
if ($notwas) {
|
|
|
504 |
$dev = new HWDevice();
|
|
|
505 |
$dev->setName($ar_buf[1]);
|
|
|
506 |
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
|
|
|
507 |
$dev->setCapacity($ar_buf[2] * 1024 * 1024);
|
|
|
508 |
}
|
|
|
509 |
$this->sys->setIdeDevices($dev);
|
|
|
510 |
}
|
|
|
511 |
} elseif (preg_match('/^(ada[0-9]+): Serial Number (.*)/', $line, $ar_buf)) {
|
|
|
512 |
/* duplication security */
|
|
|
513 |
$notwas = true;
|
|
|
514 |
foreach ($this->sys->getIdeDevices() as $finddev) {
|
|
|
515 |
if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
|
|
|
516 |
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
|
|
|
517 |
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
|
|
|
518 |
$finddev->setSerial(trim($ar_buf[2]));
|
|
|
519 |
}
|
|
|
520 |
$notwas = false;
|
|
|
521 |
break;
|
|
|
522 |
}
|
|
|
523 |
}
|
|
|
524 |
if ($notwas) {
|
|
|
525 |
$dev = new HWDevice();
|
|
|
526 |
$dev->setName($ar_buf[1]);
|
|
|
527 |
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
|
|
|
528 |
&& defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
|
|
|
529 |
$finddev->setSerial(trim($ar_buf[2]));
|
|
|
530 |
}
|
|
|
531 |
$this->sys->setIdeDevices($dev);
|
|
|
532 |
}
|
|
|
533 |
}
|
|
|
534 |
}
|
|
|
535 |
/* cleaning */
|
|
|
536 |
foreach ($this->sys->getIdeDevices() as $finddev) {
|
|
|
537 |
if (strpos($finddev->getName(), ': ') !== false)
|
|
|
538 |
$finddev->setName(substr(strstr($finddev->getName(), ': '), 2));
|
|
|
539 |
}
|
|
|
540 |
}
|
|
|
541 |
|
|
|
542 |
/**
|
|
|
543 |
* Physical memory information and Swap Space information
|
|
|
544 |
*
|
|
|
545 |
* @return void
|
|
|
546 |
*/
|
|
|
547 |
protected function memory()
|
|
|
548 |
{
|
|
|
549 |
if (PSI_OS == 'FreeBSD' || PSI_OS == 'OpenBSD') {
|
|
|
550 |
// vmstat on fbsd 4.4 or greater outputs kbytes not hw.pagesize
|
|
|
551 |
// I should probably add some version checking here, but for now
|
|
|
552 |
// we only support fbsd 4.4
|
|
|
553 |
$pagesize = 1024;
|
|
|
554 |
} else {
|
|
|
555 |
$pagesize = $this->grabkey('hw.pagesize');
|
|
|
556 |
}
|
|
|
557 |
if (CommonFunctions::executeProgram('vmstat', '', $vmstat, PSI_DEBUG)) {
|
|
|
558 |
$lines = preg_split("/\n/", $vmstat, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
559 |
$ar_buf = preg_split("/\s+/", trim($lines[2]), 19);
|
|
|
560 |
if (PSI_OS == 'NetBSD' || PSI_OS == 'DragonFly') {
|
|
|
561 |
$this->sys->setMemFree($ar_buf[4] * 1024);
|
|
|
562 |
} else {
|
|
|
563 |
$this->sys->setMemFree($ar_buf[4] * $pagesize);
|
|
|
564 |
}
|
|
|
565 |
$this->sys->setMemTotal($this->grabkey('hw.physmem'));
|
|
|
566 |
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
|
|
|
567 |
|
|
|
568 |
if (((PSI_OS == 'OpenBSD' || PSI_OS == 'NetBSD') && CommonFunctions::executeProgram('swapctl', '-l -k', $swapstat, PSI_DEBUG)) || CommonFunctions::executeProgram('swapinfo', '-k', $swapstat, PSI_DEBUG)) {
|
|
|
569 |
$lines = preg_split("/\n/", $swapstat, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
570 |
foreach ($lines as $line) {
|
|
|
571 |
$ar_buf = preg_split("/\s+/", $line, 6);
|
|
|
572 |
if (($ar_buf[0] != 'Total') && ($ar_buf[0] != 'Device')) {
|
|
|
573 |
$dev = new DiskDevice();
|
|
|
574 |
$dev->setMountPoint($ar_buf[0]);
|
|
|
575 |
$dev->setName("SWAP");
|
|
|
576 |
$dev->setFsType('swap');
|
|
|
577 |
$dev->setTotal($ar_buf[1] * 1024);
|
|
|
578 |
$dev->setUsed($ar_buf[2] * 1024);
|
|
|
579 |
$dev->setFree($dev->getTotal() - $dev->getUsed());
|
|
|
580 |
$this->sys->setSwapDevices($dev);
|
|
|
581 |
}
|
|
|
582 |
}
|
|
|
583 |
}
|
|
|
584 |
}
|
|
|
585 |
}
|
|
|
586 |
|
|
|
587 |
/**
|
|
|
588 |
* USB devices
|
|
|
589 |
* get the ide device information out of dmesg
|
|
|
590 |
*
|
|
|
591 |
* @return void
|
|
|
592 |
*/
|
|
|
593 |
protected function usb()
|
|
|
594 |
{
|
|
|
595 |
foreach ($this->readdmesg() as $line) {
|
|
|
596 |
// if (preg_match('/^(ugen[0-9\.]+): <(.*)> (.*) (.*)/', $line, $ar_buf)) {
|
|
|
597 |
// $dev->setName($ar_buf[1].": ".$ar_buf[2]);
|
|
|
598 |
if (preg_match('/^(u[a-z]+[0-9]+): <([^,]*)(.*)> on (usbus[0-9]+)/', $line, $ar_buf)) {
|
|
|
599 |
$dev = new HWDevice();
|
|
|
600 |
$dev->setName($ar_buf[2]);
|
|
|
601 |
$this->sys->setUSBDevices($dev);
|
|
|
602 |
}
|
|
|
603 |
}
|
|
|
604 |
}
|
|
|
605 |
|
|
|
606 |
/**
|
|
|
607 |
* filesystem information
|
|
|
608 |
*
|
|
|
609 |
* @return void
|
|
|
610 |
*/
|
|
|
611 |
protected function filesystems()
|
|
|
612 |
{
|
|
|
613 |
$arrResult = Parser::df();
|
|
|
614 |
foreach ($arrResult as $dev) {
|
|
|
615 |
$this->sys->setDiskDevices($dev);
|
|
|
616 |
}
|
|
|
617 |
}
|
|
|
618 |
|
|
|
619 |
/**
|
|
|
620 |
* Distribution
|
|
|
621 |
*
|
|
|
622 |
* @return void
|
|
|
623 |
*/
|
|
|
624 |
protected function distro()
|
|
|
625 |
{
|
|
|
626 |
if (CommonFunctions::executeProgram('uname', '-s', $result, PSI_DEBUG)) {
|
|
|
627 |
$this->sys->setDistribution($result);
|
|
|
628 |
}
|
|
|
629 |
}
|
|
|
630 |
|
|
|
631 |
/**
|
|
|
632 |
* get the information
|
|
|
633 |
*
|
|
|
634 |
* @see PSI_Interface_OS::build()
|
|
|
635 |
*
|
|
|
636 |
* @return Void
|
|
|
637 |
*/
|
|
|
638 |
public function build()
|
|
|
639 |
{
|
|
|
640 |
if (!$this->blockname || $this->blockname==='vitals') {
|
|
|
641 |
$this->distro();
|
|
|
642 |
$this->hostname();
|
|
|
643 |
$this->kernel();
|
|
|
644 |
$this->_users();
|
|
|
645 |
$this->loadavg();
|
|
|
646 |
}
|
|
|
647 |
if (!$this->blockname || $this->blockname==='hardware') {
|
|
|
648 |
$this->cpuinfo();
|
|
|
649 |
$this->pci();
|
|
|
650 |
$this->ide();
|
|
|
651 |
$this->scsi();
|
|
|
652 |
$this->usb();
|
|
|
653 |
}
|
|
|
654 |
if (!$this->blockname || $this->blockname==='memory') {
|
|
|
655 |
$this->memory();
|
|
|
656 |
}
|
|
|
657 |
if (!$this->blockname || $this->blockname==='filesystem') {
|
|
|
658 |
$this->filesystems();
|
|
|
659 |
}
|
|
|
660 |
}
|
|
|
661 |
}
|