Subversion Repositories ALCASAR

Rev

Rev 2770 | Rev 3037 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2770 Rev 2976
Line 173... Line 173...
173
     * @return array
173
     * @return array
174
     */
174
     */
175
    protected function readdmesg()
175
    protected function readdmesg()
176
    {
176
    {
177
        if ($this->_dmesg === null) {
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
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);
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);
180
                $this->_dmesg = preg_split("/\n/", $parts[count($parts) - 1], -1, PREG_SPLIT_NO_EMPTY);
181
            } else {
181
            } else {
182
                $this->_dmesg = array();
182
                $this->_dmesg = array();
183
            }
183
            }
Line 245... Line 245...
245
    {
245
    {
246
        $s = $this->grabkey('vm.loadavg');
246
        $s = $this->grabkey('vm.loadavg');
247
        $s = preg_replace('/{ /', '', $s);
247
        $s = preg_replace('/{ /', '', $s);
248
        $s = preg_replace('/ }/', '', $s);
248
        $s = preg_replace('/ }/', '', $s);
249
        $this->sys->setLoad($s);
249
        $this->sys->setLoad($s);
-
 
250
        if (PSI_LOAD_BAR) {
250
        if (PSI_LOAD_BAR && (PSI_OS != "Darwin")) {
251
            if (PSI_OS != 'Darwin') {
251
            if ($fd = $this->grabkey('kern.cp_time')) {
252
                if ($fd = $this->grabkey('kern.cp_time')) {
252
                // Find out the CPU load
253
                    // Find out the CPU load
253
                // user + sys = load
254
                    // user + sys = load
254
                // total = total
255
                    // total = total
255
                preg_match($this->_CPURegExp2, $fd, $res);
256
                    if (preg_match($this->_CPURegExp2, $fd, $res) && (sizeof($res) > 4)) {
256
                $load = $res[2] + $res[3] + $res[4]; // cpu.user + cpu.sys
257
                        $load = $res[2] + $res[3] + $res[4]; // cpu.user + cpu.sys
257
                $total = $res[2] + $res[3] + $res[4] + $res[5]; // cpu.total
258
                        $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
                        // we need a second value, wait 1 second befor getting (< 1 second no good value will occour)
259
                sleep(1);
260
                        sleep(1);
260
                $fd = $this->grabkey('kern.cp_time');
261
                        $fd = $this->grabkey('kern.cp_time');
261
                preg_match($this->_CPURegExp2, $fd, $res);
262
                        if (preg_match($this->_CPURegExp2, $fd, $res) && (sizeof($res) > 4)) {
262
                $load2 = $res[2] + $res[3] + $res[4];
263
                            $load2 = $res[2] + $res[3] + $res[4];
263
                $total2 = $res[2] + $res[3] + $res[4] + $res[5];
264
                            $total2 = $res[2] + $res[3] + $res[4] + $res[5];
264
                $this->sys->setLoadPercent((100 * ($load2 - $load)) / ($total2 - $total));
265
                            $this->sys->setLoadPercent((100 * ($load2 - $load)) / ($total2 - $total));
-
 
266
                        }
-
 
267
                    }
-
 
268
                }
-
 
269
            } else {
-
 
270
                $ncpu = $this->grabkey('hw.ncpu');
-
 
271
                if (!is_null($ncpu) && (trim($ncpu) != "") && ($ncpu >= 1) && CommonFunctions::executeProgram('ps', "-A -o %cpu", $pstable, false) && !empty($pstable)) {
-
 
272
                    $pslines = preg_split("/\n/", $pstable, -1, PREG_SPLIT_NO_EMPTY);
-
 
273
                    if (!empty($pslines) && (count($pslines)>1) && (trim($pslines[0])==="%CPU")) {
-
 
274
                        array_shift($pslines);
-
 
275
                        $sum = 0;
-
 
276
                        foreach ($pslines as $psline) {
-
 
277
                            $sum+=trim($psline);
-
 
278
                        }
-
 
279
                        $this->sys->setLoadPercent(min($sum/$ncpu, 100));
-
 
280
                    }
-
 
281
                }
265
            }
282
            }
266
        }
283
        }
267
    }
284
    }
268
 
285
 
269
    /**
286
    /**
Line 273... Line 290...
273
     */
290
     */
274
    protected function cpuinfo()
291
    protected function cpuinfo()
