Subversion Repositories ALCASAR

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
2770 rexy 1
<?php
2
/**
3
 * IBM AIX System Class
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PSI AIX OS class
9
 * @author    Krzysztof Paz (kpaz@gazeta.pl) based on HPUX of Michael Cramer <BigMichi1@users.sourceforge.net>
10
 * @copyright 2011 Krzysztof Paz
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.AIX.inc.php 287 2009-06-26 12:11:59Z Krzysztof Paz, IBM POLSKA
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
15
/**
16
* IBM AIX sysinfo class
17
* get all the required information from IBM AIX system
18
*
19
* @category  PHP
20
* @package   PSI AIX OS class
21
* @author    Krzysztof Paz (kpaz@gazeta.pl) based on Michael Cramer <BigMichi1@users.sourceforge.net>
22
* @copyright 2011 Krzysztof Paz
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 AIX extends OS
28
{
29
 
30
    private $_aixdata = array();
31
 
32
    /**
33
     * Virtual Host Name
34
     * @return void
35
     */
36
    private function _hostname()
37
    {
38
        /*   if (PSI_USE_VHOST === true) {
39
               if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
40
           } else {
41
               if (CommonFunctions::executeProgram('hostname', '', $ret)) {
42
                   $this->sys->setHostname($ret);
43
               }
44
           } */
45
        if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
46
 
47
    }
48
 
49
    /**
50
     * IBM AIX Version
51
     * @return void
52
     */
53
    private function _kernel()
54
    {
55
        if (CommonFunctions::executeProgram('oslevel', '', $ret1) && CommonFunctions::executeProgram('oslevel', '-s', $ret2)) {
56
            $this->sys->setKernel($ret1 . '   (' . $ret2 . ')');
57
        }
58
    }
59
 
60
    /**
61
     * UpTime
62
     * time the system is running
63
     * @return void
64
     */
65
    private function _uptime()
66
    {
67
        if (CommonFunctions::executeProgram('uptime', '', $buf)) {
68
            if (preg_match("/up (\d+) day[s]?,\s*(\d+):(\d+),/", $buf, $ar_buf)) {
69
                $min = $ar_buf[3];
70
                $hours = $ar_buf[2];
71
                $days = $ar_buf[1];
72
                $this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60);
73
            }
74
        }
75
    }
76
 
77
    /**
78
     * Processor Load
79
     * optionally create a loadbar
80
     * @return void
81
     */
82
    private function _loadavg()
83
    {
84
        if (CommonFunctions::executeProgram('uptime', '', $buf)) {
85
            if (preg_match("/average: (.*), (.*), (.*)$/", $buf, $ar_buf)) {
86
                $this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]);
87
            }
88
        }
89
    }
90
 
91
    /**
92
     * CPU information
93
     * All of the tags here are highly architecture dependant
94
     * @return void
95
     */
96
    private function _cpuinfo()
97
    {
98
        $ncpu = 0;
99
        $tcpu = "";
100
        $vcpu = "";
101
        $ccpu = "";
102
        $scpu = "";
103
        foreach ($this->readaixdata() as $line) {
104
            if (preg_match("/^Number Of Processors:\s+(\d+)/", $line, $ar_buf)) {
105
                $ncpu = $ar_buf[1];
106
            }
107
            if (preg_match("/^Processor Type:\s+(.+)/", $line, $ar_buf)) {
108
                $tcpu = $ar_buf[1];
109
            }
110
            if (preg_match("/^Processor Version:\s+(.+)/", $line, $ar_buf)) {
111
                $vcpu = $ar_buf[1];
112
            }
113
            if (preg_match("/^CPU Type:\s+(.+)/", $line, $ar_buf)) {
114
                $ccpu = $ar_buf[1];
115
            }
116
            if (preg_match("/^Processor Clock Speed:\s+(\d+)\s/", $line, $ar_buf)) {
117
                $scpu = $ar_buf[1];
118
            }
119
        }
120
        for ($i = 0; $i < $ncpu; $i++) {
121
            $dev = new CpuDevice();
122
            if (trim($tcpu) != "") {
123
                $cpu = trim($tcpu);
124
                if (trim($vcpu) != "") $cpu .= " ".trim($vcpu);
125
                if (trim($ccpu) != "") $cpu .= " ".trim($ccpu);
126
                $dev->setModel($cpu);
127
            }
128
            if (trim($scpu) != "") {
129
                $dev->setCpuSpeed(trim($scpu));
130
            }
131
            $this->sys->setCpus($dev);
132
        }
133
    }
