| 2770 |
rexy |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* DragonFly System Class
|
|
|
4 |
*
|
|
|
5 |
* PHP version 5
|
|
|
6 |
*
|
|
|
7 |
* @category PHP
|
|
|
8 |
* @package PSI DragonFly 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.DragonFly.inc.php 287 2009-06-26 12:11:59Z bigmichi1 $
|
|
|
13 |
* @link http://phpsysinfo.sourceforge.net
|
|
|
14 |
*/
|
|
|
15 |
/**
|
|
|
16 |
* DragonFly sysinfo class
|
|
|
17 |
* get all the required information from DragonFly system
|
|
|
18 |
*
|
|
|
19 |
* @category PHP
|
|
|
20 |
* @package PSI DragonFly OS class
|
|
|
21 |
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
|
|
|
22 |
* @copyright 2009 phpSysInfo
|
|
|
23 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
|
|
|
24 |
* @version Release: 3.0
|
|
|
25 |
* @link http://phpsysinfo.sourceforge.net
|
|
|
26 |
*/
|
|
|
27 |
class DragonFly extends BSDCommon
|
|
|
28 |
{
|
|
|
29 |
/**
|
|
|
30 |
* define the regexp for log parser
|
|
|
31 |
*/
|
|
|
32 |
public function __construct($blockname = false)
|
|
|
33 |
{
|
|
|
34 |
parent::__construct($blockname);
|
|
|
35 |
$this->setCPURegExp1("/^cpu(.*)\, (.*) MHz/");
|
|
|
36 |
$this->setCPURegExp2("/^(.*) at scsibus.*: <(.*)> .*/");
|
|
|
37 |
$this->setSCSIRegExp2("/^(da[0-9]+): (.*)MB /");
|
|
|
38 |
$this->setPCIRegExp1("/(.*): <(.*)>(.*) (pci|legacypci)[0-9]+$/");
|
|
|
39 |
$this->setPCIRegExp2("/(.*): <(.*)>.* at [0-9\.]+$/");
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* UpTime
|
|
|
44 |
* time the system is running
|
|
|
45 |
*
|
|
|
46 |
* @return void
|
|
|
47 |
*/
|
|
|
48 |
private function _uptime()
|
|
|
49 |
{
|
|
|
50 |
$a = $this->grabkey('kern.boottime');
|
|
|
51 |
preg_match("/sec = ([0-9]+)/", $a, $buf);
|
|
|
52 |
$this->sys->setUptime(time() - $buf[1]);
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
/**
|
|
|
56 |
* get network information
|
|
|
57 |
*
|
|
|
58 |
* @return void
|
|
|
59 |
*/
|
|
|
60 |
private function _network()
|
|
|
61 |
{
|
|
|
62 |
CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_b);
|
|
|
63 |
CommonFunctions::executeProgram('netstat', '-ndi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_n);
|
|
|
64 |
$lines_b = preg_split("/\n/", $netstat_b, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
65 |
$lines_n = preg_split("/\n/", $netstat_n, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
66 |
for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) {
|
|
|
67 |
$ar_buf_b = preg_split("/\s+/", $lines_b[$i]);
|
|
|
68 |
$ar_buf_n = preg_split("/\s+/", $lines_n[$i]);
|
|
|
69 |
if (!empty($ar_buf_b[0]) && (!empty($ar_buf_n[5]) || ($ar_buf_n[5] === "0"))) {
|
|
|
70 |
$dev = new NetDevice();
|
|
|
71 |
$dev->setName($ar_buf_b[0]);
|
|
|
72 |
$dev->setTxBytes($ar_buf_b[8]);
|
|
|
73 |
$dev->setRxBytes($ar_buf_b[5]);
|
|
|
74 |
$dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]);
|
|
|
75 |
$dev->setDrops($ar_buf_n[8]);
|
|
|
76 |
$this->sys->setNetDevices($dev);
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
/**
|
|
|
82 |
* get the ide information
|
|
|
83 |
*
|
|
|
84 |
* @return void
|
|
|
85 |
*/
|
|
|
86 |
protected function ide()
|
|
|
87 |
{
|
|
|
88 |
foreach ($this->readdmesg() as $line) {
|
|
|
89 |
if (preg_match('/^(.*): (.*) <(.*)> at (ata[0-9]+\-(.*)) (.*)/', $line, $ar_buf)) {
|
|
|
90 |
$dev = new HWDevice();
|
|
|
91 |
$dev->setName($ar_buf[1]);
|
|
|
92 |
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS && !preg_match("/^acd[0-9]+(.*)/", $ar_buf[1])) {
|
|
|
93 |
$dev->setCapacity($ar_buf[2] * 1024 * 1024);
|
|
|
94 |
}
|
|
|
95 |
$this->sys->setIdeDevices($dev);
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
/**
|
|
|
101 |
* get icon name
|
|
|
102 |
*
|
|
|
103 |
* @return void
|
|
|
104 |
*/
|
|
|
105 |
private function _distroicon()
|
|
|
106 |
{
|
|
|
107 |
$this->sys->setDistributionIcon('DragonFly.png');
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
/**
|
|
|
111 |
* Processes
|
|
|
112 |
*
|
|
|
113 |
* @return void
|
|
|
114 |
*/
|
|
|
115 |
protected function _processes()
|
|
|
116 |
{
|
|
|
117 |
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
|
|
|
118 |
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
119 |
$processes['*'] = 0;
|
|
|
120 |
foreach ($lines as $line) {
|
|
|
121 |
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
|
|
|
122 |
$processes['*']++;
|
|
|
123 |
$state = $ar_buf[1];
|
|
|
124 |
if ($state == 'I') $state = 'S'; //linux format
|
|
|
125 |
if (isset($processes[$state])) {
|
|
|
126 |
$processes[$state]++;
|
|
|
127 |
} else {
|
|
|
128 |
$processes[$state] = 1;
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
}
|
|
|
132 |
if ($processes['*'] > 0) {
|
|
|
133 |
$this->sys->setProcesses($processes);
|
|
|
134 |
}
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
/**
|
|
|
139 |
* get the information
|
|
|
140 |
*
|
|
|
141 |
* @see BSDCommon::build()
|
|
|
142 |
*
|
|
|
143 |
* @return Void
|
|
|
144 |
*/
|
|
|
145 |
public function build()
|
|
|
146 |
{
|
|
|
147 |
parent::build();
|
|
|
148 |
if (!$this->blockname || $this->blockname==='vitals') {
|
|
|
149 |
$this->_distroicon();
|
|
|
150 |
$this->_uptime();
|
|
|
151 |
$this->_processes();
|
|
|
152 |
}
|
|
|
153 |
if (!$this->blockname || $this->blockname==='network') {
|
|
|
154 |
$this->_network();
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
}
|