Merge remote-tracking branch 'origin/pr/1239'
authorMarc Fournier <marc.fournier@camptocamp.com>
Fri, 22 Apr 2016 20:22:44 +0000 (22:22 +0200)
committerMarc Fournier <marc.fournier@camptocamp.com>
Fri, 22 Apr 2016 20:22:44 +0000 (22:22 +0200)
src/collectd.conf.pod
src/sensors.c

index c72d64a..43dfeae 100644 (file)
@@ -6148,6 +6148,12 @@ few ones. This option enables you to do that: By setting B<IgnoreSelected> to
 I<true> the effect of B<Sensor> is inverted: All selected sensors are ignored
 and all other sensors are collected.
 
+=item B<UseLabels> I<true>|I<false>
+
+Configures how sensor readings are reported. When set to I<true>, sensor
+readings are reported using their descriptive label (e.g. "VCore"). When set to
+I<false> (the default) the sensor name is used ("in0").
+
 =back
 
 =head2 Plugin C<sigrok>
index 852b41c..63a1c8e 100644 (file)
@@ -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);
@@ -553,6 +561,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,
@@ -565,8 +574,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";