[collectd] [PATCH] unixsock plugin: Implemented the "flush" command.

Sebastian Harl sh at tokkee.org
Tue Feb 26 18:16:25 CET 2008


This command flushes all cached data using plugin_flush_all(). An optional
timeout may be specified as an argument.

Signed-off-by: Sebastian Harl <sh at tokkee.org>
---
 src/collectd-unixsock.pod |    9 +++++++++
 src/unixsock.c            |   30 ++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/src/collectd-unixsock.pod b/src/collectd-unixsock.pod
index d17852a..a08a75d 100644
--- a/src/collectd-unixsock.pod
+++ b/src/collectd-unixsock.pod
@@ -174,6 +174,15 @@ Example:
   -> | PUTNOTIF type=temperature severity=warning time=1201094702 message=The roof is on fire!
   <- | 0 Success
 
+=item B<FLUSH> [I<Timeout>]
+
+Flushes all cached data older than I<Timeout> seconds. If no timeout has been
+specified, it defaults to -1 which causes all data to be flushed.
+
+Example:
+  -> | FLUSH
+  <- | 0 Done
+
 =back
 
 =head2 Identifiers
diff --git a/src/unixsock.c b/src/unixsock.c
index 63c3ae9..5e70a35 100644
--- a/src/unixsock.c
+++ b/src/unixsock.c
@@ -544,6 +544,32 @@ static int us_handle_listval (FILE *fh, char **fields, int fields_num)
 	return (0);
 } /* int us_handle_listval */
 
+static int us_handle_flush (FILE *fh, char **fields, int fields_num)
+{
+	int timeout = -1;
+
+	if ((fields_num != 1) && (fields_num != 2))
+	{
+		DEBUG ("unixsock plugin: us_handle_flush: "
+				"Wrong number of fields: %i", fields_num);
+		fprintf (fh, "-1 Wrong number of fields: Got %i, expected 1 or 2.\n",
+				fields_num);
+		fflush (fh);
+		return (-1);
+	}
+
+	if (fields_num == 2)
+		timeout = atoi (fields[1]);
+
+	INFO ("unixsock plugin: flushing all data");
+	plugin_flush_all (timeout);
+	INFO ("unixsock plugin: finished flushing all data");
+
+	fprintf (fh, "0 Done\n");
+	fflush (fh);
+	return (0);
+} /* int us_handle_flush */
+
 static void *us_handle_client (void *arg)
 {
 	int fd;
@@ -607,6 +633,10 @@ static void *us_handle_client (void *arg)
 		{
 			handle_putnotif (fh, fields, fields_num);
 		}
+		else if (strcasecmp (fields[0], "flush") == 0)
+		{
+			us_handle_flush (fh, fields, fields_num);
+		}
 		else
 		{
 			fprintf (fh, "-1 Unknown command: %s\n", fields[0]);
-- 
1.5.4.2.184.gb23b

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20080226/d1f889a3/attachment.pgp 


More information about the collectd mailing list