projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Treewide: cleanup whitespace
[collectd.git]
/
src
/
write_riemann.c
diff --git
a/src/write_riemann.c
b/src/write_riemann.c
index
328341e
..
8191ae2
100644
(file)
--- a/
src/write_riemann.c
+++ b/
src/write_riemann.c
@@
-26,27
+26,25
@@
* Florian octo Forster <octo at collectd.org>
*/
* Florian octo Forster <octo at collectd.org>
*/
+#include <arpa/inet.h>
+#include <errno.h>
+#include <netdb.h>
+#include <inttypes.h>
+#include <pthread.h>
+
#include "collectd.h"
#include "plugin.h"
#include "common.h"
#include "configfile.h"
#include "utils_cache.h"
#include "riemann.pb-c.h"
#include "collectd.h"
#include "plugin.h"
#include "common.h"
#include "configfile.h"
#include "utils_cache.h"
#include "riemann.pb-c.h"
-
-#include <sys/socket.h>
-#include <arpa/inet.h>
-#include <errno.h>
-#include <netdb.h>
-#include <inttypes.h>
-#include <pthread.h>
+#include "write_riemann_threshold.h"
#define RIEMANN_HOST "localhost"
#define RIEMANN_PORT "5555"
#define RIEMANN_TTL_FACTOR 2.0
#define RIEMANN_BATCH_MAX 8192
#define RIEMANN_HOST "localhost"
#define RIEMANN_PORT "5555"
#define RIEMANN_TTL_FACTOR 2.0
#define RIEMANN_BATCH_MAX 8192
-int write_riemann_threshold_check(const data_set_t *, const value_list_t *, int *);
-
struct riemann_host {
char *name;
char *event_service_prefix;
struct riemann_host {
char *name;
char *event_service_prefix;
@@
-207,12
+205,11
@@
static int riemann_send_msg (struct riemann_host *host, const Msg *msg) /* {{{ *
if (host->use_tcp)
buffer_len += 4;
if (host->use_tcp)
buffer_len += 4;
- buffer =
malloc (
buffer_len);
+ buffer =
calloc (1,
buffer_len);
if (buffer == NULL) {
if (buffer == NULL) {
- ERROR ("write_riemann plugin:
m
alloc failed.");
+ ERROR ("write_riemann plugin:
c
alloc failed.");
return ENOMEM;
}
return ENOMEM;
}
- memset (buffer, 0, buffer_len);
if (host->use_tcp)
{
if (host->use_tcp)
{
@@
-365,15
+362,14
@@
static Msg *riemann_notification_to_protobuf(struct riemann_host *host, /* {{{ *
char service_buffer[6 * DATA_MAX_NAME_LEN];
char const *severity;
notification_meta_t *meta;
char service_buffer[6 * DATA_MAX_NAME_LEN];
char const *severity;
notification_meta_t *meta;
-
in
t i;
+
size_
t i;
- msg =
malloc (
sizeof (*msg));
+ msg =
calloc (1,
sizeof (*msg));
if (msg == NULL)
{
if (msg == NULL)
{
- ERROR ("write_riemann plugin:
m
alloc failed.");
+ ERROR ("write_riemann plugin:
c
alloc failed.");
return (NULL);
}
return (NULL);
}
- memset (msg, 0, sizeof (*msg));
msg__init (msg);
msg->events = malloc (sizeof (*msg->events));
msg__init (msg);
msg->events = malloc (sizeof (*msg->events));
@@
-384,15
+380,14
@@
static Msg *riemann_notification_to_protobuf(struct riemann_host *host, /* {{{ *
return (NULL);
}
return (NULL);
}
- event =
malloc (
sizeof (*event));
+ event =
calloc (1,
sizeof (*event));
if (event == NULL)
{
if (event == NULL)
{
- ERROR ("write_riemann plugin:
m
alloc failed.");
+ ERROR ("write_riemann plugin:
c
alloc failed.");
sfree (msg->events);
sfree (msg);
return (NULL);
}
sfree (msg->events);
sfree (msg);
return (NULL);
}
- memset (event, 0, sizeof (*event));
event__init (event);
msg->events[0] = event;
event__init (event);
msg->events[0] = event;
@@
-474,15
+469,14
@@
static Event *riemann_value_to_protobuf(struct riemann_host const *host, /* {{{
char name_buffer[5 * DATA_MAX_NAME_LEN];
char service_buffer[6 * DATA_MAX_NAME_LEN];
double ttl;
char name_buffer[5 * DATA_MAX_NAME_LEN];
char service_buffer[6 * DATA_MAX_NAME_LEN];
double ttl;
-
in
t i;
+
size_
t i;
- event =
malloc (
sizeof (*event));
+ event =
calloc (1,
sizeof (*event));
if (event == NULL)
{
if (event == NULL)
{
- ERROR ("write_riemann plugin:
m
alloc failed.");
+ ERROR ("write_riemann plugin:
c
alloc failed.");
return (NULL);
}
return (NULL);
}
- memset (event, 0, sizeof (*event));
event__init (event);
event->host = strdup (vl->host);
event__init (event);
event->host = strdup (vl->host);
@@
-609,17
+603,16
@@
static Msg *riemann_value_list_to_protobuf (struct riemann_host const *host, /*
gauge_t *rates = NULL;
/* Initialize the Msg structure. */
gauge_t *rates = NULL;
/* Initialize the Msg structure. */
- msg =
malloc (
sizeof (*msg));
+ msg =
calloc (1,
sizeof (*msg));
if (msg == NULL)
{
if (msg == NULL)
{
- ERROR ("write_riemann plugin:
m
alloc failed.");
+ ERROR ("write_riemann plugin:
c
alloc failed.");
return (NULL);
}
return (NULL);
}
- memset (msg, 0, sizeof (*msg));
msg__init (msg);
/* Set up events. First, the list of pointers. */
msg__init (msg);
/* Set up events. First, the list of pointers. */
- msg->n_events =
(size_t)
vl->values_len;
+ msg->n_events = vl->values_len;
msg->events = calloc (msg->n_events, sizeof (*msg->events));
if (msg->events == NULL)
{
msg->events = calloc (msg->n_events, sizeof (*msg->events));
if (msg->events == NULL)
{
@@
-744,8
+737,8
@@
static int riemann_batch_add_value_list (struct riemann_host *host, /* {{{ */
len = msg__get_packed_size(host->batch_msg);
ret = 0;
len = msg__get_packed_size(host->batch_msg);
ret = 0;
- if (
len >= host->batch_max
) {
- ret = riemann_batch_flush_nolock(0, host);
+ if (
(host->batch_max < 0) || (((size_t) host->batch_max) <= len)
) {
+
ret = riemann_batch_flush_nolock(0, host);
}
pthread_mutex_unlock(&host->lock);
}
pthread_mutex_unlock(&host->lock);
@@
-778,35
+771,35
@@
static int riemann_notification(const notification_t *n, user_data_t *ud) /* {{{
} /* }}} int riemann_notification */
static int riemann_write(const data_set_t *ds, /* {{{ */
} /* }}} int riemann_notification */
static int riemann_write(const data_set_t *ds, /* {{{ */
- const value_list_t *vl,
- user_data_t *ud)
+
const value_list_t *vl,
+
user_data_t *ud)
{
int status = 0;
int statuses[vl->values_len];
struct riemann_host *host = ud->data;
{
int status = 0;
int statuses[vl->values_len];
struct riemann_host *host = ud->data;
- Msg *msg;
-
- if (host->check_thresholds)
- write_riemann_threshold_check(ds, vl, statuses);
-
- if (host->use_tcp == 1 && host->batch_mode) {
-
- riemann_batch_add_value_list (host, ds, vl, statuses);
+ if (host->check_thresholds) {
+ status = write_riemann_threshold_check(ds, vl, statuses);
+ if (status != 0)
+ return status;
+ } else {
+ memset (statuses, 0, sizeof (statuses));
+ }
- } else {
+ if (host->use_tcp == 1 && host->batch_mode) {
+ riemann_batch_add_value_list (host, ds, vl, statuses);
+ } else {
+ Msg *msg = riemann_value_list_to_protobuf (host, ds, vl, statuses);
+ if (msg == NULL)
+ return (-1);
-
msg = riemann_value_list_to_protobuf (host, ds, vl, statuses
);
-
if (msg == NULL
)
-
return (-1
);
+
status = riemann_send (host, msg
);
+
if (status != 0
)
+
ERROR ("write_riemann plugin: riemann_send failed with status %i", status
);
- status = riemann_send (host, msg);
- if (status != 0)
- ERROR ("write_riemann plugin: riemann_send failed with status %i",
- status);
+ riemann_msg_protobuf_free (msg);
+ }
- riemann_msg_protobuf_free (msg);
- }
return status;
} /* }}} int riemann_write */
return status;
} /* }}} int riemann_write */