*
* Authors:
* Florian octo Forster <octo at collectd.org>
- *
+ *
* Lubos Stanek <lubek at users.sourceforge.net> Wed Oct 27, 2006
* - config ExtendedSensorNaming option
* - precise sensor feature selection (chip-bus-address/type-feature)
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#include "utils_ignorelist.h"
#if defined(HAVE_SENSORS_SENSORS_H)
typedef struct sensors_labeltypes_s sensors_labeltypes_t;
/* finite list of known labels extracted from lm_sensors */
-static sensors_labeltypes_t known_features[] =
+static sensors_labeltypes_t known_features[] =
{
{ "fan1", SENSOR_TYPE_FANSPEED },
{ "fan2", SENSOR_TYPE_FANSPEED },
{
"Sensor",
"IgnoreSelected",
- "SensorConfigFile"
+ "SensorConfigFile",
+ "UseLabels"
};
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
} featurelist_t;
static char *conffile = NULL;
+static _Bool use_labels = 0;
/* #endif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500) */
#else /* if SENSORS_API_VERSION >= 0x500 */
"as bug."
#endif
-featurelist_t *first_feature = NULL;
+static featurelist_t *first_feature = NULL;
static ignorelist_t *sensor_list;
#if SENSORS_API_VERSION < 0x400
static int sensors_feature_name_to_type (const char *name)
{
- int i;
-
/* Yes, this is slow, but it's only ever done during initialization, so
* it's a one time cost.. */
- for (i = 0; i < known_features_num; i++)
+ for (int i = 0; i < known_features_num; i++)
if (strcasecmp (known_features[i].label, name) == 0)
return (known_features[i].type);
if (IS_TRUE (value))
ignorelist_set_invert (sensor_list, 0);
}
+#if (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500)
+ else if (strcasecmp (key, "UseLabels") == 0)
+ {
+ use_labels = IS_TRUE (value) ? 1 : 0;
+ }
+#endif
else
{
return (-1);
static void sensors_free_features (void)
{
- featurelist_t *thisft;
featurelist_t *nextft;
if (first_feature == NULL)
sensors_cleanup ();
- for (thisft = first_feature; thisft != NULL; thisft = nextft)
+ for (featurelist_t *thisft = first_feature; thisft != NULL; thisft = nextft)
{
nextft = thisft->next;
sfree (thisft);
FILE *fh = NULL;
featurelist_t *last_feature = NULL;
-
+
const sensors_chip_name *chip;
int chip_num;
continue;
}
- fl = (featurelist_t *) malloc (sizeof (featurelist_t));
+ fl = calloc (1, sizeof (*fl));
if (fl == NULL)
{
- ERROR ("sensors plugin: malloc failed.");
+ ERROR ("sensors plugin: calloc failed.");
continue;
}
- memset (fl, '\0', sizeof (featurelist_t));
fl->chip = chip;
fl->data = feature;
&& (subfeature->type != SENSORS_SUBFEATURE_POWER_INPUT))
continue;
- fl = (featurelist_t *) malloc (sizeof (featurelist_t));
+ fl = calloc (1, sizeof (*fl));
if (fl == NULL)
{
- ERROR ("sensors plugin: malloc failed.");
+ ERROR ("sensors plugin: calloc failed.");
continue;
}
- memset (fl, '\0', sizeof (featurelist_t));
fl->chip = chip;
fl->feature = feature;
static void sensors_submit (const char *plugin_instance,
const char *type, const char *type_instance,
- double val)
+ double value)
{
char match_key[1024];
int status;
- value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
status = ssnprintf (match_key, sizeof (match_key), "%s/%s-%s",
return;
}
- values[0].gauge = val;
-
- vl.values = values;
+ vl.values = &(value_t) { .gauge = value };
vl.values_len = 1;
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
static int sensors_read (void)
{
- featurelist_t *fl;
-
if (sensors_load_conf () != 0)
return (-1);
#if SENSORS_API_VERSION < 0x400
- for (fl = first_feature; fl != NULL; fl = fl->next)
+ for (featurelist_t *fl = first_feature; fl != NULL; fl = fl->next)
{
double value;
int status;
/* #endif SENSORS_API_VERSION < 0x400 */
#elif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500)
- for (fl = first_feature; fl != NULL; fl = fl->next)
+ for (featurelist_t *fl = first_feature; fl != NULL; fl = fl->next)
{
double value;
int status;
char plugin_instance[DATA_MAX_NAME_LEN];
char type_instance[DATA_MAX_NAME_LEN];
+ char *sensor_label;
const char *type;
status = sensors_get_value (fl->chip,
if (status < 0)
continue;
- sstrncpy (type_instance, fl->feature->name,
- sizeof (type_instance));
+ if (use_labels)
+ {
+ sensor_label = sensors_get_label (fl->chip, fl->feature);
+ sstrncpy (type_instance, sensor_label, sizeof (type_instance));
+ free (sensor_label);
+ }
+ else
+ {
+ sstrncpy (type_instance, fl->feature->name,
+ sizeof (type_instance));
+ }
if (fl->feature->type == SENSORS_FEATURE_IN)
type = "voltage";