From: Florian Forster Date: Fri, 17 Jul 2020 11:08:51 +0000 (+0200) Subject: Various: s/metric_t/metric_single_t/g X-Git-Tag: 6.0.0-rc0~144^2~71 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1182ac6f168cc921f0fa3e73d834bc7f3d3ea821;p=thirdparty%2Fcollectd.git Various: s/metric_t/metric_single_t/g --- diff --git a/src/aggregation.c b/src/aggregation.c index 23d259caa..c3e9c5299 100644 --- a/src/aggregation.c +++ b/src/aggregation.c @@ -715,12 +715,12 @@ static int agg_read(void) /* {{{ */ return (success > 0) ? 0 : -1; } /* }}} int agg_read */ -static int agg_write(metric_t const *metric_p, /* {{{ */ +static int agg_write(metric_single_t const *m, /* {{{ */ __attribute__((unused)) user_data_t *user_data) { bool created_by_aggregation = false; /* Ignore values that were created by the aggregation plugin to avoid weird * effects. */ - (void)meta_data_get_boolean(metric_p->meta->meta, "aggregation:created", + (void)meta_data_get_boolean(m->meta->meta, "aggregation:created", &created_by_aggregation); if (created_by_aggregation) return 0; @@ -730,7 +730,7 @@ static int agg_write(metric_t const *metric_p, /* {{{ */ if (lookup == NULL) status = ENOENT; else { - status = lookup_search(lookup, metric_p); + status = lookup_search(lookup, m); if (status > 0) status = 0; } diff --git a/src/amqp.c b/src/amqp.c index 8405bc027..91c11ffa7 100644 --- a/src/amqp.c +++ b/src/amqp.c @@ -29,9 +29,9 @@ #include "collectd.h" #include "plugin.h" +#include "utils/avltree/avltree.h" #include "utils/cmds/putval.h" #include "utils/common/common.h" -#include "utils/avltree/avltree.h" #include "utils/format_graphite/format_graphite.h" #include "utils/format_json/format_json.h" #include "utils_random.h" @@ -788,7 +788,7 @@ static int camqp_write_locked(camqp_config_t *conf, /* {{{ */ return status; } /* }}} int camqp_write_locked */ -static int camqp_write(const metric_t *metric_p, /* {{{ */ +static int camqp_write(metric_single_t const *m, /* {{{ */ user_data_t *user_data) { camqp_config_t *conf = user_data->data; char routing_key[6 * DATA_MAX_NAME_LEN]; @@ -796,7 +796,7 @@ static int camqp_write(const metric_t *metric_p, /* {{{ */ int status; char *index_p = (char *)&buffer[0]; - if ((metric_p == NULL) || (metric_p->ds == NULL) || (conf == NULL)) + if ((m == NULL) || (metric_p->ds == NULL) || (conf == NULL)) return EINVAL; if (conf->routing_key != NULL) { @@ -804,15 +804,15 @@ static int camqp_write(const metric_t *metric_p, /* {{{ */ } else { int buffer_size = sizeof(routing_key); int tmp_str_len = 0; - tmp_str_len = strlen(metric_p->identity->name); + tmp_str_len = strlen(m->identity->name); if (tmp_str_len < buffer_size) { - snprintf(index_p, tmp_str_len + 1, "%s", metric_p->identity->name); + snprintf(index_p, tmp_str_len + 1, "%s", m->identity->name); index_p += tmp_str_len; /* This is the location of the trailing nul */ buffer_size -= tmp_str_len; } - if (metric_p->identity->root_p != NULL) { - c_avl_iterator_t *iter_p = c_avl_get_iterator(metric_p->identity->root_p); + if (m->identity->root_p != NULL) { + c_avl_iterator_t *iter_p = c_avl_get_iterator(m->identity->root_p); if (iter_p != NULL) { char *key_p = NULL; char *value_p = NULL; @@ -826,8 +826,8 @@ static int camqp_write(const metric_t *metric_p, /* {{{ */ buffer_size -= tmp_str_len; } else { snprintf(index_p, buffer_size, ";%s", value_p); - buffer_size = 0; - break; + buffer_size = 0; + break; } } } @@ -846,7 +846,7 @@ static int camqp_write(const metric_t *metric_p, /* {{{ */ } if (conf->format == CAMQP_FORMAT_COMMAND) { - status = cmd_create_putval(buffer, sizeof(buffer), metric_p); + status = cmd_create_putval(buffer, sizeof(buffer), m); if (status != 0) { ERROR("amqp plugin: cmd_create_putval failed with status %i.", status); return status; @@ -856,12 +856,12 @@ static int camqp_write(const metric_t *metric_p, /* {{{ */ size_t bfill = 0; format_json_initialize(buffer, &bfill, &bfree); - format_json_metric(buffer, &bfill, &bfree, metric_p, conf->store_rates); + format_json_metric(buffer, &bfill, &bfree, m, conf->store_rates); format_json_finalize(buffer, &bfill, &bfree); } else if (conf->format == CAMQP_FORMAT_GRAPHITE) { status = - format_graphite(buffer, sizeof(buffer), metric_p, conf->prefix, - conf->postfix, conf->escape_char, conf->graphite_flags); + format_graphite(buffer, sizeof(buffer), m, conf->prefix, conf->postfix, + conf->escape_char, conf->graphite_flags); if (status != 0) { ERROR("amqp plugin: format_graphite failed with status %i.", status); return status; diff --git a/src/amqp1.c b/src/amqp1.c index 20e7cc543..67ac5fca9 100644 --- a/src/amqp1.c +++ b/src/amqp1.c @@ -430,7 +430,7 @@ static int amqp1_notify(notification_t const *n, } /* }}} int amqp1_notify */ -static int amqp1_write(const metric_t *metric_p, /* {{{ */ +static int amqp1_write(metric_single_t const *m, /* {{{ */ user_data_t *user_data) { int status = 0; size_t bfree = BUFSIZE; @@ -479,8 +479,8 @@ static int amqp1_write(const metric_t *metric_p, /* {{{ */ break; case AMQP1_FORMAT_JSON: format_json_initialize((char *)cdm->mbuf.start, &bfill, &bfree); - format_json_metric((char *)cdm->mbuf.start, &bfill, &bfree, metric_p, - instance->store_rates); + format_json_metric((char *)cdm->mbuf.start, &bfill, &bfree, m, + instance->store_rates); status = format_json_finalize((char *)cdm->mbuf.start, &bfill, &bfree); if (status != 0) { ERROR("amqp1 plugin: format_json_finalize failed with status %i.", diff --git a/src/check_uptime.c b/src/check_uptime.c index e877505bc..dd7dc1a28 100644 --- a/src/check_uptime.c +++ b/src/check_uptime.c @@ -54,19 +54,20 @@ static int format_uptime(unsigned long uptime_sec, char *buf, size_t bufsize) { return ret; } -static int cu_notify(enum cache_event_type_e event_type, const metric_t *metric_p, - gauge_t old_uptime, gauge_t new_uptime) { +static int cu_notify(enum cache_event_type_e event_type, + metric_single_t const *m, gauge_t old_uptime, + gauge_t new_uptime) { notification_t n; - notification_init_metric(&n, NOTIF_FAILURE, NULL, metric_p); + notification_init_metric(&n, NOTIF_FAILURE, NULL, m); int status; char *buf = n.message; size_t bufsize = sizeof(n.message); - n.time = metric_p->time; + n.time = m->time; const char *service = "Service"; - if (strcmp(metric_p->plugin, "uptime") == 0) + if (strcmp(m->plugin, "uptime") == 0) service = "Host"; switch (event_type) { @@ -132,10 +133,10 @@ static int cu_cache_event(cache_event_t *event, switch (event->type) { case CE_VALUE_NEW: DEBUG("check_uptime: CE_VALUE_NEW, %s", event->value_list_name); - if (c_avl_get(types_tree, event->metric_p->type, NULL) == 0) { + if (c_avl_get(types_tree, event->m->type, NULL) == 0) { event->ret = 1; - cu_notify(CE_VALUE_NEW, event->metric_p, NAN /* old */, - event->metric_p->value.gauge /* new */); + cu_notify(CE_VALUE_NEW, event->m, NAN /* old */, + event->m->value.gauge /* new */); } break; case CE_VALUE_UPDATE: @@ -146,8 +147,8 @@ static int cu_cache_event(cache_event_t *event, } else { if (!isnan(values_history[0]) && !isnan(values_history[1]) && values_history[0] < values_history[1]) { - cu_notify(CE_VALUE_UPDATE, event->metric_p, - values_history[1] /* old */, values_history[0] /* new */); + cu_notify(CE_VALUE_UPDATE, event->m, values_history[1] /* old */, + values_history[0] /* new */); } } break; @@ -158,7 +159,7 @@ static int cu_cache_event(cache_event_t *event, old_uptime = value.gauge; } - cu_notify(CE_VALUE_EXPIRED, event->metric_p, old_uptime, NAN /* new */); + cu_notify(CE_VALUE_EXPIRED, event->m, old_uptime, NAN /* new */); break; } return 0; diff --git a/src/grpc.cc b/src/grpc.cc index 522fe97bd..d07acc82c 100644 --- a/src/grpc.cc +++ b/src/grpc.cc @@ -40,9 +40,9 @@ extern "C" { #include #include +#include "collectd.h" #include "plugin.h" #include "utils/common/common.h" -#include "collectd.h" #include "daemon/utils_cache.h" } @@ -76,7 +76,8 @@ static grpc::string default_addr("0.0.0.0:50051"); * helper functions */ -static bool ident_matches(const metric_t *vl, const metric_t *matcher) { +static bool ident_matches(metric_single_t const *vl, + const metric_single_t *matcher) { if (fnmatch(matcher->host, vl->host, 0)) return false; diff --git a/src/perl.c b/src/perl.c index bf9c87f15..c1823c298 100644 --- a/src/perl.c +++ b/src/perl.c @@ -33,8 +33,8 @@ /* do not automatically get the thread specific Perl interpreter */ #define PERL_NO_GET_CONTEXT -#include #include "collectd.h" +#include #include #include @@ -115,7 +115,7 @@ static XS(Collectd__fc_register); static XS(Collectd_call_by_name); static int perl_read(user_data_t *ud); -static int perl_write(const metric_t *metric_p, user_data_t *user_data); +static int perl_write(metric_single_t const *m, user_data_t *user_data); static void perl_log(int level, const char *msg, user_data_t *user_data); static int perl_notify(const notification_t *notif, user_data_t *user_data); static int perl_flush(cdtime_t timeout, const char *identifier, @@ -347,27 +347,26 @@ static size_t av2value(pTHX_ char *name, AV *array, value_t *value, return ds->ds_num; } /* static size_t av2value (char *, AV *, value_t *, size_t) */ -static int hv2metric_list(pTHX_ HV *hash, metric_t *metric_p) { - if ((NULL == hash) || (NULL == metric_p)) +static int hv2metric_list(pTHX_ HV *hash, metric_single_t *m) { + if ((NULL == hash) || (NULL == m)) return -1; SV **tmp = av_fetch(array, 0, 0); if (NULL != tmp) { - if (DS_TYPE_COUNTER == metric_p->value_type) - metric_p->value.counter = SvIV(*tmp); - else if (DS_TYPE_GAUGE == metric_p->value_type) - metric_p->value.gauge = SvNV(*tmp); - else if (DS_TYPE_DERIVE == metric_p->value_type) - metric_p->value.derive = SvIV(*tmp); - else if (DS_TYPE_ABSOLUTE == metric_p->value_type) - metric_p->value.absolute = SvIV(*tmp); + if (DS_TYPE_COUNTER == m->value_type) + m->value.counter = SvIV(*tmp); + else if (DS_TYPE_GAUGE == m->value_type) + m->value.gauge = SvNV(*tmp); + else if (DS_TYPE_DERIVE == m->value_type) + m->value.derive = SvIV(*tmp); + else if (DS_TYPE_ABSOLUTE == m->value_type) + m->value.absolute = SvIV(*tmp); } else { return 0; } return 1; } - /* * value list: * { @@ -2133,8 +2132,7 @@ static int perl_read(user_data_t *user_data) { return pplugin_call(aTHX_ PLUGIN_READ, user_data->data); } /* static int perl_read (user_data_t *user_data) */ -static int perl_write(const metric_t *metric_p, - user_data_t *user_data) { +static int perl_write(metric_single_t const *m, user_data_t *user_data) { int status; dTHX; @@ -2159,7 +2157,7 @@ static int perl_write(const metric_t *metric_p, log_debug("perl_write: c_ithread: interp = %p (active threads: %i)", aTHX, perl_threads->number_of_threads); - status = pplugin_call(aTHX_ PLUGIN_WRITE, user_data->data, metric_p); + status = pplugin_call(aTHX_ PLUGIN_WRITE, user_data->data, m); if (aTHX == perl_threads->head->interp) pthread_mutex_unlock(&perl_threads->mutex); diff --git a/src/pyvalues.c b/src/pyvalues.c index 8d52b6a0a..12e2ffb03 100644 --- a/src/pyvalues.c +++ b/src/pyvalues.c @@ -710,25 +710,24 @@ static PyObject *Values_write(Values *self, PyObject *args, PyObject *kwds) { int ret; const data_set_t *ds; size_t size; - metric_t metric = STRUCT_METRIC_INIT; + metric_single_t metric = STRUCT_METRIC_INIT; PyObject *values = self->values, *meta = self->meta; double time = self->data.time, interval = self->interval; - char *host = NULL, *plugin = NULL, *type = NULL, - *data_source = NULL, *dest = NULL; + char *host = NULL, *plugin = NULL, *type = NULL, *data_source = NULL, + *dest = NULL; - static char *kwlist[] = { - "destination", "type", "values", - "dat_source", "plugin", "host", "time", - "interval", "meta", NULL}; + static char *kwlist[] = {"destination", "type", "values", "dat_source", + "plugin", "host", "time", "interval", + "meta", NULL}; if (!PyArg_ParseTupleAndKeywords( args, kwds, "et|etOetetetetdiO", kwlist, NULL, &dest, NULL, &type, &values, NULL, &plugin_instance, NULL, &type_instance, NULL, &plugin, NULL, &host, &time, &interval, &meta)) return NULL; - metric.identity = identity_create_legacy((plugin ? plugin : self->data.plugin), - (type ? type : self->data.type), - (host ? host : self->data.host)); + metric.identity = identity_create_legacy( + (plugin ? plugin : self->data.plugin), (type ? type : self->data.type), + (host ? host : self->data.host)); sstrncpy(value_list.host, host ? host : self->data.host, sizeof(value_list.host)); diff --git a/src/snmp_agent.c b/src/snmp_agent.c index 8339cb451..08006e4bb 100644 --- a/src/snmp_agent.c +++ b/src/snmp_agent.c @@ -29,11 +29,11 @@ #include "collectd.h" -#include #include "utils/avltree/avltree.h" #include "utils/common/common.h" #include "utils_cache.h" #include "utils_llist.h" +#include #include @@ -481,7 +481,7 @@ static int snmp_agent_tokenize(const char *input, c_avl_tree_t *tokens, } static int snmp_agent_fill_index_list(table_definition_t *td, - metric_t const *metric_p) { + metric_single_t const *m) { int ret; int i; netsnmp_variable_list *key = td->index_list_cont; @@ -497,8 +497,8 @@ static int snmp_agent_fill_index_list(table_definition_t *td, /* Generating list filled with all data necessary to generate an OID */ switch (source) { case INDEX_HOST: - ret = c_avl_get(metric_p->identity->root_p, (void *)"__host__", - (void **)&host_p); + ret = + c_avl_get(m->identity->root_p, (void *)"__host__", (void **)&host_p); if (ret != 0) { ERROR(PLUGIN_NAME ": Unknown index key resource host"); return -EINVAL; @@ -506,13 +506,13 @@ static int snmp_agent_fill_index_list(table_definition_t *td, ptr = host_p; break; case INDEX_PLUGIN: - ptr = metric_p->plugin; + ptr = m->plugin; break; case INDEX_TYPE: - ptr = metric_p->type; + ptr = m->type; break; case INDEX_DATA_SOURCE: - ptr = metric_p->ds->name; + ptr = m->ds->name; break; default: ERROR(PLUGIN_NAME ": Unknown index key source provided"); @@ -595,13 +595,13 @@ static int snmp_agent_prep_index_list(table_definition_t const *td, } static int snmp_agent_generate_index(table_definition_t *td, - metric_t const *metric_p, + metric_single_t const *m, oid_t *index_oid) { /* According to given information by index_keys list * index OID is going to be built */ - int ret = snmp_agent_fill_index_list(td, metric_p); + int ret = snmp_agent_fill_index_list(td, m); if (ret != 0) return -EINVAL; @@ -760,9 +760,9 @@ static void snmp_agent_table_data_remove(data_definition_t *dd, } } -static int snmp_agent_clear_missing(const metric_t *metric_p, +static int snmp_agent_clear_missing(metric_single_t const *m, __attribute__((unused)) user_data_t *ud) { - if (metric_p == NULL) + if (m == NULL) return -EINVAL; for (llentry_t *te = llist_head(g_agent->tables); te != NULL; te = te->next) { @@ -772,8 +772,7 @@ static int snmp_agent_clear_missing(const metric_t *metric_p, data_definition_t *dd = de->value; if (!dd->is_index_key) { - if (CHECK_DD_TYPE(dd, metric_p->plugin, metric_p->type, - metric_p->ds->name)) { + if (CHECK_DD_TYPE(dd, m->plugin, metric_p->type, m->ds->name)) { oid_t *index_oid = calloc(1, sizeof(*index_oid)); if (index_oid == NULL) { @@ -781,7 +780,7 @@ static int snmp_agent_clear_missing(const metric_t *metric_p, return -ENOMEM; } - int ret = snmp_agent_generate_index(td, metric_p, index_oid); + int ret = snmp_agent_generate_index(td, m, index_oid); if (ret == 0) snmp_agent_table_data_remove(dd, td, index_oid); @@ -995,8 +994,7 @@ static int snmp_agent_format_name(char *name, int name_len, int i = 0; netsnmp_variable_list *key = td->index_list_cont; char str[DATA_MAX_NAME_LEN]; - char *fields[MAX_KEY_SOURCES] = {hostname_g, dd->plugin, - dd->type, + char *fields[MAX_KEY_SOURCES] = {hostname_g, dd->plugin, dd->type, dd->data_source}; /* Looking for simple keys only */ @@ -1028,7 +1026,7 @@ static int snmp_agent_format_name(char *name, int name_len, return ret; } snprintf(name, name_len, fields[INDEX_HOST], fields[INDEX_PLUGIN], - fields[INDEX_TYPE],fields[INDEX_DATA_SOURCE]); + fields[INDEX_TYPE], fields[INDEX_DATA_SOURCE]); for (i = 0; i < MAX_KEY_SOURCES; i++) { if (td->tokens[i]) sfree(fields[i]); @@ -2011,8 +2009,8 @@ error: return ret; } -static int snmp_agent_write(metric_t const *metric_p) { - if (metric_p == NULL) +static int snmp_agent_write(metric_single_t const *m) { + if (m == NULL) return -EINVAL; for (llentry_t *te = llist_head(g_agent->tables); te != NULL; te = te->next) { @@ -2022,8 +2020,7 @@ static int snmp_agent_write(metric_t const *metric_p) { data_definition_t *dd = de->value; if (!dd->is_index_key) { - if (CHECK_DD_TYPE(dd, metric_p->plugin, metric_p->type, - metric_p->ds->name)) { + if (CHECK_DD_TYPE(dd, m->plugin, metric_p->type, m->ds->name)) { oid_t *index_oid = calloc(1, sizeof(*index_oid)); bool free_index_oid = true; @@ -2032,7 +2029,7 @@ static int snmp_agent_write(metric_t const *metric_p) { return -ENOMEM; } - int ret = snmp_agent_generate_index(td, metric_p, index_oid); + int ret = snmp_agent_generate_index(td, m, index_oid); if (ret == 0) ret = snmp_agent_update_index(dd, td, index_oid, &free_index_oid); @@ -2050,12 +2047,12 @@ static int snmp_agent_write(metric_t const *metric_p) { return 0; } -static int snmp_agent_collect(const metric_t *metric_p, +static int snmp_agent_collect(metric_single_t const *m, user_data_t __attribute__((unused)) * user_data) { pthread_mutex_lock(&g_agent->lock); - snmp_agent_write(metric_p); + snmp_agent_write(m); pthread_mutex_unlock(&g_agent->lock); diff --git a/src/threshold.c b/src/threshold.c index ba940e8f1..210fe7227 100644 --- a/src/threshold.c +++ b/src/threshold.c @@ -275,7 +275,7 @@ static int ut_config_host(const threshold_t *th_orig, oconfig_item_t *ci) { * if appropriate. * Does not fail. */ -static int ut_report_state(const metric_t *metric_p, const threshold_t *th, +static int ut_report_state(metric_single_t const *m, const threshold_t *th, const gauge_t value, int state) { /* {{{ */ int state_old; notification_t n; @@ -287,22 +287,22 @@ static int ut_report_state(const metric_t *metric_p, const threshold_t *th, /* Check if hits matched */ if ((th->hits != 0)) { - int hits = uc_get_hits(metric_p); + int hits = uc_get_hits(m); /* STATE_OKAY resets hits unless PERSIST_OK flag is set. Hits resets if * threshold is hit. */ if (((state == STATE_OKAY) && ((th->flags & UT_FLAG_PERSIST_OK) == 0)) || (hits > th->hits)) { DEBUG("ut_report_state: reset uc_get_hits_vl = 0"); - uc_set_hits(metric_p, 0); /* reset hit counter and notify */ + uc_set_hits(m, 0); /* reset hit counter and notify */ } else { DEBUG("ut_report_state: th->hits = %d, uc_get_hits = %d", th->hits, uc_get_hits(mstric_p)); - (void)uc_inc_hits(metric_p, 1); /* increase hit counter */ + (void)uc_inc_hits(m, 1); /* increase hit counter */ return 0; } } /* end check hits */ - state_old = uc_get_state(metric_p); + state_old = uc_get_state(m); /* If the state didn't change, report if `persistent' is specified. If the * state is `okay', then only report if `persist_ok` flag is set. */ @@ -317,9 +317,9 @@ static int ut_report_state(const metric_t *metric_p, const threshold_t *th, } if (state != state_old) - uc_set_state(metric_p, state); + uc_set_state(m, state); - notification_init_metric(&n, NOTIF_FAILURE, NULL, metric_p); + notification_init_metric(&n, NOTIF_FAILURE, NULL, m); buf = n.message; bufsize = sizeof(n.message); @@ -331,14 +331,14 @@ static int ut_report_state(const metric_t *metric_p, const threshold_t *th, else n.severity = NOTIF_FAILURE; - n.time = metric_p->time; + n.time = m->time; - status = ssnprintf(buf, bufsize, "Name %s", metric_p->identity->name); + status = ssnprintf(buf, bufsize, "Name %s", m->identity->name); buf += status; bufsize -= status; - if (metric_p->identity->root_p != NULL) { - c_avl_iterator_t *iter_p = c_avl_get_iterator(metric_p->identity->root_p); + if (m->identity->root_p != NULL) { + c_avl_iterator_t *iter_p = c_avl_get_iterator(m->identity->root_p); if (iter_p != NULL) { char *key_p = NULL; char *value_p = NULL; @@ -357,7 +357,7 @@ static int ut_report_state(const metric_t *metric_p, const threshold_t *th, c_avl_iterator_destroy(iter_p); } - plugin_notification_meta_add_string(&n, "DataSource", metric_p->ds->name); + plugin_notification_meta_add_string(&n, "DataSource", m->ds->name); plugin_notification_meta_add_double(&n, "CurrentValue", value); plugin_notification_meta_add_double(&n, "WarningMin", th->warning_min); plugin_notification_meta_add_double(&n, "WarningMax", th->warning_max); @@ -372,7 +372,7 @@ static int ut_report_state(const metric_t *metric_p, const threshold_t *th, ssnprintf(buf, bufsize, ": All data sources are within range again. " "Current value of \"%s\" is %f.", - metric_p->ds->name, value); + m->ds->name, value); } else if (state == STATE_UNKNOWN) { ERROR("ut_report_state: metric transition to UNKNOWN from a different " "state. This shouldn't happen."); @@ -389,7 +389,7 @@ static int ut_report_state(const metric_t *metric_p, const threshold_t *th, ssnprintf(buf, bufsize, ": Data source \"%s\" is currently " "%f. That is within the %s region of %f%s and %f%s.", - metric_p->ds->name, value, + m->ds->name, value, (state == STATE_ERROR) ? "failure" : "warning", min, ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "", max, ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : ""); @@ -397,7 +397,7 @@ static int ut_report_state(const metric_t *metric_p, const threshold_t *th, ssnprintf(buf, bufsize, ": Data source \"%s\" is currently " "%f. That is %s the %s threshold of %f%s.", - metric_p->ds->name, value, isnan(min) ? "below" : "above", + m->ds->name, value, isnan(min) ? "below" : "above", (state == STATE_ERROR) ? "failure" : "warning", isnan(min) ? max : min, ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : ""); @@ -406,8 +406,7 @@ static int ut_report_state(const metric_t *metric_p, const threshold_t *th, ssnprintf(buf, bufsize, ": Data source \"%s\" is currently " "%g (%.2f%%). That is %s the %s threshold of %.2f%%.", - metric_p->ds->name, value, value, - (value < min) ? "below" : "above", + m->ds->name, value, value, (value < min) ? "below" : "above", (state == STATE_ERROR) ? "failure" : "warning", (value < min) ? min : max); } else /* is not inverted */ @@ -415,7 +414,7 @@ static int ut_report_state(const metric_t *metric_p, const threshold_t *th, ssnprintf(buf, bufsize, ": Data source \"%s\" is currently " "%f. That is %s the %s threshold of %f.", - metric_p->ds->name, value, (value < min) ? "below" : "above", + m->ds->name, value, (value < min) ? "below" : "above", (state == STATE_ERROR) ? "failure" : "warning", (value < min) ? min : max); } @@ -437,7 +436,7 @@ static int ut_report_state(const metric_t *metric_p, const threshold_t *th, * appropriate. * Does not fail. */ -static int ut_check_one_data_source(const metric_t *metric_p, +static int ut_check_one_data_source(metric_single_t const *m, const threshold_t *th, const gauge_t value) { /* {{{ */ int is_warning = 0; @@ -445,8 +444,7 @@ static int ut_check_one_data_source(const metric_t *metric_p, int prev_state = STATE_OKAY; /* check if this threshold applies to this data source */ - if ((th->data_source[0] != 0) && - (strcmp(metric_p->ds->name, th->data_source) != 0)) + if ((th->data_source[0] != 0) && (strcmp(m->ds->name, th->data_source) != 0)) return STATE_UNKNOWN; if ((th->flags & UT_FLAG_INVERT) != 0) { @@ -457,7 +455,7 @@ static int ut_check_one_data_source(const metric_t *metric_p, /* XXX: This is an experimental code, not optimized, not fast, not reliable, * and probably, do not work as you expect. Enjoy! :D */ if (th->hysteresis > 0) { - prev_state = uc_get_state(metric_p); + prev_state = uc_get_state(m); /* The purpose of hysteresis is elliminating flapping state when the value * oscilates around the thresholds. In other words, what is important is * the previous state; if the new value would trigger a transition, make @@ -521,7 +519,7 @@ static int ut_check_one_data_source(const metric_t *metric_p, * defined. * Returns less than zero if the data set doesn't have any data sources. */ -static int ut_check_one_threshold(const metric_t *metric_p, +static int ut_check_one_threshold(metric_single_t const *m, const threshold_t *th, const gauge_t value) { /* {{{ */ int ret = -1; @@ -549,7 +547,7 @@ static int ut_check_one_threshold(const metric_t *metric_p, int status; - status = ut_check_one_data_source(metric_p, th, values_copy); + status = ut_check_one_data_source(m, th, values_copy); if (ret < status) { ret = status; } @@ -565,7 +563,7 @@ static int ut_check_one_threshold(const metric_t *metric_p, * Returns zero on success and if no threshold has been configured. Returns * less than zero on failure. */ -static int ut_check_threshold(const metric_t *metric_p, +static int ut_check_threshold(metric_single_t const *m, __attribute__((unused)) user_data_t *ud) { /* {{{ */ threshold_t *th; @@ -581,20 +579,20 @@ static int ut_check_threshold(const metric_t *metric_p, /* Is this lock really necessary? So far, thresholds are only inserted at * startup. -octo */ pthread_mutex_lock(&threshold_lock); - th = threshold_search(metric_p); + th = threshold_search(m); pthread_mutex_unlock(&threshold_lock); if (th == NULL) return 0; DEBUG("ut_check_threshold: Found matching threshold(s)"); - status = uc_get_rate(metric_p, &value); + status = uc_get_rate(m, &value); if (status != 0) return 0; while (th != NULL) { - status = ut_check_one_threshold(metric_p, th, value); + status = ut_check_one_threshold(m, th, value); if (status < 0) { ERROR("ut_check_threshold: ut_check_one_threshold failed."); return -1; @@ -608,7 +606,7 @@ static int ut_check_threshold(const metric_t *metric_p, th = th->next; } /* while (th) */ - status = ut_report_state(metric_p, worst_th, value, worst_state); + status = ut_report_state(m, worst_th, value, worst_state); if (status != 0) { ERROR("ut_check_threshold: ut_report_state failed."); return -1; @@ -622,7 +620,7 @@ static int ut_check_threshold(const metric_t *metric_p, * * This function is called whenever a value goes "missing". */ -static int ut_missing(const metric_t *metric_p, +static int ut_missing(metric_single_t const *m, __attribute__((unused)) user_data_t *ud) { /* {{{ */ threshold_t *th; cdtime_t missing_time; @@ -633,18 +631,18 @@ static int ut_missing(const metric_t *metric_p, if (threshold_tree == NULL) return 0; - th = threshold_search(metric_p); + th = threshold_search(m); /* dispatch notifications for "interesting" values only */ if ((th == NULL) || ((th->flags & UT_FLAG_INTERESTING) == 0)) return 0; now = cdtime(); - missing_time = now - metric_p->time; - if ((identifier_p = metric_marshal_text(metric_p)) != 0) { + missing_time = now - m->time; + if ((identifier_p = metric_marshal_text(m)) != 0) { ERROR("uc_update: metric_marshal_text failed."); } - notification_init_metric(&n, NOTIF_FAILURE, NULL, metric_p); + notification_init_metric(&n, NOTIF_FAILURE, NULL, m); ssnprintf(n.message, sizeof(n.message), "%s has not been updated for %.3f seconds.", identifier_p, CDTIME_T_TO_DOUBLE(missing_time)); diff --git a/src/write_graphite.c b/src/write_graphite.c index 822f72667..5dfe28da4 100644 --- a/src/write_graphite.c +++ b/src/write_graphite.c @@ -388,10 +388,11 @@ static int wg_send_message(char const *message, struct wg_callback *cb) { return 0; } -static int wg_write_messages(metric_t const *m, struct wg_callback *cb) { +static int wg_write_messages(metric_single_t const *m, struct wg_callback *cb) { strbuf_t buf = STRBUF_CREATE; - int status = format_graphite(&buf, m, cb->prefix, cb->postfix, cb->escape_char, cb->format_flags); + int status = format_graphite(&buf, m, cb->prefix, cb->postfix, + cb->escape_char, cb->format_flags); if (status != 0) { STRBUF_DESTROY(buf); return status; @@ -403,7 +404,7 @@ static int wg_write_messages(metric_t const *m, struct wg_callback *cb) { return status; } /* int wg_write_messages */ -static int wg_write(metric_t const *m, user_data_t *user_data) { +static int wg_write(metric_single_t const *m, user_data_t *user_data) { if ((m == NULL) || (user_data == NULL)) { return EINVAL; } diff --git a/src/write_http.c b/src/write_http.c index c343b5444..c250747a2 100644 --- a/src/write_http.c +++ b/src/write_http.c @@ -399,7 +399,7 @@ static void wh_callback_free(void *data) /* {{{ */ sfree(cb); } /* }}} void wh_callback_free */ -static int wh_write_command(const metric_t *metric_p, /* {{{ */ +static int wh_write_command(metric_single_t const *m, /* {{{ */ wh_callback_t *cb) { char values[512]; char command[1024]; @@ -413,7 +413,7 @@ static int wh_write_command(const metric_t *metric_p, /* {{{ */ /* Copy the identifier to `key' and escape it. */ char *metric_string_p = NULL; - if ((metric_string_p = metric_marshal_text(metric_p)) != 0) { + if ((metric_string_p = metric_marshal_text(m)) != 0) { return -1; } @@ -421,7 +421,7 @@ static int wh_write_command(const metric_t *metric_p, /* {{{ */ /* Convert the values to an ASCII representation and put that into * `values'. */ - status = format_values(values, sizeof(values), metric_p, cb->store_rates); + status = format_values(values, sizeof(values), m, cb->store_rates); if (status != 0) { ERROR("write_http plugin: error with " "wh_value_list_to_string"); @@ -431,7 +431,7 @@ static int wh_write_command(const metric_t *metric_p, /* {{{ */ command_len = (size_t)snprintf( command, sizeof(command), "PUTVAL %s interval=%.3f %s\r\n", - metric_string_p, CDTIME_T_TO_DOUBLE(metric_p->interval), values); + metric_string_p, CDTIME_T_TO_DOUBLE(m->interval), values); if (command_len >= sizeof(command)) { ERROR("write_http plugin: Command buffer too small: " "Need %" PRIsz " bytes.", @@ -477,7 +477,7 @@ static int wh_write_command(const metric_t *metric_p, /* {{{ */ return 0; } /* }}} int wh_write_command */ -static int wh_write_json(const metric_t *metric_p, /* {{{ */ +static int wh_write_json(metric_single_t const *m, /* {{{ */ wh_callback_t *cb) { int status; @@ -488,9 +488,8 @@ static int wh_write_json(const metric_t *metric_p, /* {{{ */ return -1; } - status = - format_json_metric(cb->send_buffer, &cb->send_buffer_fill, - &cb->send_buffer_free, metric_p, cb->store_rates); + status = format_json_metric(cb->send_buffer, &cb->send_buffer_fill, + &cb->send_buffer_free, m, cb->store_rates); if (status == -ENOMEM) { status = wh_flush_nolock(/* timeout = */ 0, cb); if (status != 0) { @@ -499,9 +498,8 @@ static int wh_write_json(const metric_t *metric_p, /* {{{ */ return status; } - status = - format_json_metric(cb->send_buffer, &cb->send_buffer_fill, - &cb->send_buffer_free, metric_p, cb->store_rates); + status = format_json_metric(cb->send_buffer, &cb->send_buffer_fill, + &cb->send_buffer_free, m, cb->store_rates); } if (status != 0) { pthread_mutex_unlock(&cb->send_lock); @@ -519,7 +517,7 @@ static int wh_write_json(const metric_t *metric_p, /* {{{ */ return 0; } /* }}} int wh_write_json */ -static int wh_write_kairosdb(const metric_t *metric_p, /* {{{ */ +static int wh_write_kairosdb(metric_single_t const *m, /* {{{ */ wh_callback_t *cb) { int status; @@ -535,7 +533,7 @@ static int wh_write_kairosdb(const metric_t *metric_p, /* {{{ */ } status = format_kairosdb_metric( - cb->send_buffer, &cb->send_buffer_fill, &cb->send_buffer_free, metric_p, + cb->send_buffer, &cb->send_buffer_fill, &cb->send_buffer_free, m, cb->store_rates, (char const *const *)http_attrs, http_attrs_num, cb->data_ttl, cb->metrics_prefix); if (status == -ENOMEM) { @@ -547,7 +545,7 @@ static int wh_write_kairosdb(const metric_t *metric_p, /* {{{ */ } status = format_kairosdb_metric( - cb->send_buffer, &cb->send_buffer_fill, &cb->send_buffer_free, metric_p, + cb->send_buffer, &cb->send_buffer_fill, &cb->send_buffer_free, m, cb->store_rates, (char const *const *)http_attrs, http_attrs_num, cb->data_ttl, cb->metrics_prefix); } @@ -567,7 +565,7 @@ static int wh_write_kairosdb(const metric_t *metric_p, /* {{{ */ return 0; } /* }}} int wh_write_kairosdb */ -static int wh_write(const metric_t *metric_p, /* {{{ */ +static int wh_write(metric_single_t const *m, /* {{{ */ user_data_t *user_data) { wh_callback_t *cb; int status; @@ -580,13 +578,13 @@ static int wh_write(const metric_t *metric_p, /* {{{ */ switch (cb->format) { case WH_FORMAT_JSON: - status = wh_write_json(metric_p, cb); + status = wh_write_json(m, cb); break; case WH_FORMAT_KAIROSDB: - status = wh_write_kairosdb(metric_p, cb); + status = wh_write_kairosdb(m, cb); break; default: - status = wh_write_command(metric_p, cb); + status = wh_write_command(m, cb); break; } return status; diff --git a/src/write_kafka.c b/src/write_kafka.c index 5307bcd2a..8f7f36cba 100644 --- a/src/write_kafka.c +++ b/src/write_kafka.c @@ -57,7 +57,7 @@ struct kafka_topic_context { }; static int kafka_handle(struct kafka_topic_context *); -static int kafka_write(const metric_t *, user_data_t *); +static int kafka_write(metric_single_t const *, user_data_t *); static int32_t kafka_partition(const rd_kafka_topic_t *, const void *, size_t, int32_t, void *, void *); @@ -171,7 +171,7 @@ static int kafka_handle(struct kafka_topic_context *ctx) /* {{{ */ } /* }}} int kafka_handle */ static int kafka_write(/* {{{ */ - const metric_t *metric_p, user_data_t *ud) { + metric_single_t const *m, user_data_t *ud) { int status = 0; void *key; size_t keylen = 0; @@ -181,8 +181,8 @@ static int kafka_write(/* {{{ */ size_t blen = 0; struct kafka_topic_context *ctx = ud->data; - if ((metric_p == NULL) || (metric_p->ds == NULL) || - (metric_p->identity == NULL) || (ctx == NULL)) + if ((m == NULL) || (metric_p->ds == NULL) || (m->identity == NULL) || + (ctx == NULL)) return EINVAL; pthread_mutex_lock(&ctx->lock); @@ -195,7 +195,7 @@ static int kafka_write(/* {{{ */ switch (ctx->format) { case KAFKA_FORMAT_COMMAND: - status = cmd_create_putval(buffer, sizeof(buffer), metric_p); + status = cmd_create_putval(buffer, sizeof(buffer), m); if (status != 0) { ERROR("write_kafka plugin: cmd_create_putval failed with status %i.", status); @@ -205,14 +205,14 @@ static int kafka_write(/* {{{ */ break; case KAFKA_FORMAT_JSON: format_json_initialize(buffer, &bfill, &bfree); - format_json_metric(buffer, &bfill, &bfree, metric_p, ctx->store_rates); + format_json_metric(buffer, &bfill, &bfree, m, ctx->store_rates); format_json_finalize(buffer, &bfill, &bfree); blen = strlen(buffer); break; case KAFKA_FORMAT_GRAPHITE: status = - format_graphite(buffer, sizeof(buffer), metric_p, ctx->prefix, - ctx->postfix, ctx->escape_char, ctx->graphite_flags); + format_graphite(buffer, sizeof(buffer), m, ctx->prefix, ctx->postfix, + ctx->escape_char, ctx->graphite_flags); if (status != 0) { ERROR("write_kafka plugin: format_graphite failed with status %i.", status); diff --git a/src/write_redis.c b/src/write_redis.c index 9a35e2d08..d532e60c5 100644 --- a/src/write_redis.c +++ b/src/write_redis.c @@ -57,7 +57,7 @@ typedef struct wr_node_s wr_node_t; * Functions */ static int wr_write(/* {{{ */ - const metric_t *metric_p, user_data_t *ud) { + metric_single_t const *m, user_data_t *ud) { wr_node_t *node = ud->data; char key[512]; char value[512] = {0}; @@ -68,18 +68,18 @@ static int wr_write(/* {{{ */ redisReply *rr; char *metric_string_p = NULL; - if ((metric_string_p = metric_marshal_text(metric_p)) != 0) { + if ((metric_string_p = metric_marshal_text(m)) != 0) { return -1; } ssnprintf(key, sizeof(key), "%s%s", (node->prefix != NULL) ? node->prefix : REDIS_DEFAULT_PREFIX, metric_string_p); - ssnprintf(time, sizeof(time), "%.9f", CDTIME_T_TO_DOUBLE(metric_p->time)); + ssnprintf(time, sizeof(time), "%.9f", CDTIME_T_TO_DOUBLE(m->time)); value_size = sizeof(value); value_ptr = &value[0]; - status = format_values(value_ptr, value_size, metric_p, node->store_rates); + status = format_values(value_ptr, value_size, m, node->store_rates); if (status != 0) { sfree(metric_string_p); return status; @@ -137,9 +137,8 @@ static int wr_write(/* {{{ */ * remove element, scored less than 'current-max_set_duration' * '(...' indicates 'less than' in redis CLI. */ - rr = redisCommand( - node->conn, "ZREMRANGEBYSCORE %s -1 (%.9f", key, - (CDTIME_T_TO_DOUBLE(metric_p->time) - node->max_set_duration)); + rr = redisCommand(node->conn, "ZREMRANGEBYSCORE %s -1 (%.9f", key, + (CDTIME_T_TO_DOUBLE(m->time) - node->max_set_duration)); if (rr == NULL) WARNING("ZREMRANGEBYSCORE command error. key:%s message:%s", key, node->conn->errstr);