2 * rd_sensors.c: Read sensors statistics
3 * (C) 1999-2011 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 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 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);
66 while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
68 while ((feature = sensors_get_features(chip, &i))) {
69 if ((feature->type == SENSORS_FEATURE_FAN) && (count < nbr)) {
71 st_pwr_fan_i = st_pwr_fan + count;
72 sensors_snprintf_chip_name(st_pwr_fan_i->device, MAX_SENSORS_DEV_LEN, chip);
74 while ((sub = sensors_get_all_subfeatures(chip, feature, &j))) {
75 if ((sub->type == SENSORS_SUBFEATURE_FAN_INPUT) &&
76 (sub->flags & SENSORS_MODE_R)) {
77 if ((err = sensors_get_value(chip, sub->number, &st_pwr_fan_i->rpm))) {
78 st_pwr_fan_i->rpm = 0;
81 else if ((sub->type == SENSORS_SUBFEATURE_FAN_MIN)) {
82 if ((err = sensors_get_value(chip, sub->number, &st_pwr_fan_i->rpm_min))) {
83 st_pwr_fan_i->rpm_min = 0;
91 #endif /* HAVE_SENSORS */
95 ***************************************************************************
96 * Read device temperature statistics.
99 * @st_pwr_temp Structure where stats will be saved.
100 * @nbr Total number of fans.
103 * @st_pwr_temp Structure with statistics.
104 ***************************************************************************
106 void read_temp(struct stats_pwr_temp *st_pwr_temp, int nbr)
110 const sensors_chip_name *chip;
111 const sensors_feature *feature;
112 const sensors_subfeature *sub;
113 struct stats_pwr_temp *st_pwr_temp_i;
117 memset(st_pwr_temp, 0, STATS_PWR_TEMP_SIZE);
120 while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
122 while ((feature = sensors_get_features(chip, &i))) {
123 if ((feature->type == SENSORS_FEATURE_TEMP) && (count < nbr)) {
125 st_pwr_temp_i = st_pwr_temp + count;
126 sensors_snprintf_chip_name(st_pwr_temp_i->device, MAX_SENSORS_DEV_LEN, chip);
128 while ((sub = sensors_get_all_subfeatures(chip, feature, &j))) {
129 if ((sub->type == SENSORS_SUBFEATURE_TEMP_INPUT) &&
130 (sub->flags & SENSORS_MODE_R)) {
131 if ((err = sensors_get_value(chip, sub->number, &st_pwr_temp_i->temp))) {
132 st_pwr_temp_i->temp = 0;
135 else if ((sub->type == SENSORS_SUBFEATURE_TEMP_MIN)) {
136 if ((err = sensors_get_value(chip, sub->number, &st_pwr_temp_i->temp_min))) {
137 st_pwr_temp_i->temp_min = 0;
140 else if ((sub->type == SENSORS_SUBFEATURE_TEMP_MAX)) {
141 if ((err = sensors_get_value(chip, sub->number, &st_pwr_temp_i->temp_max))) {
142 st_pwr_temp_i->temp_max = 0;
150 #endif /* HAVE_SENSORS */
154 ***************************************************************************
155 * Read voltage inputs statistics.
158 * @st_pwr_in Structure where stats will be saved.
159 * @nbr Total number of voltage inputs.
162 * @st_pwr_in Structure with statistics.
163 ***************************************************************************
165 void read_in(struct stats_pwr_in *st_pwr_in, int nbr)
169 const sensors_chip_name *chip;
170 const sensors_feature *feature;
171 const sensors_subfeature *sub;
172 struct stats_pwr_in *st_pwr_in_i;
176 memset(st_pwr_in, 0, STATS_PWR_IN_SIZE);
179 while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
181 while ((feature = sensors_get_features(chip, &i))) {
182 if ((feature->type == SENSORS_FEATURE_IN) && (count < nbr)) {
184 st_pwr_in_i = st_pwr_in + count;
185 sensors_snprintf_chip_name(st_pwr_in_i->device, MAX_SENSORS_DEV_LEN, chip);
187 while ((sub = sensors_get_all_subfeatures(chip, feature, &j))) {
188 if ((sub->type == SENSORS_SUBFEATURE_IN_INPUT) &&
189 (sub->flags & SENSORS_MODE_R)) {
190 if ((err = sensors_get_value(chip, sub->number, &st_pwr_in_i->in))) {
194 else if ((sub->type == SENSORS_SUBFEATURE_IN_MIN)) {
195 if ((err = sensors_get_value(chip, sub->number, &st_pwr_in_i->in_min))) {
196 st_pwr_in_i->in_min = 0;
199 else if ((sub->type == SENSORS_SUBFEATURE_IN_MAX)) {
200 if ((err = sensors_get_value(chip, sub->number, &st_pwr_in_i->in_max))) {
201 st_pwr_in_i->in_max = 0;
209 #endif /* HAVE_SENSORS */
214 ***************************************************************************
215 * Count the number of sensors of given type on the machine.
218 * @type Type of sensors.
222 ***************************************************************************
224 int get_sensors_nr(sensors_feature_type type) {
226 const sensors_chip_name *chip;
227 const sensors_feature *feature;
231 while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
233 while ((feature = sensors_get_features(chip, &i))) {
234 if (feature->type == type) {
242 #endif /* HAVE_SENSORS */
245 ***************************************************************************
246 * Count the number of fans on the machine.
250 ***************************************************************************
255 return get_sensors_nr(SENSORS_FEATURE_FAN);
258 #endif /* HAVE_SENSORS */
262 ***************************************************************************
263 * Count the number of temperature sensors on the machine.
266 * Number of temperature sensors.
267 ***************************************************************************
269 int get_temp_nr(void)
272 return get_sensors_nr(SENSORS_FEATURE_TEMP);
275 #endif /* HAVE_SENSORS */
280 ***************************************************************************
281 * Count the number of voltage inputs on the machine.
284 * Number of voltage inputs.
285 ***************************************************************************
290 return get_sensors_nr(SENSORS_FEATURE_IN);
293 #endif /* HAVE_SENSORS */