Subversion Repositories ALCASAR

Rev

Rev 2770 | Rev 3037 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2770 Rev 2976
1
<?php
1
<?php
2
/**
2
/**
3
 * hwmon sensor class, getting hardware sensors information from /sys/class/hwmon/hwmon
3
 * hwmon sensor class, getting hardware sensors information from /sys/class/hwmon/hwmon
4
 *
4
 *
5
 * PHP version 5
5
 * PHP version 5
6
 *
6
 *
7
 * @category  PHP
7
 * @category  PHP
8
 * @package   PSI_Sensor
8
 * @package   PSI_Sensor
9
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
9
 * @author    Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
10
 * @copyright 2016 phpSysInfo
10
 * @copyright 2016 phpSysInfo
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
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   Release: 3.0
12
 * @version   Release: 3.0
13
 * @link      http://phpsysinfo.sourceforge.net
13
 * @link      http://phpsysinfo.sourceforge.net
14
 */
14
 */
15
class Hwmon extends Sensors
15
class Hwmon extends Sensors
16
{
16
{
17
    /**
17
    /**
18
     * get temperature information
18
     * get temperature information
19
     *
19
     *
20
     * @param  string $hwpath
20
     * @param  string $hwpath
21
     * @return void
21
     * @return void
22
     */
22
     */
23
    protected function _temperature($hwpath)
23
    protected function _temperature($hwpath)
24
    {
24
    {
25
       $sensor = glob($hwpath."temp*_input", GLOB_NOSORT);
25
       $sensor = glob($hwpath."temp*_input", GLOB_NOSORT);
26
       if (is_array($sensor) && (($total = count($sensor)) > 0)) {
26
       if (is_array($sensor) && (($total = count($sensor)) > 0)) {
27
            $buf = "";
27
            $buf = "";
28
            for ($i = 0; $i < $total; $i++) if (($buf = CommonFunctions::rolv($sensor[$i]))!==null) {
28
            for ($i = 0; $i < $total; $i++) if (($buf = CommonFunctions::rolv($sensor[$i]))!==null) {
29
                $dev = new SensorDevice();
29
                $dev = new SensorDevice();
30
                $dev->setValue($buf/1000);
30
                $dev->setValue($buf/1000);
31
                if (($buf = CommonFunctions::rolv($sensor[$i], "/\/[^\/]*_input$/", "/name"))!==null) {
31
                if (($buf = CommonFunctions::rolv($sensor[$i], "/\/[^\/]*_input$/", "/name"))!==null) {
32
                   $name = " (".$buf.")";
32
                   $name = " (".$buf.")";
33
                } else {
33
                } else {
34
                   $name = "";
34
                   $name = "";
35
                }
35
                }
36
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_label"))!==null) {
36
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_label"))!==null) {
37
                    $dev->setName($buf.$name);
37
                    $dev->setName($buf.$name);
38
                } else {
38
                } else {
39
                    $labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
39
                    $labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
-
 
40
                    if (($name == " (drivetemp)") && (count($buf = CommonFunctions::gdc($hwpath . "device/block", false)))) {
-
 
41
                        $labelname = "/dev/" . $buf[0];
-
 
42
                        if (($buf = CommonFunctions::rolv($hwpath . "device/model"))!==null) {
-
 
43
                            $labelname .= " (".$buf.")";
-
 
44
                            $name = "";
-
 
45
                        }
-
 
46
                    }
40
                    if ($labelname !== "") {
47
                    if ($labelname !== "") {
41
                        $dev->setName($labelname.$name);
48
                        $dev->setName($labelname.$name);
42
                    } else {
49
                    } else {
43
                        $dev->setName('unknown'.$name);
50
                        $dev->setName('unknown'.$name);
44
                    }
51
                    }
45
                }
52
                }
46
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_crit"))!==null) {
53
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_crit"))!==null) {
47
                    $dev->setMax($buf/1000);
54
                    $dev->setMax($buf/1000);
48
                    if (CommonFunctions::rolv($sensor[$i], "/_input$/", "_crit_alarm")==="1") {
55
                    if (CommonFunctions::rolv($sensor[$i], "/_input$/", "_crit_alarm")==="1") {
49
                        $dev->setEvent("Critical Alarm");
56
                        $dev->setEvent("Critical Alarm");
50
                    }
57
                    }
51
                } elseif (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_max"))!==null) {
58
                } elseif (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_max"))!==null) {
52
                    $dev->setMax($buf/1000);
59
                    $dev->setMax($buf/1000);
53
                }
60
                }
54
                $this->mbinfo->setMbTemp($dev);
61
                $this->mbinfo->setMbTemp($dev);
55
            }
62
            }
56
        }
63
        }
