2 * rd_sensors.c: Read sensors statistics
3 * (C) 1999-2016 by Sebastien GODARD (sysstat <at> orange.fr)
5 ***************************************************************************
6 * This program is free software; you can redistribute it and/or modify it *
7 * under the terms of the GNU General Public License as published by the *
8 * Free Software Foundation; either version 2 of the License, or (at your *
9 * option) any later version. *
11 * This program is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without the implied warranty of MERCHANTABILITY *
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
16 * You should have received a copy of the GNU General Public License along *
17 * with this program; if not, write to the Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA *
19 ***************************************************************************
26 #include "rd_sensors.h"
31 #define _(string) gettext(string)
33 #define _(string) (string)
37 #include "sensors/sensors.h"
41 ***************************************************************************
42 * Read fan statistics.
45 * @st_pwr_fan Structure where stats will be saved.
46 * @nbr Total number of fans.
49 * @st_pwr_fan Structure with statistics.
50 ***************************************************************************
52 void read_fan(struct stats_pwr_fan *st_pwr_fan, int nbr)
56 const sensors_chip_name *chip;
57 const sensors_feature *feature;
58 const sensors_subfeature *sub;
59 struct stats_pwr_fan *st_pwr_fan_i;
63 memset(st_pwr_fan, 0, STATS_PWR_FAN_SIZE);
65 while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
67 while ((feature = sensors_get_features(chip, &i))) {
68 if ((feature->type == SENSORS_FEATURE_FAN) && (count < nbr)) {
70 st_pwr_fan_i = st_pwr_fan + count;
71 sensors_snprintf_chip_name(st_pwr_fan_i->device, MAX_SENSORS_DEV_LEN, chip);
73 while ((sub = sensors_get_all_subfeatures(chip, feature, &j))) {
74 if ((sub->type == SENSORS_SUBFEATURE_FAN_INPUT) &&
75 (sub->flags & SENSORS_MODE_R)) {
76 if (sensors_get_value(chip, sub->number, &st_pwr_fan_i->rpm)) {
77 st_pwr_fan_i->rpm = 0;
80 else if ((sub->type == SENSORS_SUBFEATURE_FAN_MIN)) {
81 if (sensors_get_value(chip, sub->number, &st_pwr_fan_i->rpm_min)) {
82 st_pwr_fan_i->rpm_min = 0;
90 #endif /* HAVE_SENSORS */
94 ***************************************************************************
95 * Read device temperature statistics.
98 * @st_pwr_temp Structure where stats will be saved.
99 * @nbr Total number of fans.
102 * @st_pwr_temp Structure with statistics.
103 ***************************************************************************
105 void read_temp(struct stats_pwr_temp *st_pwr_temp, int nbr)
109 const sensors_chip_name *chip;
110 const sensors_feature *feature;
111 const sensors_subfeature *sub;
112 struct stats_pwr_temp *st_pwr_temp_i;
116 memset(st_pwr_temp, 0, STATS_PWR_TEMP_SIZE);
118 while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
120 while ((feature = sensors_get_features(chip, &i))) {
121 if ((feature->type == SENSORS_FEATURE_TEMP) && (count < nbr)) {
123 st_pwr_temp_i = st_pwr_temp + count;
124 sensors_snprintf_chip_name(st_pwr_temp_i->device, MAX_SENSORS_DEV_LEN, chip);
126 while ((sub = sensors_get_all_subfeatures(chip, feature, &j))) {
127 if ((sub->type == SENSORS_SUBFEATURE_TEMP_INPUT) &&
128 (sub->flags & SENSORS_MODE_R)) {
129 if (sensors_get_value(chip, sub->number, &st_pwr_temp_i->temp)) {
130 st_pwr_temp_i->temp = 0;
133 else if ((sub->type == SENSORS_SUBFEATURE_TEMP_MIN)) {
134 if (sensors_get_value(chip, sub->number, &st_pwr_temp_i->temp_min)) {
135 st_pwr_temp_i->temp_min = 0;
138 else if ((sub->type == SENSORS_SUBFEATURE_TEMP_MAX)) {
139 if (sensors_get_value(chip, sub->number, &st_pwr_temp_i->temp_max)) {
140 st_pwr_temp_i->temp_max = 0;
148 #endif /* HAVE_SENSORS */
152 ***************************************************************************
153 * Read voltage inputs statistics.
156 * @st_pwr_in Structure where stats will be saved.
157 * @nbr Total number of voltage inputs.
160 * @st_pwr_in Structure with statistics.
161 ***************************************************************************
163 void read_in(struct stats_pwr_in *st_pwr_in, int nbr)
167 const sensors_chip_name *chip;
168 const sensors_feature *feature;
169 const sensors_subfeature *sub;
170 struct stats_pwr_in *st_pwr_in_i;
174 memset(st_pwr_in, 0, STATS_PWR_IN_SIZE);
176 while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
178 while ((feature = sensors_get_features(chip, &i))) {
179 if ((feature->type == SENSORS_FEATURE_IN) && (count < nbr)) {
181 st_pwr_in_i = st_pwr_in + count;
182 sensors_snprintf_chip_name(st_pwr_in_i->device, MAX_SENSORS_DEV_LEN, chip);
184 while ((sub = sensors_get_all_subfeatures(chip, feature, &j))) {
185 if ((sub->type == SENSORS_SUBFEATURE_IN_INPUT) &&
186 (sub->flags & SENSORS_MODE_R)) {
187 if (sensors_get_value(chip, sub->number, &st_pwr_in_i->in)) {
191 else if ((sub->type == SENSORS_SUBFEATURE_IN_MIN)) {
192 if (sensors_get_value(chip, sub->number, &st_pwr_in_i->in_min)) {
193 st_pwr_in_i->in_min = 0;
196 else if ((sub->type == SENSORS_SUBFEATURE_IN_MAX)) {
197 if (sensors_get_value(chip, sub->number, &st_pwr_in_i->in_max)) {
198 st_pwr_in_i->in_max = 0;
206 #endif /* HAVE_SENSORS */
211 ***************************************************************************
212 * Count the number of sensors of given type on the machine.
215 * @type Type of sensors.
219 ***************************************************************************
221 int get_sensors_nr(sensors_feature_type type) {
223 const sensors_chip_name *chip;
224 const sensors_feature *feature;
228 while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
230 while ((feature = sensors_get_features(chip, &i))) {
231 if (feature->type == type) {
239 #endif /* HAVE_SENSORS */
242 ***************************************************************************
243 * Count the number of fans on the machine.
247 ***************************************************************************
252 return get_sensors_nr(SENSORS_FEATURE_FAN);
255 #endif /* HAVE_SENSORS */
259 ***************************************************************************
260 * Count the number of temperature sensors on the machine.
263 * Number of temperature sensors.
264 ***************************************************************************
266 int get_temp_nr(void)
269 return get_sensors_nr(SENSORS_FEATURE_TEMP);
272 #endif /* HAVE_SENSORS */
277 ***************************************************************************
278 * Count the number of voltage inputs on the machine.
281 * Number of voltage inputs.
282 ***************************************************************************
287 return get_sensors_nr(SENSORS_FEATURE_IN);
290 #endif /* HAVE_SENSORS */