static Msg *riemann_value_list_to_protobuf (struct riemann_host const *host, /* {{{ */ data_set_t const *ds, value_list_t const *vl, int *statuses) { Msg *msg; size_t i; gauge_t *rates = NULL; /* Initialize the Msg structure. */ msg = malloc (sizeof (*msg)); if (msg == NULL) { ERROR ("write_riemann plugin: malloc failed."); return (NULL); } memset (msg, 0, sizeof (*msg)); msg__init (msg); /* Set up events. First, the list of pointers. */ msg->n_events = vl->values_len; msg->events = calloc (msg->n_events, sizeof (*msg->events)); if (msg->events == NULL) { ERROR ("write_riemann plugin: calloc failed."); riemann_msg_protobuf_free (msg); return (NULL); } if (host->store_rates) { rates = uc_get_rate (ds, vl); if (rates == NULL) { ERROR ("write_riemann plugin: uc_get_rate failed."); riemann_msg_protobuf_free (msg); return (NULL); } } for (i = 0; i < msg->n_events; i++) { msg->events[i] = riemann_value_to_protobuf (host, ds, vl, (int) i, rates, statuses[i]); if (msg->events[i] == NULL) { riemann_msg_protobuf_free (msg); sfree (rates); return (NULL); } } sfree (rates); return (msg); } /* }}} Msg *riemann_value_list_to_protobuf */
static int riemann_notification(const notification_t *n, user_data_t *ud) /* {{{ */ { int status; struct riemann_host *host = ud->data; Msg *msg; msg = riemann_notification_to_protobuf (host, n); if (msg == NULL) return (-1); status = riemann_send (host, msg); if (status != 0) ERROR ("write_riemann plugin: riemann_send failed with status %i", status); riemann_msg_protobuf_free (msg); return (status); } /* }}} int riemann_notification */
static int riemann_write(const data_set_t *ds, /* {{{ */ const value_list_t *vl, user_data_t *ud) { int status; struct riemann_host *host = ud->data; Msg *msg; msg = riemann_value_list_to_protobuf (host, ds, vl); if (msg == NULL) return (-1); status = riemann_send (host, msg); if (status != 0) ERROR ("write_riemann plugin: riemann_send failed with status %i", status); riemann_msg_protobuf_free (msg); return status; } /* }}} int riemann_write */
/* * Always call while holding host->lock ! */ static int riemann_batch_flush_nolock (cdtime_t timeout, struct riemann_host *host) { cdtime_t now; int status = 0; if (timeout > 0) { now = cdtime (); if ((host->batch_init + timeout) > now) return status; } riemann_send_msg(host, host->batch_msg); riemann_msg_protobuf_free(host->batch_msg); if (host->use_tcp && ((status = riemann_recv_ack(host)) != 0)) riemann_disconnect (host); host->batch_init = cdtime(); host->batch_msg = NULL; return status; }