57
    }
64
    }
58
 
65
 
59
    /**
66
    /**
60
     * get voltage information
67
     * get voltage information
61
     *
68
     *
62
     * @param  string $hwpath
69
     * @param  string $hwpath
63
     * @return void
70
     * @return void
64
     */
71
     */
65
    private function _voltage($hwpath)
72
    private function _voltage($hwpath)
66
    {
73
    {
67
       $sensor = glob($hwpath."in*_input", GLOB_NOSORT);
74
       $sensor = glob($hwpath."in*_input", GLOB_NOSORT);
68
       if (is_array($sensor) && (($total = count($sensor)) > 0)) {
75
       if (is_array($sensor) && (($total = count($sensor)) > 0)) {
69
            $buf = "";
76
            $buf = "";
70
            for ($i = 0; $i < $total; $i++) if (($buf = CommonFunctions::rolv($sensor[$i]))!==null) {
77
            for ($i = 0; $i < $total; $i++) if (($buf = CommonFunctions::rolv($sensor[$i]))!==null) {
71
                $dev = new SensorDevice();
78
                $dev = new SensorDevice();
72
                $dev->setValue($buf/1000);
79
                $dev->setValue($buf/1000);
73
                if (($buf = CommonFunctions::rolv($sensor[$i], "/\/[^\/]*_input$/", "/name"))!==null) {
80
                if (($buf = CommonFunctions::rolv($sensor[$i], "/\/[^\/]*_input$/", "/name"))!==null) {
74
                   $name = " (".$buf.")";
81
                   $name = " (".$buf.")";
75
                } else {
82
                } else {
76
                   $name = "";
83
                   $name = "";
77
                }
84
                }
78
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_label"))!==null) {
85
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_label"))!==null) {
79
                    $dev->setName($buf.$name);
86
                    $dev->setName($buf.$name);
80
                } else {
87
                } else {
81
                    $labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
88
                    $labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
82
                    if ($labelname !== "") {
89
                    if ($labelname !== "") {
83
                        $dev->setName($labelname.$name);
90
                        $dev->setName($labelname.$name);
84
                    } else {
91
                    } else {
85
                        $dev->setName('unknown'.$name);
92
                        $dev->setName('unknown'.$name);
86
                    }
93
                    }
87
                }
94
                }
88
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_max"))!==null) {
95
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_max"))!==null) {
89
                    $dev->setMax($buf/1000);
96
                    $dev->setMax($buf/1000);
90
                }
97
                }
91
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_min"))!==null) {
98
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_min"))!==null) {
92
                    $dev->setMin($buf/1000);
99
                    $dev->setMin($buf/1000);
93
                }
100
                }
94
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_alarm"))==="1") {
101
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_alarm"))==="1") {
95
                    $dev->setEvent("Alarm");
102
                    $dev->setEvent("Alarm");
96
                }
103
                }
97
                $this->mbinfo->setMbVolt($dev);
104
                $this->mbinfo->setMbVolt($dev);
98
            }
105
            }
99
        }
106
        }
100
    }
107
    }
101
 
108
 
