Subversion Repositories ALCASAR

Rev

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