Subversion Repositories ALCASAR

Rev

Rev 2770 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2770 Rev 3037
Line 30... Line 30...
30
     * define the regexp for log parser
30
     * define the regexp for log parser
31
     */
31
     */
32
    public function __construct($blockname = false)
32
    public function __construct($blockname = false)
33
    {
33
    {
34
        parent::__construct($blockname);
34
        parent::__construct($blockname);
35
        $this->setCPURegExp1("/^cpu(.*)\, (.*) MHz/");
35
        //$this->setCPURegExp1("/^cpu(.*)\, (.*) MHz/");
36
        $this->setCPURegExp2("/user = (.*), nice = (.*), sys = (.*), intr = (.*), idle = (.*)/");
36
        $this->setCPURegExp2("/user = (.*), nice = (.*), sys = (.*), intr = (.*), idle = (.*)/");
37
        $this->setSCSIRegExp1("/^(.*) at scsibus.*: <(.*)> .*/");
37
        $this->setSCSIRegExp1("/^(.*) at scsibus.*: <(.*)> .*/");
38
        $this->setSCSIRegExp2("/^(sd[0-9]+): (.*)([MG])B,/");
38
        $this->setSCSIRegExp2("/^(sd[0-9]+): (.*)([MG])B,/");
39
        $this->setPCIRegExp1("/(.*) at pci[0-9]+ dev [0-9]* function [0-9]*: (.*)$/");
39
        $this->setPCIRegExp1("/(.*) at pci[0-9]+ dev [0-9]* function [0-9]*: (.*)$/");
40
        $this->setPCIRegExp2("/\"(.*)\" (.*).* at [.0-9]+ irq/");
40
        $this->setPCIRegExp2("/\"(.*)\" (.*).* at [.0-9]+ irq/");
41
    }
41
    }
42
 
42
 
43
    /**
43
    /**
44
     * UpTime
-
 
45
     * time the system is running
-
 
46
     *
-
 
47
     * @return void
-
 
48
     */
-
 
49
    private function _uptime()
-
 
50
    {
-
 
51
        $a = $this->grabkey('kern.boottime');
-
 
52
        $this->sys->setUptime(time() - $a);
-
 
53
    }
-
 
54
 
-
 
55
    /**
-
 
56
     * get network information
44
     * get network information
57
     *
45
     *
58
     * @return void
46
     * @return void
59
     */
47
     */
60
    private function _network()
48
    private function _network()
Line 146... Line 134...
146
            }
134
            }
147
        }
135
        }
148
    }
136
    }
149
 
137
 
150
    /**
138
    /**
-
 
139
     * CPU information
-
 
140
     *
-
 
141
     * @return void
-
 
142
     */
-
 
143
    protected function cpuinfo()
-
 
144
    {
-
 
145
        $was = false;
-
 
146
        $cpuarray = array();
-
 
147
        foreach ($this->readdmesg() as $line) {
-
 
148
            if (preg_match("/^cpu([0-9])+: (.*)/", $line, $ar_buf)) {
-
 
149
                $was = true;
-
 
150
                $ar_buf[2] = trim($ar_buf[2]);
-
 
151
                if (preg_match("/^(.+), ([\d\.]+) MHz/", $ar_buf[2], $ar_buf2)) {
-
 
152
                    if (($model = trim($ar_buf2[1])) !== "") {
-
 
153
                        $cpuarray[$ar_buf[1]]['model'] = $model;
-
 
154
                    }
-
 
155
                    if (($speed = trim($ar_buf2[2])) > 0) {
-
 
156
                        $cpuarray[$ar_buf[1]]['speed'] = $speed;
-
 
157
                    }
-
 
158
                } elseif (preg_match("/^L2 cache (\d+) ([KM])B /", $ar_buf[2], $ar_buf2)) {
-
 
159
                    if ($ar_buf2[2]=="M") {
-
 
160
                        $cpuarray[$ar_buf[1]]['cache'] = $ar_buf2[1]*1024*1024;
-
 
161
                    } elseif ($ar_buf2[2]=="K") {
-
 
162
                        $cpuarray[$ar_buf[1]]['cache'] = $ar_buf2[1]*1024;
-
 
163
                    }
-
 
164
                }
-
 
165
            } elseif (!preg_match("/^cpu[0-9]+ /", $line) && $was) {
-
 
166
                break;
-
 
167
            }
-
 
168
        }
-
 
169
 
-
 
170
        $ncpu = $this->grabkey('hw.ncpu');
-
 
171
        if (($ncpu === "") || !($ncpu >= 1)) {
-
 
172
            $ncpu = 1;
-
 
173
        }
-
 
174
        $ncpu = max($ncpu, count($cpuarray));
-
 
175
 
-
 
176
        $model = $this->grabkey('machdep.cpu_brand');
-
 
177
        $model2 = $this->grabkey('hw.model');
-
 
178
        if ($cpuspeed = $this->grabkey('machdep.tsc_freq')) {
-
 
179
            $speed = round($cpuspeed / 1000000);
-
 
180
        } else {
-
 
181
            $speed = "";
-
 
182
        }
-
 
183
 
-
 
184
        for ($cpu = 0 ; $cpu < $ncpu ; $cpu++) {
-
 
185
            $dev = new CpuDevice();
-
 
186
 
-
 
187
            if (isset($cpuarray[$cpu]['model'])) {
-
 
188
                $dev->setModel($cpuarray[$cpu]['model']);
-
 
189
            } elseif ($model !== "") {
-
 
190
                $dev->setModel($model);
-
 
191
            } elseif ($model2 !== "") {
-
 
192
                $dev->setModel($model2);
-
 
193
            }
-
 
194
            if (isset($cpuarray[$cpu]['speed'])) {
-
 
195
                $dev->setCpuSpeed($cpuarray[$cpu]['speed']);
-
 
196
            } elseif ($speed !== "") {
-
 
197
                $dev->setCpuSpeed($speed);
-
 
198
            }
-
 
199
            if (isset($cpuarray[$cpu]['cache'])) {
-
 
200
                $dev->setCache($cpuarray[$cpu]['cache']);
-
 
201
            }
-
 
202
            if (($ncpu == 1) && PSI_LOAD_BAR) {
-
 
203
                $dev->setLoad($this->cpuusage());
-
 
204
            }
-
 
205
            $this->sys->setCpus($dev);
-
 
206
        }
-
 
207
    }
-
 
208
 
-
 
209
    /**
151
     * get icon name
210
     * get icon name
152
     *
211
     *
153
     * @return void
212
     * @return void
154
     */
213
     */
155
    private function _distroicon()
214
    private function _distroicon()
Line 189... Line 248...
189
    /**
248
    /**
190
     * get the information
249
     * get the information
191
     *
250
     *
192
     * @see BSDCommon::build()
251
     * @see BSDCommon::build()
193
     *
252
     *
194
     * @return Void
253
     * @return void
195
     */
254
     */
196
    public function build()
255
    public function build()
197
    {
256
    {
198
        parent::build();
257
        parent::build();
199
        if (!$this->blockname || $this->blockname==='vitals') {
258
        if (!$this->blockname || $this->blockname==='vitals') {
200
            $this->_distroicon();
259
            $this->_distroicon();
201
            $this->_uptime();
-
 
202
            $this->_processes();
260
            $this->_processes();
203
        }
261
        }
204
        if (!$this->blockname || $this->blockname==='network') {
262
        if (!$this->blockname || $this->blockname==='network') {
205
            $this->_network();
263
            $this->_network();
206
        }
264
        }