102
    /**
109
    /**
103
     * get fan information
110
     * get fan information
104
     *
111
     *
105
     * @param  string $hwpath
112
     * @param  string $hwpath
106
     * @return void
113
     * @return void
107
     */
114
     */
108
    protected function _fans($hwpath)
115
    protected function _fans($hwpath)
109
    {
116
    {
110
       $sensor = glob($hwpath."fan*_input", GLOB_NOSORT);
117
       $sensor = glob($hwpath."fan*_input", GLOB_NOSORT);
111
       if (is_array($sensor) && (($total = count($sensor)) > 0)) {
118
       if (is_array($sensor) && (($total = count($sensor)) > 0)) {
112
            $buf = "";
119
            $buf = "";
113
            for ($i = 0; $i < $total; $i++) if (($buf = CommonFunctions::rolv($sensor[$i]))!==null) {
120
            for ($i = 0; $i < $total; $i++) if (($buf = CommonFunctions::rolv($sensor[$i]))!==null) {
114
                $dev = new SensorDevice();
121
                $dev = new SensorDevice();
115
                $dev->setValue($buf);
122
                $dev->setValue($buf);
116
                if (($buf = CommonFunctions::rolv($sensor[$i], "/\/[^\/]*_input$/", "/name"))!==null) {
123
                if (($buf = CommonFunctions::rolv($sensor[$i], "/\/[^\/]*_input$/", "/name"))!==null) {
117
                   $name = " (".$buf.")";
124
                   $name = " (".$buf.")";
118
                } else {
125
                } else {
119
                   $name = "";
126
                   $name = "";
120
                }
127
                }
121
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_label"))!==null) {
128
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_label"))!==null) {
122
                    $dev->setName($buf.$name);
129
                    $dev->setName($buf.$name);
123
                } else {
130
                } else {
124
                    $labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
131
                    $labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
125
                    if ($labelname !== "") {
132
                    if ($labelname !== "") {
126
                        $dev->setName($labelname.$name);
133
                        $dev->setName($labelname.$name);
127
                    } else {
134
                    } else {
128
                        $dev->setName('unknown'.$name);
135
                        $dev->setName('unknown'.$name);
129
                    }
136
                    }
130
                }
137
                }
131
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_full_speed"))!==null) {
138
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_full_speed"))!==null) {
132
                    $dev->setMax($buf);
139
                    $dev->setMax($buf);
133
                } elseif (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_max"))!==null) {
140
                } elseif (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_max"))!==null) {
134
                    $dev->setMax($buf);
141
                    $dev->setMax($buf);
135
                }
142
                }
136
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_min"))!==null) {
143
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_min"))!==null) {
137
                    $dev->setMin($buf);
144
                    $dev->setMin($buf);
138
                }
145
                }
139
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_alarm"))==="1") {
146
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_alarm"))==="1") {
140
                    $dev->setEvent("Alarm");
147
                    $dev->setEvent("Alarm");
141
                }
148
                }
142
                $this->mbinfo->setMbFan($dev);
149
                $this->mbinfo->setMbFan($dev);
143
            }
150
            }
144
        }
151
        }
145
    }
152
    }
146
 
153
 
147
    /**
154
    /**
148
     * get power information
155
     * get power information
149
     *
156
     *
150
     * @param  string $hwpath
157
     * @param  string $hwpath
151
     * @return void
158
     * @return void
152
     */
159
     */
153
    private function _power($hwpath)
160
    private function _power($hwpath)
