Subversion Repositories ALCASAR

Rev

Rev 3037 | Details | Compare with Previous | Last modification | View Log

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