134
 
135
    /**
136
     * PCI devices
137
     * @return void
138
     */
139
    private function _pci()
140
    {
141
        foreach ($this->readaixdata() as $line) {
142
            if (preg_match("/^[\*\+]\s\S+\s+\S+\s+(.*PCI.*)/", $line, $ar_buf)) {
143
                $dev = new HWDevice();
144
                $dev->setName(trim($ar_buf[1]));
145
                $this->sys->setPciDevices($dev);
146
            }
147
        }
148
    }
149
 
150
    /**
151
     * IDE devices
152
     * @return void
153
     */
154
    private function _ide()
155
    {
156
        foreach ($this->readaixdata() as $line) {
157
            if (preg_match("/^[\*\+]\s\S+\s+\S+\s+(.*IDE.*)/", $line, $ar_buf)) {
158
                $dev = new HWDevice();
159
                $dev->setName(trim($ar_buf[1]));
160
                $this->sys->setIdeDevices($dev);
161
            }
162
        }
163
    }
164
 
165
    /**
166
     * SCSI devices
167
     * @return void
168
     */
169
    private function _scsi()
170
    {
171
        foreach ($this->readaixdata() as $line) {
172
            if (preg_match("/^[\*\+]\s\S+\s+\S+\s+(.*SCSI.*)/", $line, $ar_buf)) {
173
                $dev = new HWDevice();
174
                $dev->setName(trim($ar_buf[1]));
175
                $this->sys->setScsiDevices($dev);
176
            }
177
        }
178
    }
179
 
180
    /**
181
     * USB devices
182
     * @return void
183
     */
184
    private function _usb()
185
    {
186
        foreach ($this->readaixdata() as $line) {
187
            if (preg_match("/^[\*\+]\s\S+\s+\S+\s+(.*USB.*)/", $line, $ar_buf)) {
188
                $dev = new HWDevice();
189
                $dev->setName(trim($ar_buf[1]));
190
                $this->sys->setUsbDevices($dev);
191
            }
192
        }
193
    }
194
 
195
    /**
196
     * Network devices
197
     * includes also rx/tx bytes
198
     * @return void
199
     */
200
    private function _network()
201
    {
202
        if (CommonFunctions::executeProgram('netstat', '-ni | tail -n +2', $netstat)) {
203
            $lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
204
            foreach ($lines as $line) {
205
                $ar_buf = preg_split("/\s+/", $line);
206
                if (! empty($ar_buf[0]) && ! empty($ar_buf[3])) {
207
                    $dev = new NetDevice();
208
                    $dev->setName($ar_buf[0]);
209
                    $dev->setRxBytes($ar_buf[4]);
210
                    $dev->setTxBytes($ar_buf[6]);
211
                    $dev->setErrors($ar_buf[5] + $ar_buf[7]);
212
                    //$dev->setDrops($ar_buf[8]);
213
                    $this->sys->setNetDevices($dev);
214
                }
215
            }
216
        }
217
    }
218
 
219
    /**
220
     * Physical memory information and Swap Space information
221
     * @return void
222
     */
223
    private function _memory()
