diff --git a/src/write_redis.c b/src/write_redis.c
index 404391a6928996a65a004ebafcd048613844b0ce..58f2cae3e28dc02b3a9fad6bcbb80171230631a3 100644 (file)
--- a/src/write_redis.c
+++ b/src/write_redis.c
/**
/**
- * collectd - src/target_set.c
- * Copyright (C) 2008-2010 Florian Forster
+ * collectd - src/write_redis.c
+ * Copyright (C) 2010 Florian Forster
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
user_data_t *ud)
{
wr_node_t *node = ud->data;
user_data_t *ud)
{
wr_node_t *node = ud->data;
+ char ident[512];
char key[512];
char value[512];
char key[512];
char value[512];
- char tmp[512];
+ size_t value_size;
+ char *value_ptr;
int status;
int i;
int status;
int i;
- status = FORMAT_VL (tmp, sizeof (tmp), vl);
+ status = FORMAT_VL (ident, sizeof (ident), vl);
if (status != 0)
return (status);
if (status != 0)
return (status);
- ssnprintf (key, sizeof (key), "collectd/%s", tmp);
-
- ssnprintf (value, sizeof (value), "%lu", (unsigned long) vl->time);
+ ssnprintf (key, sizeof (key), "collectd/%s", ident);
+
+ memset (value, 0, sizeof (value));
+ value_size = sizeof (value);
+ value_ptr = &value[0];
+
+#define APPEND(...) do { \
+ status = snprintf (value_ptr, value_size, __VA_ARGS__); \
+ if (((size_t) status) > value_size) \
+ { \
+ value_ptr += value_size; \
+ value_size = 0; \
+ } \
+ else \
+ { \
+ value_ptr += status; \
+ value_size -= status; \
+ } \
+} while (0)
+
+ APPEND ("%lu", (unsigned long) vl->time);
for (i = 0; i < ds->ds_num; i++)
{
if (ds->ds[i].type == DS_TYPE_COUNTER)
for (i = 0; i < ds->ds_num; i++)
{
if (ds->ds[i].type == DS_TYPE_COUNTER)
- ssnprintf (tmp, sizeof (tmp), "%s:%llu",
- value, vl->values[i].counter);
+ APPEND ("%llu", vl->values[i].counter);
else if (ds->ds[i].type == DS_TYPE_GAUGE)
else if (ds->ds[i].type == DS_TYPE_GAUGE)
- ssnprintf (tmp, sizeof (tmp), "%s:%g",
- value, vl->values[i].gauge);
+ APPEND ("%g", vl->values[i].gauge);
else if (ds->ds[i].type == DS_TYPE_DERIVE)
else if (ds->ds[i].type == DS_TYPE_DERIVE)
- ssnprintf (tmp, sizeof (tmp), "%s:%"PRIi64,
- value, vl->values[i].derive);
+ APPEND ("%"PRIi64, vl->values[i].derive);
else if (ds->ds[i].type == DS_TYPE_ABSOLUTE)
else if (ds->ds[i].type == DS_TYPE_ABSOLUTE)
- ssnprintf (tmp, sizeof (tmp), "%s:%"PRIu64,
- value, vl->values[i].absolute);
+ APPEND ("%"PRIu64, vl->values[i].absolute);
else
assert (23 == 42);
else
assert (23 == 42);
-
- memcpy (value, tmp, sizeof (value));
}
}
+#undef APPEND
+
pthread_mutex_lock (&node->lock);
if (node->conn == NULL)
pthread_mutex_lock (&node->lock);
if (node->conn == NULL)
assert (node->conn != NULL);
status = credis_zadd (node->conn, key, (double) vl->time, value);
assert (node->conn != NULL);
status = credis_zadd (node->conn, key, (double) vl->time, value);
+ credis_sadd (node->conn, "collectd/values", ident);
+
pthread_mutex_unlock (&node->lock);
return (0);
pthread_mutex_unlock (&node->lock);
return (0);