X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsensors.c;h=fde8dcd7ec00e2a93e6d4826a92d0d67775c9cc5;hb=7e5df1a2c6611bd4ac9fb8ac4b78106f9139ae6e;hp=551d267ca2da0c5d4fdb00eda24b4da404393ca2;hpb=dc80c73c20ef0e69c3850fd9679a827ad79e61a1;p=collectd.git diff --git a/src/sensors.c b/src/sensors.c index 551d267c..fde8dcd7 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -46,36 +46,6 @@ # define SENSORS_HAVE_READ 0 #endif -static data_source_t data_source_fanspeed[1] = -{ - {"value", DS_TYPE_GAUGE, 0, NAN} -}; - -static data_set_t fanspeed_ds = -{ - "fanspeed", 1, data_source_fanspeed -}; - -static data_source_t data_source_temperature[1] = -{ - {"value", DS_TYPE_GAUGE, -273.15, NAN} -}; - -static data_set_t temperature_ds = -{ - "temperature", 1, data_source_temperature -}; - -static data_source_t data_source_voltage[1] = -{ - {"value", DS_TYPE_GAUGE, NAN, NAN} -}; - -static data_set_t voltage_ds = -{ - "voltage", 1, data_source_voltage -}; - #if SENSORS_HAVE_READ #define SENSOR_TYPE_VOLTAGE 0 #define SENSOR_TYPE_FANSPEED 1 @@ -238,7 +208,7 @@ void sensors_free_features (void) first_feature = NULL; } -static void sensors_load_conf (void) +static int sensors_load_conf (void) { FILE *fh; featurelist_t *last_feature = NULL; @@ -264,7 +234,7 @@ static void sensors_load_conf (void) if ((sensors_config_mtime != 0) && (sensors_config_mtime == statbuf.st_mtime)) - return; + return (0); if (sensors_config_mtime != 0) { @@ -280,7 +250,7 @@ static void sensors_load_conf (void) char errbuf[1024]; ERROR ("sensors plugin: fopen(%s) failed: %s", conffile, sstrerror (errno, errbuf, sizeof (errbuf))); - return; + return (-1); } status = sensors_init (fh); @@ -289,7 +259,7 @@ static void sensors_load_conf (void) { ERROR ("sensors plugin: Cannot initialize sensors. " "Data will not be collected."); - return; + return (-1); } sensors_config_mtime = statbuf.st_mtime; @@ -359,8 +329,11 @@ static void sensors_load_conf (void) sensors_cleanup (); INFO ("sensors plugin: lm_sensors reports no " "features. Data will not be collected."); + return (-1); } -} /* void sensors_load_conf */ + + return (0); +} /* int sensors_load_conf */ static int sensors_shutdown (void) { @@ -374,12 +347,24 @@ static void sensors_submit (const char *plugin_instance, const char *type, const char *type_instance, double val) { + char match_key[1024]; + int status; + value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - if ((sensor_list != NULL) - && (ignorelist_match (sensor_list, type_instance))) + status = snprintf (match_key, sizeof (match_key), "%s/%s-%s", + plugin_instance, type, type_instance); + if ((status < 1) || (status >= sizeof (match_key))) return; + match_key[sizeof (match_key) - 1] = '\0'; + + if (sensor_list != NULL) + { + DEBUG ("sensors plugin: Checking ignorelist for `%s'", match_key); + if (ignorelist_match (sensor_list, match_key)) + return; + } values[0].gauge = val; @@ -402,7 +387,8 @@ static int sensors_read (void) char plugin_instance[DATA_MAX_NAME_LEN]; char type_instance[DATA_MAX_NAME_LEN]; - sensors_load_conf (); + if (sensors_load_conf () != 0) + return (-1); for (feature = first_feature; feature != NULL; feature = feature->next) { @@ -449,22 +435,12 @@ static int sensors_read (void) } /* int sensors_read */ #endif /* SENSORS_HAVE_READ */ -void module_register (modreg_e load) +void module_register (void) { - if (load & MR_DATASETS) - { - plugin_register_data_set (&fanspeed_ds); - plugin_register_data_set (&temperature_ds); - plugin_register_data_set (&voltage_ds); - } - #if SENSORS_HAVE_READ - if (load & MR_READ) - { - plugin_register_config ("sensors", sensors_config, - config_keys, config_keys_num); - plugin_register_read ("sensors", sensors_read); - plugin_register_shutdown ("sensors", sensors_shutdown); - } + plugin_register_config ("sensors", sensors_config, + config_keys, config_keys_num); + plugin_register_read ("sensors", sensors_read); + plugin_register_shutdown ("sensors", sensors_shutdown); #endif } /* void module_register */