From: Florian Forster Date: Sun, 10 Feb 2019 20:50:51 +0000 (+0100) Subject: Merge branch 'collectd-5.8' X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=711f5b6c86f51061c21bedcaa46214a01de0125c;hp=e19d1f0affb0b68e11c9ed3448b3d5a663bb0049 Merge branch 'collectd-5.8' Conflicts: src/sensors.c --- diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index bb31e024..a38a9986 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -8397,26 +8397,26 @@ Sets how the values are cumulated. I is one of: =item B -Calculate the average. +Calculate the average of all values matched during the interval. =item B -Use the smallest number only. +Report the smallest value matched during the interval. =item B -Use the greatest number only. +Report the greatest value matched during the interval. =item B -Use the last number found. +Report the last value matched during the interval. =item B -Use the last number found. The number is not reset at the end of an interval. -It is continously reported until another number is matched. This is intended -for cases in which only state changes are reported, for example a thermometer -that only reports the temperature when it changes. +Report the last matching value. The metric is I reset to C at the end +of an interval. It is continuously reported until another value is matched. +This is intended for cases in which only state changes are reported, for +example a thermometer that only reports the temperature when it changes. =item B @@ -8447,6 +8447,9 @@ Increase the internal counter by one. These B are the only ones that do not use the matched subexpression, but simply count the number of matched lines. Thus, you may use a regular expression without submatch in this case. +B is reset to I after every read, unlike other B +metrics which are reset to C. + =item B Type to do calculations based on the distribution of values, primarily @@ -8520,8 +8523,12 @@ The B and B types interpret the submatch as a floating point number, using L. The B and B types interpret the submatch as an unsigned integer using L. The B types interpret the submatch as a signed integer using -L. B and B do not use the submatch at all -and it may be omitted in this case. +L. B, B and B do not use the +submatch at all and it may be omitted in this case. + +The B types, unless noted otherwise, are reset to C after being +reported. In other words, B reports the average of all values +matched since the last metric was reported (or C if there was no match). =item B I diff --git a/src/daemon/common.c b/src/daemon/common.c index 1775573a..b5a1c980 100644 --- a/src/daemon/common.c +++ b/src/daemon/common.c @@ -339,6 +339,9 @@ int strjoin(char *buffer, size_t buffer_size, char **fields, size_t fields_num, buffer_req += sep_len; buffer_req += field_len; + if (buffer_size == 0) + continue; + if ((i != 0) && (sep_len > 0)) { if (sep_len >= avail) { /* prevent subsequent iterations from writing to the diff --git a/src/daemon/common_test.c b/src/daemon/common_test.c index af2840e5..93a19d1b 100644 --- a/src/daemon/common_test.c +++ b/src/daemon/common_test.c @@ -168,10 +168,12 @@ DEF_TEST(strjoin) { cases[i].fields_num, cases[i].separator); EXPECT_EQ_INT(cases[i].want_return, status); EXPECT_EQ_STR(cases[i].want_buffer, buffer); - } - /* use (NULL, 0) to determine required buffer size. */ - EXPECT_EQ_INT(3, strjoin(NULL, 0, (char *[]){"a", "b"}, 2, "-")); + /* use (NULL, 0) to determine required buffer size. */ + EXPECT_EQ_INT(cases[i].want_return, + strjoin(NULL, 0, cases[i].fields, cases[i].fields_num, + cases[i].separator)); + } return 0; } diff --git a/src/log_logstash.c b/src/log_logstash.c index 8f3063f3..d115ae56 100644 --- a/src/log_logstash.c +++ b/src/log_logstash.c @@ -182,22 +182,14 @@ err: static void log_logstash_log(int severity, const char *msg, user_data_t __attribute__((unused)) * user_data) { - yajl_gen g; -#if !defined(HAVE_YAJL_V2) - yajl_gen_config conf = {}; - - conf.beautify = 0; -#endif - if (severity > log_level) return; #if HAVE_YAJL_V2 - g = yajl_gen_alloc(NULL); + yajl_gen g = yajl_gen_alloc(NULL); #else - g = yajl_gen_alloc(&conf, NULL); + yajl_gen g = yajl_gen_alloc(&(yajl_gen_config){0}, NULL); #endif - if (g == NULL) { fprintf(stderr, "Could not allocate JSON generator.\n"); return; diff --git a/src/sensors.c b/src/sensors.c index 0d4a400c..b800e98f 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -51,6 +51,21 @@ static const char *config_keys[] = {"Sensor", "IgnoreSelected", "SensorConfigFile", "UseLabels"}; static int config_keys_num = STATIC_ARRAY_SIZE(config_keys); +#if SENSORS_API_VERSION < 0x400 +typedef struct featurelist { + const sensors_chip_name *chip; + const sensors_feature_data *data; + int type; + struct featurelist *next; +} featurelist_t; + +#ifndef SENSORS_CONF_PATH +#define SENSORS_CONF_PATH "/etc/sensors.conf" +#endif +static char *conffile = SENSORS_CONF_PATH; +/* #endif SENSORS_API_VERSION < 0x400 */ + +#elif (SENSORS_API_VERSION >= 0x400) typedef struct featurelist { const sensors_chip_name *chip; const sensors_feature *feature; @@ -60,6 +75,7 @@ typedef struct featurelist { static char *conffile; static bool use_labels; +#endif static featurelist_t *first_feature; static ignorelist_t *sensor_list; @@ -87,9 +103,13 @@ static int sensors_config(const char *key, const char *value) { ignorelist_set_invert(sensor_list, 1); if (IS_TRUE(value)) ignorelist_set_invert(sensor_list, 0); - } else if (strcasecmp(key, "UseLabels") == 0) { + } +#if (SENSORS_API_VERSION >= 0x400) + else if (strcasecmp(key, "UseLabels") == 0) { use_labels = IS_TRUE(value); - } else { + } +#endif + else { return -1; } @@ -145,6 +165,74 @@ static int sensors_load_conf(void) { return -1; } +#if SENSORS_API_VERSION < 0x400 + chip_num = 0; + while ((chip = sensors_get_detected_chips(&chip_num)) != NULL) { + int feature_num0 = 0; + int feature_num1 = 0; + + while (42) { + const sensors_feature_data *feature; + int feature_type; + featurelist_t *fl; + + feature = sensors_get_all_features(*chip, &feature_num0, &feature_num1); + + /* Check if all features have been read. */ + if (feature == NULL) + break; + + /* "master features" only */ + if (feature->mapping != SENSORS_NO_MAPPING) { + DEBUG("sensors plugin: sensors_load_conf: " + "Ignoring subfeature `%s', " + "because (feature->mapping " + "!= SENSORS_NO_MAPPING).", + feature->name); + continue; + } + + /* skip ignored in sensors.conf */ + if (sensors_get_ignored(*chip, feature->number) == 0) { + DEBUG("sensors plugin: sensors_load_conf: " + "Ignoring subfeature `%s', " + "because " + "`sensors_get_ignored' told " + "me so.", + feature->name); + continue; + } + + feature_type = sensors_feature_name_to_type(feature->name); + if (feature_type == SENSOR_TYPE_UNKNOWN) { + DEBUG("sensors plugin: sensors_load_conf: " + "Ignoring subfeature `%s', " + "because its type is " + "unknown.", + feature->name); + continue; + } + + fl = calloc(1, sizeof(*fl)); + if (fl == NULL) { + ERROR("sensors plugin: calloc failed."); + continue; + } + + fl->chip = chip; + fl->data = feature; + fl->type = feature_type; + + if (first_feature == NULL) + first_feature = fl; + else + last_feature->next = fl; + last_feature = fl; + } /* while sensors_get_all_features */ + } /* while sensors_get_detected_chips */ +/* #endif SENSORS_API_VERSION < 0x400 */ + +#elif (SENSORS_API_VERSION >= 0x400) chip_num = 0; while ((chip = sensors_get_detected_chips(NULL, &chip_num)) != NULL) { const sensors_feature *feature; @@ -207,6 +295,7 @@ static int sensors_load_conf(void) { } /* while (subfeature) */ } /* while (feature) */ } /* while (chip) */ +#endif /* (SENSORS_API_VERSION >= 0x400) */ if (first_feature == NULL) { sensors_cleanup(); @@ -258,6 +347,30 @@ static int sensors_read(void) { if (sensors_load_conf() != 0) return -1; +#if SENSORS_API_VERSION < 0x400 + 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]; + + status = sensors_get_feature(*fl->chip, fl->data->number, &value); + if (status < 0) + continue; + + status = sensors_snprintf_chip_name(plugin_instance, + sizeof(plugin_instance), fl->chip); + if (status < 0) + continue; + + sstrncpy(type_instance, fl->data->name, sizeof(type_instance)); + + sensors_submit(plugin_instance, sensor_type_name_map[fl->type], + type_instance, value); + } /* for fl = first_feature .. NULL */ +/* #endif SENSORS_API_VERSION < 0x400 */ + +#elif (SENSORS_API_VERSION >= 0x400) for (featurelist_t *fl = first_feature; fl != NULL; fl = fl->next) { double value; int status; @@ -304,6 +417,7 @@ static int sensors_read(void) { sensors_submit(plugin_instance, type, type_instance, value); } /* for fl = first_feature .. NULL */ +#endif /* (SENSORS_API_VERSION >= 0x400) */ return 0; } /* int sensors_read */ diff --git a/src/write_prometheus.c b/src/write_prometheus.c index 53a07095..3b32ac09 100644 --- a/src/write_prometheus.c +++ b/src/write_prometheus.c @@ -760,7 +760,12 @@ static int prom_open_socket(int addrfamily) { int fd = -1; for (struct addrinfo *ai = res; ai != NULL; ai = ai->ai_next) { - fd = socket(ai->ai_family, ai->ai_socktype | SOCK_CLOEXEC, 0); + int flags = ai->ai_socktype; +#ifdef SOCK_CLOEXEC + flags |= SOCK_CLOEXEC; +#endif + + fd = socket(ai->ai_family, flags, 0); if (fd == -1) continue;