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;
if (lookup == NULL)
status = ENOENT;
else {
- status = lookup_search(lookup, metric_p);
+ status = lookup_search(lookup, m);
if (status > 0)
status = 0;
}
#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"
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];
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) {
} 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;
buffer_size -= tmp_str_len;
} else {
snprintf(index_p, buffer_size, ";%s", value_p);
- buffer_size = 0;
- break;
+ buffer_size = 0;
+ break;
}
}
}
}
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;
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;
} /* }}} 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;
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.",
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) {
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:
} 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;
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;
#include <fnmatch.h>
#include <stdbool.h>
+#include "collectd.h"
#include "plugin.h"
#include "utils/common/common.h"
-#include "collectd.h"
#include "daemon/utils_cache.h"
}
* 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;
/* do not automatically get the thread specific Perl interpreter */
#define PERL_NO_GET_CONTEXT
-#include <stdbool.h>
#include "collectd.h"
+#include <stdbool.h>
#include <EXTERN.h>
#include <perl.h>
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,
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:
* {
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;
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);
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));
#include "collectd.h"
-#include <regex.h>
#include "utils/avltree/avltree.h"
#include "utils/common/common.h"
#include "utils_cache.h"
#include "utils_llist.h"
+#include <regex.h>
#include <net-snmp/net-snmp-config.h>
}
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;
/* 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;
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");
}
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;
}
}
-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) {
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) {
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);
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 */
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]);
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) {
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;
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);
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);
* 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;
/* 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. */
}
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);
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;
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);
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.");
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) ? "%" : "");
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) ? "%" : "");
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 */
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);
}
* 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;
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) {
/* 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
* 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;
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;
}
* 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;
/* 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;
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;
*
* 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;
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));
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;
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;
}
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];
/* 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;
}
/* 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");
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.",
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;
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) {
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);
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;
}
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) {
}
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);
}
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;
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;
};
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 *);
} /* }}} 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;
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);
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);
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);
* 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};
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;
* 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);