224
    {
225
        $mems = "";
226
        $tswap = "";
227
        $pswap = "";
228
        foreach ($this->readaixdata() as $line) {
229
            if (preg_match("/^Good Memory Size:\s+(\d+)\s+MB/", $line, $ar_buf)) {
230
                $mems = $ar_buf[1];
231
            }
232
            if (preg_match("/^\s*Total Paging Space:\s+(\d+)MB/", $line, $ar_buf)) {
233
                $tswap = $ar_buf[1];
234
            }
235
            if (preg_match("/^\s*Percent Used:\s+(\d+)%/", $line, $ar_buf)) {
236
                $pswap = $ar_buf[1];
237
            }
238
        }
239
        if (trim($mems) != "") {
240
            $mems = $mems*1024*1024;
241
            $this->sys->setMemTotal($mems);
242
            $memu = 0;
243
            $memf = 0;
244
            if (CommonFunctions::executeProgram('svmon', '-G', $buf)) {
245
                if (preg_match("/^memory\s+\d+\s+(\d+)\s+/", $buf, $ar_buf)) {
246
                    $memu = $ar_buf[1]*1024*4;
247
                    $memf = $mems - $memu;
248
                }
249
            }
250
            $this->sys->setMemUsed($memu);
251
            $this->sys->setMemFree($memf);
252
//            $this->sys->setMemApplication($mems);
253
//            $this->sys->setMemBuffer($mems);
254
//            $this->sys->setMemCache($mems);
255
        }
256
        if (trim($tswap) != "") {
257
            $dev = new DiskDevice();
258
            $dev->setName("SWAP");
259
            $dev->setFsType('swap');
260
            $dev->setTotal($tswap * 1024 * 1024);
261
            if (trim($pswap) != "") {
262
                $dev->setUsed($dev->getTotal() * $pswap / 100);
263
            }
264
            $dev->setFree($dev->getTotal() - $dev->getUsed());
265
            $this->sys->setSwapDevices($dev);
266
        }
267
    }
268
 
269
    /**
270
     * filesystem information
271
     *
272
     * @return void
273
     */
274
    private function _filesystems()
275
    {
276
        if (CommonFunctions::executeProgram('df', '-kP', $df, PSI_DEBUG)) {
277
            $mounts = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
278
            if (CommonFunctions::executeProgram('mount', '-v', $s, PSI_DEBUG)) {
279
                $lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
280
                foreach ($lines as $line) {
281
                    $a = preg_split('/ /', $line, -1, PREG_SPLIT_NO_EMPTY);
282
                    $fsdev[$a[0]] = $a[4];
283
                }
284
            }
285
            foreach ($mounts as $mount) {
286
                $ar_buf = preg_split("/\s+/", $mount, 6);
287
                $dev = new DiskDevice();
288
                $dev->setName($ar_buf[0]);
289
                $dev->setTotal($ar_buf[1] * 1024);
290
                $dev->setUsed($ar_buf[2] * 1024);
291
                $dev->setFree($ar_buf[3] * 1024);
292
                $dev->setMountPoint($ar_buf[5]);
293
                if (isset($fsdev[$ar_buf[0]])) {
294
                    $dev->setFsType($fsdev[$ar_buf[0]]);
295
                }
296
                $this->sys->setDiskDevices($dev);
297
            }
298
        }
299
    }
300
 
301
    /**
302
     * Distribution
303
     *
304
     * @return void
305
     */
306
    private function _distro()
307
    {
308
        $this->sys->setDistribution('IBM AIX');
309
        $this->sys->setDistributionIcon('AIX.png');
310
    }
311
 
312
    /**
313
     * IBM AIX informations by K.PAZ
314
     * @return array
315
     */
316
    private function readaixdata()
317
    {
318
        if (count($this->_aixdata) === 0) {
319
            if (CommonFunctions::executeProgram('prtconf', '', $bufr)) {
320
                $this->_aixdata = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
321
            }
322
        }
323
 
324
        return $this->_aixdata;
325
    }
326
 
327
    /**
328
     * get the information
329
     *
330
     * @see PSI_Interface_OS::build()
331
     *
332
     * @return Void
333
     */
334
    public function build()
335
    {
336
        $this->error->addError("WARN", "The AIX version of phpSysInfo is a work in progress, some things currently don't work");
337
        if (!$this->blockname || $this->blockname==='vitals') {
338
            $this->_distro();
339
            $this->_hostname();
340
            $this->_kernel();
341
            $this->_uptime();
342
            $this->_users();
343
            $this->_loadavg();
344
        }
345
        if (!$this->blockname || $this->blockname==='hardware') {
346
            $this->_cpuinfo();
347
            $this->_pci();
348
            $this->_ide();
349
            $this->_scsi();
350
            $this->_usb();
351
        }
352
        if (!$this->blockname || $this->blockname==='network') {
353
            $this->_network();
354
        }
355
        if (!$this->blockname || $this->blockname==='memory') {
356
            $this->_memory();
357
        }
358
        if (!$this->blockname || $this->blockname==='filesystem') {
359
            $this->_filesystems();
360
        }
361
    }
362
}