~ubuntu-branches/ubuntu/oneiric/sysstat/oneiric

« back to all changes in this revision

Viewing changes to rd_sensors.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Luberda
  • Date: 2011-03-23 13:26:07 UTC
  • mfrom: (1.1.20 upstream) (2.1.12 sid)
  • Revision ID: james.westby@ubuntu.com-20110323132607-huhxd19s8ts5muq7
Tags: 10.0.0-1
* New upstream (stable) release:
  + Don't link sysstat's commands with sensors library if not
    needed (closes: #612571).
  + [Adam Heath]: iostat incorrectly mapped device-mapper IDs
    greater than 256. This is now fixed (closes: #614397).
* debian/rules: switch to using dh command.
* Remove 07-remove_fdatasync.patch, no longer needed. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * rd_sensors.c: Read sensors statistics
 
3
 * (C) 1999-2011 by Sebastien GODARD (sysstat <at> orange.fr)
 
4
 *
 
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.                                              *
 
10
 *                                                                         *
 
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 *
 
14
 * for more details.                                                       *
 
15
 *                                                                         *
 
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
 ***************************************************************************
 
20
 */
 
21
 
 
22
#include <stdio.h>
 
23
#include <string.h>
 
24
 
 
25
#include "common.h"
 
26
#include "rd_sensors.h"
 
27
 
 
28
#ifdef USE_NLS
 
29
#include <locale.h>
 
30
#include <libintl.h>
 
31
#define _(string) gettext(string)
 
32
#else
 
33
#define _(string) (string)
 
34
#endif
 
35
 
 
36
#ifdef HAVE_SENSORS
 
37
#include "sensors/sensors.h"
 
38
#endif
 
39
 
 
40
/*
 
41
 ***************************************************************************
 
42
 * Read fan statistics.
 
43
 *
 
44
 * IN:
 
45
 * @st_pwr_fan  Structure where stats will be saved.
 
46
 * @nbr         Total number of fans.
 
47
 *
 
48
 * OUT:
 
49
 * @st_pwr_fan Structure with statistics.
 
50
 ***************************************************************************
 
51
 */
 
52
void read_fan(struct stats_pwr_fan *st_pwr_fan, int nbr)
 
53
{
 
54
#ifdef HAVE_SENSORS
 
55
        int count = 0;
 
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;
 
60
        int chip_nr = 0;
 
61
        int i, j;
 
62
 
 
63
        memset(st_pwr_fan, 0, STATS_PWR_FAN_SIZE);
 
64
        int err = 0;
 
65
 
 
66
        while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
 
67
                i = 0;
 
68
                while ((feature = sensors_get_features(chip, &i))) {
 
69
                        if ((feature->type == SENSORS_FEATURE_FAN) && (count < nbr)) {
 
70
                                j = 0;
 
71
                                st_pwr_fan_i = st_pwr_fan + count;
 
72
                                sensors_snprintf_chip_name(st_pwr_fan_i->device, MAX_SENSORS_DEV_LEN, chip);
 
73
                                
 
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;
 
79
                                                }
 
80
                                        }
 
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;
 
84
                                                }
 
85
                                        }
 
86
                                }
 
87
                                count++;
 
88
                        }
 
89
                }
 
90
        }
 
91
#endif /* HAVE_SENSORS */
 
92
}
 
93
 
 
94
/*
 
95
 ***************************************************************************
 
96
 * Read device temperature statistics.
 
97
 *
 
98
 * IN:
 
99
 * @st_pwr_temp Structure where stats will be saved.
 
100
 * @nbr         Total number of fans.
 
101
 *
 
102
 * OUT:
 
103
 * @st_pwr_temp Structure with statistics.
 
104
 ***************************************************************************
 
105
 */
 
106
void read_temp(struct stats_pwr_temp *st_pwr_temp, int nbr)
 
107
{
 
108
#ifdef HAVE_SENSORS
 
109
        int count = 0;
 
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;
 
114
        int chip_nr = 0;
 
115
        int i, j;
 
116
 
 
117
        memset(st_pwr_temp, 0, STATS_PWR_TEMP_SIZE);
 
118
        int err = 0;
 
119
 
 
120
        while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
 
121
                i = 0;
 
122
                while ((feature = sensors_get_features(chip, &i))) {
 
123
                        if ((feature->type == SENSORS_FEATURE_TEMP) && (count < nbr)) {
 
124
                                j = 0;
 
125
                                st_pwr_temp_i = st_pwr_temp + count;
 
126
                                sensors_snprintf_chip_name(st_pwr_temp_i->device, MAX_SENSORS_DEV_LEN, chip);
 
127
                                
 
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;
 
133
                                                }
 
134
                                        }
 
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;
 
138
                                                }
 
139
                                        }
 
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;
 
