From 8ed3735980de12f32dd488d0d285d108f098836e Mon Sep 17 00:00:00 2001 From: Christian Fetzer Date: Mon, 24 Aug 2015 09:49:21 +0200 Subject: [PATCH] sensors: Report sensor readings by descriptive labels Adds an option UseLabels to configure how sensor readings are reported. The default reports readings using the sensor name (e.g. "in0"). With this option set to true, the readings are reported using the label (e.g. "VCore"). --- src/collectd.conf.pod | 6 ++++++ src/sensors.c | 24 +++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index aaeeaf41..78a348b3 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -6031,6 +6031,12 @@ few ones. This option enables you to do that: By setting B to I the effect of B is inverted: All selected sensors are ignored and all other sensors are collected. +=item B I|I + +Configures how sensor readings are reported. When set to I, sensor +readings are reported using their descriptive label (e.g. "VCore"). When set to +I (the default) the sensor name is used ("in0"). + =back =head2 Plugin C diff --git a/src/sensors.c b/src/sensors.c index f5b09bd2..2f3695f2 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -140,7 +140,8 @@ static const char *config_keys[] = { "Sensor", "IgnoreSelected", - "SensorConfigFile" + "SensorConfigFile", + "UseLabels" }; static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); @@ -169,6 +170,7 @@ typedef struct featurelist } 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 */ @@ -257,6 +259,12 @@ static int sensors_config (const char *key, const char *value) 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); @@ -555,6 +563,7 @@ static int sensors_read (void) 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, @@ -567,8 +576,17 @@ static int sensors_read (void) 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"; -- 2.30.2