154
    {
161
    {
155
       $sensor = glob($hwpath."power*_input", GLOB_NOSORT);
162
       $sensor = glob($hwpath."power*_input", GLOB_NOSORT);
156
       if (is_array($sensor) && (($total = count($sensor)) > 0)) {
163
       if (is_array($sensor) && (($total = count($sensor)) > 0)) {
157
            $buf = "";
164
            $buf = "";
158
            for ($i = 0; $i < $total; $i++) if (($buf = CommonFunctions::rolv($sensor[$i]))!==null) {
165
            for ($i = 0; $i < $total; $i++) if (($buf = CommonFunctions::rolv($sensor[$i]))!==null) {
159
                $dev = new SensorDevice();
166
                $dev = new SensorDevice();
160
                $dev->setValue($buf/1000000);
167
                $dev->setValue($buf/1000000);
161
                if (($buf = CommonFunctions::rolv($sensor[$i], "/\/[^\/]*_input$/", "/name"))!==null) {
168
                if (($buf = CommonFunctions::rolv($sensor[$i], "/\/[^\/]*_input$/", "/name"))!==null) {
162
                   $name = " (".$buf.")";
169
                   $name = " (".$buf.")";
163
                } else {
170
                } else {
164
                   $name = "";
171
                   $name = "";
165
                }
172
                }
166
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_label"))!==null) {
173
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_label"))!==null) {
167
                    $dev->setName($buf.$name);
174
                    $dev->setName($buf.$name);
168
                } else {
175
                } else {
169
                    $labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
176
                    $labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
170
                    if ($labelname !== "") {
177
                    if ($labelname !== "") {
171
                        $dev->setName($labelname.$name);
178
                        $dev->setName($labelname.$name);
172
                    } else {
179
                    } else {
173
                        $dev->setName('unknown'.$name);
180
                        $dev->setName('unknown'.$name);
174
                    }
181
                    }
175
                }
182
                }
176
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_max"))!==null) {
183
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_max"))!==null) {
177
                    $dev->setMax($buf/1000000);
184
                    $dev->setMax($buf/1000000);
178
                }
185
                }
179
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_min"))!==null) {
186
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_min"))!==null) {
180
                    $dev->setMin($buf/1000000);
187
                    $dev->setMin($buf/1000000);
181
                }
188
                }
182
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_alarm"))==="1") {
189
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_alarm"))==="1") {
183
                    $dev->setEvent("Alarm");
190
                    $dev->setEvent("Alarm");
184
                }
191
                }
185
                $this->mbinfo->setMbPower($dev);
192
                $this->mbinfo->setMbPower($dev);
186
            }
193
            }
187
        }
194
        }
188
    }
195
    }
189
 
196
 
190
    /**
197
    /**
191
     * get current information
198
     * get current information
192
     *
199
     *
193
     * @param  string $hwpath
200
     * @param  string $hwpath
194
     * @return void
201
     * @return void
195
     */
202
     */
196
    private function _current($hwpath)
203
    private function _current($hwpath)
197
    {
204
    {
198
       $sensor = glob($hwpath."curr*_input", GLOB_NOSORT);
205
       $sensor = glob($hwpath."curr*_input", GLOB_NOSORT);
199
       if (is_array($sensor) && (($total = count($sensor)) > 0)) {
206
       if (is_array($sensor) && (($total = count($sensor)) > 0)) {
200
            $buf = "";
207
            $buf = "";
201
            for ($i = 0; $i < $total; $i++) if (($buf = CommonFunctions::rolv($sensor[$i]))!==null) {
208
            for ($i = 0; $i < $total; $i++) if (($buf = CommonFunctions::rolv($sensor[$i]))!==null) {
202
                $dev = new SensorDevice();
209
                $dev = new SensorDevice();
203
                $dev->setValue($buf/1000);
210
                $dev->setValue($buf/1000);
204
                if (($buf = CommonFunctions::rolv($sensor[$i], "/\/[^\/]*_input$/", "/name"))!==null) {
211
                if (($buf = CommonFunctions::rolv($sensor[$i], "/\/[^\/]*_input$/", "/name"))!==null) {
205
                   $name = " (".$buf.")";
212
                   $name = " (".$buf.")";
206
                } else {
213
                } else {
207
                   $name = "";
214
                   $name = "";
208
                }
215
                }
209
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_label"))!==null) {
216
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_label"))!==null) {
210
                    $dev->setName($buf.$name);
217
                    $dev->setName($buf.$name);
211
                } else {
218
                } else {
212
                    $labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
219
                    $labelname = trim(preg_replace("/_input$/", "", pathinfo($sensor[$i], PATHINFO_BASENAME)));
213
                    if ($labelname !== "") {
220
                    if ($labelname !== "") {
214
                        $dev->setName($labelname.$name);
221
                        $dev->setName($labelname.$name);
215
                    } else {
222
                    } else {
216
                        $dev->setName('unknown'.$name);
223
                        $dev->setName('unknown'.$name);
217
                    }
224
                    }
218
                }
225
                }
219
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_max"))!==null) {
226
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_max"))!==null) {
220
                    $dev->setMax($buf/1000);
227
                    $dev->setMax($buf/1000);
221
                }
228
                }
222
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_min"))!==null) {
229
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_min"))!==null) {
223
                    $dev->setMin($buf/1000);
230
                    $dev->setMin($buf/1000);
224
                }
231
                }
