From: Peter Stamfest Date: Mon, 24 Feb 2014 19:06:32 +0000 (+0100) Subject: Extend rrdcached client API to be able to also send FORGET and other X-Git-Tag: v1.5.0-rc1~132^2~1^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=09afe10196d8b0deec425ce1715a61f76a655642;p=thirdparty%2Frrdtool-1.x.git Extend rrdcached client API to be able to also send FORGET and other filename based commands easily --- diff --git a/src/rrd_client.c b/src/rrd_client.c index d796a2bd..d1b22eb4 100644 --- a/src/rrd_client.c +++ b/src/rrd_client.c @@ -615,6 +615,11 @@ int rrdc_is_connected(const char *daemon_addr) /* {{{ */ } /* }}} int rrdc_is_connected */ +/* determine whether we are connected to any daemon */ +int rrdc_is_any_connected(void) { + return sd >= 0; +} + static int rrdc_connect_unix (const char *path) /* {{{ */ { #ifdef WIN32 @@ -888,7 +893,8 @@ int rrdc_update (const char *filename, int values_num, /* {{{ */ return (status); } /* }}} int rrdc_update */ -int rrdc_flush (const char *filename) /* {{{ */ +static int rrdc_filebased_command (const char *command, + const char *filename) /* {{{ */ { char buffer[RRD_CMD_MAX]; char *buffer_ptr; @@ -905,7 +911,7 @@ int rrdc_flush (const char *filename) /* {{{ */ buffer_ptr = &buffer[0]; buffer_free = sizeof (buffer); - status = buffer_add_string ("flush", &buffer_ptr, &buffer_free); + status = buffer_add_string (command, &buffer_ptr, &buffer_free); if (status != 0) return (ENOBUFS); @@ -942,6 +948,14 @@ int rrdc_flush (const char *filename) /* {{{ */ return (status); } /* }}} int rrdc_flush */ +int rrdc_flush (const char *filename) { + return rrdc_filebased_command("flush", filename); +} + +int rrdc_forget (const char *filename) { + return rrdc_filebased_command("forget", filename); +} + rrd_info_t * rrdc_info (const char *filename) /* {{{ */ { char buffer[RRD_CMD_MAX]; diff --git a/src/rrd_client.h b/src/rrd_client.h index 5697963c..af66d775 100644 --- a/src/rrd_client.h +++ b/src/rrd_client.h @@ -44,6 +44,7 @@ int rrdc_connect (const char *addr); int rrdc_is_connected(const char *daemon_addr); +int rrdc_is_any_connected(void); int rrdc_disconnect (void); int rrdc_update (const char *filename, int values_num, @@ -61,6 +62,7 @@ int rrdc_create (const char *filename, int rrdc_flush (const char *filename); +int rrdc_forget (const char *filename); int rrdc_flush_if_daemon (const char *opt_daemon, const char *filename); int rrdc_fetch (const char *filename,