Permalink
Browse files

Merge pull request #78 from jbuchbinder/memcached-publish

Memcached publish support
  • Loading branch information...
2 parents a43ae0c + 2c20099 commit d41a7adf2f3e780ffd1d9399b2f54e2f76cb8e2f @jbuchbinder jbuchbinder committed Jan 23, 2013
Showing with 101 additions and 1 deletion.
  1. +13 −0 configure.ac
  2. +1 −1 gmetad/Makefile.am
  3. +9 −0 gmetad/conf.c.in
  4. +1 −0 gmetad/conf.h
  5. +7 −0 gmetad/gmetad.c
  6. +5 −0 gmetad/gmetad.conf.in
  7. +9 −0 gmetad/gmetad.h
  8. +6 −0 gmetad/process_xml.c
  9. +39 −0 gmetad/rrd_helpers.c
  10. +11 −0 gmetad/rrd_helpers.h
View
@@ -504,6 +504,19 @@ else
fi
echo
+echo Checking for libmemcached
+AC_ARG_WITH( memcached,
+[ --with-memcached enable memcached metrics publishing],
+if test x"$withval" = xyes; then memcache="yes"; fi)
+
+if test x"$memcache" == xyes; then
+ PKG_CHECK_MODULES(DEPS, libmemcached >= 0.8.0)
+ AC_SUBST(DEPS_CFLAGS)
+ AC_SUBST(DEPS_LIBS)
+ CFLAGS="$CFLAGS -DWITH_MEMCACHED"
+fi
+
+echo
echo Checking for confuse
if test x"$libconfusepath" != x && test x"$libconfusepath" != xyes; then
CFLAGS="$CFLAGS -I$libconfusepath/include"
View
@@ -24,7 +24,7 @@ gmetad_SOURCES = gmetad.c cmdline.c.in cmdline.c cmdline.h gmetad.h data_thread
xml_hash.c cleanup.c rrd_helpers.h daemon_init.c daemon_init.h \
server_priv.h
gmetad_LDADD = $(top_builddir)/lib/libganglia.la -lrrd -lm \
- $(GLDADD)
+ $(GLDADD) $(DEPS_LIBS)
gmetad_LDFLAGS = $(GLDFLAGS)
View
@@ -278,6 +278,14 @@ static DOTCONF_CB(cb_carbon_timeout)
return NULL;
}
+static DOTCONF_CB(cb_memcached_parameters)
+{
+ gmetad_config_t *c = (gmetad_config_t*) cmd->option->info;
+ debug_msg("Enabling memcached parameters to %s", cmd->data.str);
+ c->memcached_parameters = strdup (cmd->data.str);
+ return NULL;
+}
+
static DOTCONF_CB(cb_graphite_prefix)
{
gmetad_config_t *c = (gmetad_config_t*) cmd->option->info;
@@ -330,6 +338,7 @@ static configoption_t gmetad_options[] =
{"carbon_server", ARG_STR, cb_carbon_server, &gmetad_config, 0},
{"carbon_port", ARG_INT, cb_carbon_port, &gmetad_config, 0},
{"carbon_timeout", ARG_INT, cb_carbon_timeout, &gmetad_config, 0},
+ {"memcached_parameters", ARG_STR, cb_memcached_parameters, &gmetad_config, 0},
{"graphite_prefix", ARG_STR, cb_graphite_prefix, &gmetad_config, 0},
{"unsummarized_metrics", ARG_LIST, cb_unsummarized_metrics, &gmetad_config, 0},
LAST_OPTION
View
@@ -21,6 +21,7 @@ typedef struct
char *carbon_server;
int carbon_port;
int carbon_timeout;
+ char *memcached_parameters;
char *graphite_prefix;
int scalable_mode;
int write_rrds;
View
@@ -400,6 +400,13 @@ main ( int argc, char *argv[] )
hash_foreach( sources, print_sources, NULL);
}
+#ifdef WITH_MEMCACHED
+ if (c->memcached_parameters != NULL)
+ {
+ memcached_connection_pool = memcached_pool(c->memcached_parameters, strlen(c->memcached_parameters));
+ }
+#endif /* WITH_MEMCACHED */
+
server_socket = g_tcp_socket_server_new( c->xml_port );
if (server_socket == NULL)
{
@@ -163,4 +163,9 @@ case_sensitive_hostnames 0
# default: 500
# carbon_timeout 500
#
+# Memcached configuration (if it has been compiled in)
+# Format documentation at http://docs.libmemcached.org/libmemcached_configuration.html
+# default: ""
+# memcached_parameters "--SERVER=127.0.0.1"
+#
View
@@ -14,6 +14,11 @@
#include "daemon_init.h"
#include "my_inet_ntop.h"
+#ifdef WITH_MEMCACHED
+#include <libmemcached-1.0/memcached.h>
+#include <libmemcachedutil-1.0/util.h>
+#endif /* WITH_MEMCACHED */
+
/* For metric_hash */
typedef enum {
INT,
@@ -241,4 +246,8 @@ Metric_t;
} while (RC < 0 && errno == EINTR);
#endif
+#ifdef WITH_MEMCACHED
+memcached_pool_st* memcached_connection_pool;
+#endif /* WITH_MEMCACHED */
+
#endif
@@ -645,6 +645,12 @@ startElement_METRIC(void *data, const char *el, const char **attr)
xmldata->ds->step, xmldata->source.localtime, slope);
if (gmetad_config.carbon_server) // if the user has specified a carbon server, send the metric to carbon as well
carbon_ret=write_data_to_carbon(xmldata->sourcename, xmldata->hostname, name, metricval,xmldata->source.localtime);
+#ifdef WITH_MEMCACHED
+ if (gmetad_config.memcached_parameters) {
+ int mc_ret=write_data_to_memcached(xmldata->sourcename, xmldata->hostname, name, metricval, xmldata->source.localtime, metric->dmax);
+ }
+
+#endif /* WITH_MEMCACHED */
}
metric->id = METRIC_NODE;
metric->report_start = metric_report_start;
View
@@ -16,6 +16,11 @@
#include <netdb.h>
#include <sys/poll.h>
+#ifdef WITH_MEMCACHED
+#include <libmemcached-1.0/memcached.h>
+#include <libmemcachedutil-1.0/util.h>
+#endif /* WITH_MEMCACHED */
+
#include "rrd_helpers.h"
#define PATHSIZE 4096
@@ -313,6 +318,40 @@ push_data_to_carbon( char *graphite_msg)
return EXIT_SUCCESS;
}
+#ifdef WITH_MEMCACHED
+int
+write_data_to_memcached ( const char *source, const char *host, const char *metric,
+ const char *sum, unsigned int process_time, unsigned int expiry )
+{
+ time_t expiry_time;
+ char s_path[256];
+ sprintf(s_path, "%s/%s/%s", source, host, metric);
+
+ if (expiry != 0) {
+ expiry_time = time(NULL) + expiry;
+ } else {
+ expiry_time = (time_t) 0;
+ }
+
+ memcached_return_t rc;
+ memcached_st *memc = memcached_pool_pop(memcached_connection_pool, false, &rc);
+ if (rc != MEMCACHED_SUCCESS) {
+ debug_msg("Unable to retrieve a memcached connection from the pool");
+ return EXIT_FAILURE;
+ }
+ rc = memcached_set(memc, s_path, strlen(s_path), sum, strlen(sum), expiry_time, (uint32_t)0);
+ if (rc != MEMCACHED_SUCCESS) {
+ debug_msg("Unable to push %s value %s to the memcached server(s) - %s", s_path, sum, memcached_strerror(memc, rc));
+ memcached_pool_push(memcached_connection_pool, memc);
+ return EXIT_FAILURE;
+ } else {
+ debug_msg("Pushed %s value %s to the memcached server(s)", s_path, sum);
+ memcached_pool_push(memcached_connection_pool, memc);
+ return EXIT_SUCCESS;
+ }
+}
+#endif /* WITH_MEMCACHED */
+
int
write_data_to_carbon ( const char *source, const char *host, const char *metric,
const char *sum, unsigned int process_time )
View
@@ -1,10 +1,21 @@
#include "ganglia.h"
+#ifdef WITH_MEMCACHED
+#include <libmemcached-1.0/memcached.h>
+#include <libmemcachedutil-1.0/util.h>
+#endif /* WITH_MEMCACHED */
+
int
write_data_to_rrd ( const char *source, const char *host, const char *metric,
const char *sum, const char *num, unsigned int step,
unsigned int process_time, ganglia_slope_t slope);
+#ifdef WITH_MEMCACHED
+int
+write_data_to_memcached ( const char *source, const char *host, const char *metric,
+ const char *sum, unsigned int process_time, unsigned int expiry );
+#endif /* WITH_MEMCACHED */
+
int
write_data_to_carbon ( const char *source, const char *host, const char *metric,
const char *sum, unsigned int process_time);

0 comments on commit d41a7ad

Please sign in to comment.