225
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_alarm"))==="1") {
232
                if (($buf = CommonFunctions::rolv($sensor[$i], "/_input$/", "_alarm"))==="1") {
226
                    $dev->setEvent("Alarm");
233
                    $dev->setEvent("Alarm");
227
                }
234
                }
228
                $this->mbinfo->setMbCurrent($dev);
235
                $this->mbinfo->setMbCurrent($dev);
229
            }
236
            }
230
        }
237
        }
231
    }
238
    }
232
 
239
 
233
    /**
240
    /**
234
     * get the information
241
     * get the information
235
     *
242
     *
236
     * @see PSI_Interface_Sensor::build()
243
     * @see PSI_Interface_Sensor::build()
237
     *
244
     *
238
     * @return Void
245
     * @return Void
239
     */
246
     */
240
    public function build()
247
    public function build()
241
    {
248
    {
-
 
249
        if ((PSI_OS == 'Linux') && !defined('PSI_EMU_HOSTNAME')) {
242
        $hwpaths = glob("/sys/class/hwmon/hwmon*/", GLOB_NOSORT);
250
            $hwpaths = glob("/sys/class/hwmon/hwmon*/", GLOB_NOSORT);
243
        if (is_array($hwpaths) && (count($hwpaths) > 0)) {
251
            if (is_array($hwpaths) && (count($hwpaths) > 0)) {
244
            $hwpaths = array_merge($hwpaths, glob("/sys/class/hwmon/hwmon*/device/", GLOB_NOSORT));
252
                $hwpaths2 = glob("/sys/class/hwmon/hwmon*/device/", GLOB_NOSORT);
-
 
253
                if (is_array($hwpaths2) && (count($hwpaths2) > 0)) {
-
 
254
                    $hwpaths = array_merge($hwpaths, $hwpaths2);
245
        }
255
                }
246
        if (is_array($hwpaths) && (($totalh = count($hwpaths)) > 0)) {
256
                $totalh = count($hwpaths);
247
            for ($h = 0; $h < $totalh; $h++) {
257
                for ($h = 0; $h < $totalh; $h++) {
248
                $this->_temperature($hwpaths[$h]);
258
                    $this->_temperature($hwpaths[$h]);
249
                $this->_voltage($hwpaths[$h]);
259
                    $this->_voltage($hwpaths[$h]);
250
                $this->_fans($hwpaths[$h]);
260
                    $this->_fans($hwpaths[$h]);
251
                $this->_power($hwpaths[$h]);
261
                    $this->_power($hwpaths[$h]);
252
                $this->_current($hwpaths[$h]);
262
                    $this->_current($hwpaths[$h]);
-
 
263
                }
253
            }
264
            }
254
        }
265
        }
255
    }
266
    }
256
}
267
}
257
 
268