143
                                                }
 
144
                                        }
 
145
                                }
 
146
                                count++;
 
147
                        }
 
148
                }
 
149
        }
 
150
#endif /* HAVE_SENSORS */
 
151
}
 
152
 
 
153
/*
 
154
 ***************************************************************************
 
155
 * Read voltage inputs statistics.
 
156
 *
 
157
 * IN:
 
158
 * @st_pwr_in   Structure where stats will be saved.
 
159
 * @nbr         Total number of voltage inputs.
 
160
 *
 
161
 * OUT:
 
162
 * @st_pwr_in   Structure with statistics.
 
163
 ***************************************************************************
 
164
 */
 
165
void read_in(struct stats_pwr_in *st_pwr_in, int nbr)
 
166
{
 
167
#ifdef HAVE_SENSORS
 
168
        int count = 0;
 
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;
 
173
        int chip_nr = 0;
 
174
        int i, j;
 
175
 
 
176
        memset(st_pwr_in, 0, STATS_PWR_IN_SIZE);
 
177
        int err = 0;
 
178
 
 
179
        while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
 
180
                i = 0;
 
181
                while ((feature = sensors_get_features(chip, &i))) {
 
182
                        if ((feature->type == SENSORS_FEATURE_IN) && (count < nbr)) {
 
183
                                j = 0;
 
184
                                st_pwr_in_i = st_pwr_in + count;
 
185
                                sensors_snprintf_chip_name(st_pwr_in_i->device, MAX_SENSORS_DEV_LEN, chip);
 
186
 
 
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))) {
 
191
                                                        st_pwr_in_i->in = 0;
 
192
                                                }
 
193
                                        }
 
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;
 
197
                                                }
 
198
                                        }
 
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;
 
202
                                                }
 
203
                                        }
 
204
                                }
 
205
                                count++;
 
206
                        }
 
207
                }
 
208
        }
 
209
#endif /* HAVE_SENSORS */
 
210
}
 
211
 
 
212
#ifdef HAVE_SENSORS
 
213
/*
 
214
 ***************************************************************************
 
215
 * Count the number of sensors of given type on the machine.
 
216
 *
 
217
 * IN:
 
218
 * @type        Type of sensors.
 
219
 *
 
220
 * RETURNS:
 
221
 * Number of sensors.
 
222
 ***************************************************************************
 
223
 */
 
224
int get_sensors_nr(sensors_feature_type type) {
 
225
        int count = 0;
 
226
        const sensors_chip_name *chip;
 
227
        const sensors_feature *feature;
 
228
        int chip_nr = 0;
 
229
        int i;
 
230
 
 
231
        while ((chip = sensors_get_detected_chips(NULL, &chip_nr))) {
 
232
                i = 0;
 
233
                while ((feature = sensors_get_features(chip, &i))) {
 
234
                        if (feature->type == type) {
 
235
                                count++;
 
236
                        }
 
237
                }
 
238
        }
 
239
 
 
240
        return count;
 
241
}
 
242
#endif /* HAVE_SENSORS */
 
243
 
 
244
/*
 
245
 ***************************************************************************
 
246
 * Count the number of fans on the machine.
 
247
 *
 
248
 * RETURNS:
 
249
 * Number of fans.
 
250
 ***************************************************************************
 
251
 */
 
252
int get_fan_nr(void)
 
253
{
 
254
#ifdef HAVE_SENSORS
 
255
        return get_sensors_nr(SENSORS_FEATURE_FAN);
 
256
#else
 
257
        return 0;
 
258
#endif /* HAVE_SENSORS */
 
259
}
 
260
 
 
261
/*
 
262
 ***************************************************************************
 
263
 * Count the number of temperature sensors on the machine.
 
264
 *
 
265
 * RETURNS:
 
266
 * Number of temperature sensors.
 
267
 ***************************************************************************
 
268
 */
 
269
int get_temp_nr(void)
 
270
{
 
271
#ifdef HAVE_SENSORS
 
272
        return get_sensors_nr(SENSORS_FEATURE_TEMP);
 
273
#else
 
274
        return 0;
 
275
#endif /* HAVE_SENSORS */
 
276
 
 
277
}
 
278
 
 
279
/*
 
280
 ***************************************************************************
 
281
 * Count the number of voltage inputs on the machine.
 
282
 *
 
283
 * RETURNS:
 
284
 * Number of voltage inputs.
 
285
 ***************************************************************************
 
286
 */
 
287
int get_in_nr(void)
 
288
{
 
289
#ifdef HAVE_SENSORS
 
290
        return get_sensors_nr(SENSORS_FEATURE_IN);
 
291
#else
 
292
        return 0;
 
293
#endif /* HAVE_SENSORS */
 
294
 
 
295
}