275
    {
292
    {
276
        $dev = new CpuDevice();
293
        $dev = new CpuDevice();
277
 
294
 
278
        if (PSI_OS == "NetBSD") {
295
        if (PSI_OS == 'NetBSD') {
279
            if ($model = $this->grabkey('machdep.cpu_brand')) {
296
            if ($model = $this->grabkey('machdep.cpu_brand')) {
280
               $dev->setModel($model);
297
               $dev->setModel($model);
281
            }
298
            }
282
            if ($cpuspeed = $this->grabkey('machdep.tsc_freq')) {
299
            if ($cpuspeed = $this->grabkey('machdep.tsc_freq')) {
283
               $dev->setCpuSpeed(round($cpuspeed / 1000000));
300
               $dev->setCpuSpeed(round($cpuspeed / 1000000));
Line 288... Line 305...
288
            $dev->setModel($this->grabkey('hw.model'));
305
            $dev->setModel($this->grabkey('hw.model'));
289
        }
306
        }
290
        $notwas = true;
307
        $notwas = true;
291
        foreach ($this->readdmesg() as $line) {
308
        foreach ($this->readdmesg() as $line) {
292
            if ($notwas) {
309
            if ($notwas) {
293
               if (preg_match($this->_CPURegExp1, $line, $ar_buf)) {
310
               if (preg_match($this->_CPURegExp1, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
294
                    if ($dev->getCpuSpeed() === 0) {
311
                    if ($dev->getCpuSpeed() === 0) {
295
                        $dev->setCpuSpeed(round($ar_buf[2]));
312
                        $dev->setCpuSpeed(round($ar_buf[2]));
296
                    }
313
                    }
297
                    $notwas = false;
314
                    $notwas = false;
298
                }
315
                }
Line 327... Line 344...
327
     * @return void
344
     * @return void
328
     */
345
     */
329
    protected function scsi()
346
    protected function scsi()
330
    {
347
    {
331
        foreach ($this->readdmesg() as $line) {
348
        foreach ($this->readdmesg() as $line) {
332
            if (preg_match($this->_SCSIRegExp1, $line, $ar_buf)) {
349
            if (preg_match($this->_SCSIRegExp1, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
333
                $dev = new HWDevice();
350
                $dev = new HWDevice();
334
                $dev->setName($ar_buf[1].": ".trim($ar_buf[2]));
351
                $dev->setName($ar_buf[1].": ".trim($ar_buf[2]));
335
                $this->sys->setScsiDevices($dev);
352
                $this->sys->setScsiDevices($dev);
336
            } elseif (preg_match($this->_SCSIRegExp2, $line, $ar_buf)) {
353
            } elseif (preg_match($this->_SCSIRegExp2, $line, $ar_buf) && (sizeof($ar_buf) > 1)) {
337
                /* duplication security */
354
                /* duplication security */
338
                $notwas = true;
355
                $notwas = true;
339
                foreach ($this->sys->getScsiDevices() as $finddev) {
356
                foreach ($this->sys->getScsiDevices() as $finddev) {
340
                    if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
357
                    if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
341
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
358
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
342
                            if (isset($ar_buf[3]) && ($ar_buf[3]==="G")) {
359
                            if (isset($ar_buf[3]) && ($ar_buf[3]==="G")) {
343
                                $finddev->setCapacity($ar_buf[2] * 1024 * 1024 * 1024);
360
                                $finddev->setCapacity($ar_buf[2] * 1024 * 1024 * 1024);
344
                            } else {
361
                            } elseif (isset($ar_buf[2])) {
345
                                $finddev->setCapacity($ar_buf[2] * 1024 * 1024);
362
                                $finddev->setCapacity($ar_buf[2] * 1024 * 1024);
346
                            }
363
                            }
347
                        }
364
                        }
348
                        $notwas = false;
365
                        $notwas = false;
349
                        break;
366
                        break;
Line 353... Line 370...
353
                    $dev = new HWDevice();
370
                    $dev = new HWDevice();
354
                    $dev->setName($ar_buf[1]);
371
                    $dev->setName($ar_buf[1]);
355
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
372
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
356
                        if (isset($ar_buf[3]) && ($ar_buf[3]==="G")) {
373
                        if (isset($ar_buf[3]) && ($ar_buf[3]==="G")) {
357
                                $dev->setCapacity($ar_buf[2] * 1024 * 1024 * 1024);
374
                                $dev->setCapacity($ar_buf[2] * 1024 * 1024 * 1024);
358
                            } else {
375
                            } elseif (isset($ar_buf[2])) {
359
                                $dev->setCapacity($ar_buf[2] * 1024 * 1024);
376
                                $dev->setCapacity($ar_buf[2] * 1024 * 1024);
360
                            }
377
                            }
361
                    }
378
                    }
362
                    $this->sys->setScsiDevices($dev);
379
                    $this->sys->setScsiDevices($dev);
363
                }
380
                }
364
            } elseif (preg_match($this->_SCSIRegExp3, $line, $ar_buf)) {
381
            } elseif (preg_match($this->_SCSIRegExp3, $line, $ar_buf) && (sizeof($ar_buf) > 1)) {
365
                /* duplication security */
382
                /* duplication security */
366
                $notwas = true;
383
                $notwas = true;
367
                foreach ($this->sys->getScsiDevices() as $finddev) {
384
                foreach ($this->sys->getScsiDevices() as $finddev) {
368
                    if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
385
                    if ($notwas && (substr($finddev->getName(), 0, strpos($finddev->getName(), ': ')) == $ar_buf[1])) {
369
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
386
                        if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
370
                           && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
387
                           && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
371
                            $finddev->setSerial(trim($ar_buf[2]));
388
                            if (isset($ar_buf[2])) $finddev->setSerial(trim($ar_buf[2]));
372
                        }
389
                        }
373
                        $notwas = false;
390
                        $notwas = false;
374
                        break;
391
                        break;
375
                    }
392
                    }
376
                }
393
                }
377
                if ($notwas) {
394
                if ($notwas) {
378
                    $dev = new HWDevice();
395
                    $dev = new HWDevice();
379
                    $dev->setName($ar_buf[1]);
396
                    $dev->setName($ar_buf[1]);
380
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
397
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS
381
                       && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
398
                       && defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
382
                        $dev->setSerial(trim($ar_buf[2]));
399
                        if (isset($ar_buf[2])) $dev->setSerial(trim($ar_buf[2]));
383
                    }
400
                    }
384
                    $this->sys->setScsiDevices($dev);
401
                    $this->sys->setScsiDevices($dev);
385
                }
402
                }
386
            }
403
            }
387
        }
404
        }
Line 446... Line 463...
446
     */
463
     */
447
    protected function pci()
464
    protected function pci()
448
    {
465
    {
449
        if ((!$results = Parser::lspci(false)) && (!$results = $this->pciconf())) {
466
        if ((!$results = Parser::lspci(false)) && (!$results = $this->pciconf())) {
450
            foreach ($this->readdmesg() as $line) {
467
            foreach ($this->readdmesg() as $line) {
451
                if (preg_match($this->_PCIRegExp1, $line, $ar_buf)) {
468
                if (preg_match($this->_PCIRegExp1, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
452
                    $dev = new HWDevice();
469
                    $dev = new HWDevice();
453
                    $dev->setName($ar_buf[1].": ".$ar_buf[2]);
470
                    $dev->setName($ar_buf[1].": ".$ar_buf[2]);
454
                    $results[] = $dev;
471
                    $results[] = $dev;
455
                } elseif (preg_match($this->_PCIRegExp2, $line, $ar_buf)) {
472
                } elseif (preg_match($this->_PCIRegExp2, $line, $ar_buf) && (sizeof($ar_buf) > 2)) {
456
                    $dev = new HWDevice();
473
                    $dev = new HWDevice();
457
                    $dev->setName($ar_buf[1].": ".$ar_buf[2]);
474
                    $dev->setName($ar_buf[1].": ".$ar_buf[2]);
458
                    $results[] = $dev;
475
                    $results[] = $dev;
459
                }
476
                }
460
            }
477
            }
Line 590... Line 607...
590
     *
607
     *
591
     * @return void
608
     * @return void
592
     */
609
     */
593
    protected function usb()
610
    protected function usb()
594
    {
611
    {
-
 
612
        $notwas = true;
-
 
613
        if ((PSI_OS == 'FreeBSD') && CommonFunctions::executeProgram('usbconfig', '', $bufr, false)) {
-
 
614
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
-
 
615
            foreach ($lines as $line) {
-
 
616
                if (preg_match('/^(ugen[0-9]+\.[0-9]+): <([^,]*)(.*)> at (usbus[0-9]+)/', $line, $ar_buf)) {
-
 
617
                    $notwas = false;
-
 
618
                    $dev = new HWDevice();
-
 
619
                    $dev->setName($ar_buf[2]);
-
 
620
                    $this->sys->setUSBDevices($dev);
-
 
621
                }
-
 
622
            }
-
 
623
        }
595
        foreach ($this->readdmesg() as $line) {
624
        if ($notwas) foreach ($this->readdmesg() as $line) {
596
//            if (preg_match('/^(ugen[0-9\.]+): <(.*)> (.*) (.*)/', $line, $ar_buf)) {
625
//            if (preg_match('/^(ugen[0-9\.]+): <(.*)> (.*) (.*)/', $line, $ar_buf)) {
597
//                    $dev->setName($ar_buf[1].": ".$ar_buf[2]);
626
//                    $dev->setName($ar_buf[1].": ".$ar_buf[2]);
598
            if (preg_match('/^(u[a-z]+[0-9]+): <([^,]*)(.*)> on (usbus[0-9]+)/', $line, $ar_buf)) {
627
            if (preg_match('/^(u[a-z]+[0-9]+): <([^,]*)(.*)> on (usbus[0-9]+)/', $line, $ar_buf)) {
599
                    $dev = new HWDevice();
628
                    $dev = new HWDevice();
600
                    $dev->setName($ar_buf[2]);
629
                    $dev->setName($ar_buf[2]);