X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_latency_config.c;h=9a91f113da4b8c75c195ced04a03d31c852e6fc2;hb=7c9d772c992647fcba64a96800c146eb9f1647f8;hp=674e2752039cf9163e36a15ef3bf43b5fab0ed04;hpb=e4504c3cc5582ab915903e1b4ba010545ffc8354;p=collectd.git diff --git a/src/utils_latency_config.c b/src/utils_latency_config.c index 674e2752..9a91f113 100644 --- a/src/utils_latency_config.c +++ b/src/utils_latency_config.c @@ -25,29 +25,28 @@ * Pavel Rochnyack */ +#include "collectd.h" #include "common.h" #include "utils_latency_config.h" -#include "collectd.h" static int latency_config_add_percentile(latency_config_t *conf, - oconfig_item_t *ci, - const char *plugin) { + oconfig_item_t *ci) { double percent; int status = cf_util_get_double(ci, &percent); if (status != 0) return status; if ((percent <= 0.0) || (percent >= 100)) { - ERROR("%s plugin: The value for \"%s\" must be between 0 and 100, " - "exclusively.", - plugin, ci->key); + P_ERROR("The value for \"%s\" must be between 0 and 100, " + "exclusively.", + ci->key); return ERANGE; } double *tmp = realloc(conf->percentile, sizeof(*conf->percentile) * (conf->percentile_num + 1)); if (tmp == NULL) { - ERROR("%s plugin: realloc failed.", plugin); + P_ERROR("realloc failed."); return ENOMEM; } conf->percentile = tmp; @@ -57,31 +56,29 @@ static int latency_config_add_percentile(latency_config_t *conf, return 0; } /* int latency_config_add_percentile */ -static int latency_config_add_bucket(latency_config_t *conf, oconfig_item_t *ci, - const char *plugin) { +static int latency_config_add_bucket(latency_config_t *conf, + oconfig_item_t *ci) { if ((ci->values_num != 2) || (ci->values[0].type != OCONFIG_TYPE_NUMBER) || (ci->values[1].type != OCONFIG_TYPE_NUMBER)) { - ERROR("%s plugin: \"%s\" requires exactly two numeric arguments.", plugin, - ci->key); + P_ERROR("\"%s\" requires exactly two numeric arguments.", ci->key); return EINVAL; } if (ci->values[1].value.number && ci->values[1].value.number <= ci->values[0].value.number) { - ERROR("%s plugin: MIN must be less than MAX in \"%s\".", plugin, ci->key); + P_ERROR("MIN must be less than MAX in \"%s\".", ci->key); return ERANGE; } if (ci->values[0].value.number < 0) { - ERROR("%s plugin: MIN must be greater then or equal to zero in \"%s\".", - plugin, ci->key); + P_ERROR("MIN must be greater then or equal to zero in \"%s\".", ci->key); return ERANGE; } latency_bucket_t *tmp = realloc(conf->buckets, sizeof(*conf->buckets) * (conf->buckets_num + 1)); if (tmp == NULL) { - ERROR("%s plugin: realloc failed.", plugin); + P_ERROR("realloc failed."); return ENOMEM; } conf->buckets = tmp; @@ -91,23 +88,24 @@ static int latency_config_add_bucket(latency_config_t *conf, oconfig_item_t *ci, DOUBLE_TO_CDTIME_T(ci->values[1].value.number); conf->buckets_num++; - return (0); + return 0; } /* int latency_config_add_bucket */ -int latency_config(latency_config_t *conf, oconfig_item_t *ci, - char const *plugin) { +int latency_config(latency_config_t *conf, oconfig_item_t *ci) { int status = 0; for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp("Percentile", child->key) == 0) - status = latency_config_add_percentile(conf, child, plugin); + status = latency_config_add_percentile(conf, child); else if (strcasecmp("Bucket", child->key) == 0) - status = latency_config_add_bucket(conf, child, plugin); + status = latency_config_add_bucket(conf, child); + else if (strcasecmp("BucketType", child->key) == 0) + status = cf_util_get_string(child, &conf->bucket_type); else - WARNING("%s plugin: \"%s\" is not a valid option within a \"%s\" block.", - plugin, child->key, ci->key); + P_WARNING("\"%s\" is not a valid option within a \"%s\" block.", + child->key, ci->key); if (status != 0) return status; @@ -115,9 +113,9 @@ int latency_config(latency_config_t *conf, oconfig_item_t *ci, if ((status == 0) && (conf->percentile_num == 0) && (conf->buckets_num == 0)) { - ERROR("%s plugin: The \"%s\" block must contain at least one " - "\"Percentile\" or \"Bucket\" option.", - plugin, ci->key); + P_ERROR("The \"%s\" block must contain at least one " + "\"Percentile\" or \"Bucket\" option.", + ci->key); return EINVAL; } @@ -137,6 +135,14 @@ int latency_config_copy(latency_config_t *dst, const latency_config_t src) { return ENOMEM; } + if (src.bucket_type != NULL) { + dst->bucket_type = strdup(src.bucket_type); + if (dst->bucket_type == NULL) { + latency_config_free(*dst); + return ENOMEM; + } + } + memmove(dst->percentile, src.percentile, dst->percentile_num * sizeof(*dst->percentile)); memmove(dst->buckets, src.buckets, dst->buckets_num * sizeof(*dst->buckets)); @@ -147,4 +153,5 @@ int latency_config_copy(latency_config_t *dst, const latency_config_t src) { void latency_config_free(latency_config_t conf) { sfree(conf.percentile); sfree(conf.buckets); + sfree(conf.bucket_type); } /* void latency_config_free */