summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d35dd47)
raw | patch | inline | side by side (parent: d35dd47)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Wed, 27 Feb 2008 22:22:36 +0000 (23:22 +0100) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Wed, 27 Feb 2008 22:22:36 +0000 (23:22 +0100) |
Both options are optional. The meaning of `timeout' is the same, but must now
be prepended with `timeout='. The new `plugin=' option allows the user to
select only specific plugins to flush.
be prepended with `timeout='. The new `plugin=' option allows the user to
select only specific plugins to flush.
src/collectd-unixsock.pod | patch | blob | history | |
src/utils_cmd_flush.c | patch | blob | history |
index a08a75da0ae9ed5f4d3c41c5dcde67309d103c86..0d63d4a621a383b741902f99e3b365e7ad67b610 100644 (file)
-> | PUTNOTIF type=temperature severity=warning time=1201094702 message=The roof is on fire!
<- | 0 Success
-=item B<FLUSH> [I<Timeout>]
+=item B<FLUSH> [B<timeout=>I<Timeout>] [B<plugin=>I<Plugin> [...]]
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.
+If specified, only specific plugins are flushed. Otherwise all plugins
+providing a flush callback are flushed.
+
Example:
-> | FLUSH
<- | 0 Done
diff --git a/src/utils_cmd_flush.c b/src/utils_cmd_flush.c
index e7737a0c8d01311111c7d74494532ac7469feeed..6832493c0a0d9b8e2df0d59628eda2b7fae8528d 100644 (file)
--- a/src/utils_cmd_flush.c
+++ b/src/utils_cmd_flush.c
/**
* collectd - src/utils_cmd_flush.c
* Copyright (C) 2008 Sebastian Harl
+ * Copyright (C) 2008 Florian Forster
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
- * Author:
+ * Authors:
* Sebastian "tokkee" Harl <sh at tokkee.org>
+ * Florian "octo" Forster <octo at verplant.org>
**/
#include "collectd.h"
+#include "common.h"
#include "plugin.h"
-int handle_flush (FILE *fh, char **fields, int fields_num)
+struct flush_info_s
+{
+ char **plugins;
+ int plugins_num;
+ int timeout;
+};
+typedef struct flush_info_s flush_info_t;
+
+static int parse_option_plugin (flush_info_t *fi, const char *option)
{
- int timeout = -1;
+ char **temp;
+
+ temp = (char **) realloc (fi->plugins,
+ (fi->plugins_num + 1) * sizeof (char *));
+ if (temp == NULL)
+ {
+ ERROR ("utils_cmd_flush: parse_option_plugin: realloc failed.");
+ return (-1);
+ }
+ fi->plugins = temp;
- if ((fields_num != 1) && (fields_num != 2))
+ fi->plugins[fi->plugins_num] = strdup (option + strlen ("plugin="));
+ if (fi->plugins[fi->plugins_num] == NULL)
{
- 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);
+ /* fi->plugins is freed in handle_flush in this case */
+ ERROR ("utils_cmd_flush: parse_option_plugin: strdup failed.");
return (-1);
}
+ fi->plugins_num++;
+
+ return (0);
+} /* int parse_option_plugin */
+
+static int parse_option_timeout (flush_info_t *fi, const char *option)
+{
+ const char *value_ptr = option + strlen ("timeout=");
+ char *endptr = NULL;
+ int timeout;
+
+ timeout = strtol (value_ptr, &endptr, 0);
+ if (value_ptr == endptr)
+ return (-1);
+
+ fi->timeout = (timeout <= 0) ? (-1) : timeout;
+
+ return (0);
+} /* int parse_option_timeout */
- if (fields_num == 2)
- timeout = atoi (fields[1]);
+static int parse_option (flush_info_t *fi, const char *option)
+{
+ if (strncasecmp ("plugin=", option, strlen ("plugin=")) == 0)
+ return (parse_option_plugin (fi, option));
+ else if (strncasecmp ("timeout=", option, strlen ("timeout=")) == 0)
+ return (parse_option_timeout (fi, option));
+ else
+ return (-1);
+} /* int parse_option */
+
+int handle_flush (FILE *fh, char **fields, int fields_num)
+{
+ flush_info_t fi;
+ int status;
+ int i;
+
+ memset (&fi, '\0', sizeof (fi));
+ fi.timeout = -1;
- INFO ("unixsock plugin: flushing all data");
- plugin_flush_all (timeout);
- INFO ("unixsock plugin: finished flushing all data");
+ for (i = 1; i < fields_num; i++)
+ {
+ status = parse_option (&fi, fields[i]);
+ if (status != 0)
+ {
+ fprintf (fh, "-1 Cannot parse option %s\n", fields[i]);
+ fflush (fh);
+ return (-1);
+ }
+ }
- fprintf (fh, "0 Done\n");
+ if (fi.plugins_num > 0)
+ {
+ int success = 0;
+ for (i = 0; i < fi.plugins_num; i++)
+ {
+ status = plugin_flush_one (fi.timeout, fi.plugins[i]);
+ if (status == 0)
+ success++;
+ }
+ fprintf (fh, "0 Done: %i successful, %i errors\n",
+ success, fi.plugins_num - success);
+ }
+ else
+ {
+ plugin_flush_all (fi.timeout);
+ fprintf (fh, "0 Done");
+ }
fflush (fh);
+
+ for (i = 0; i < fi.plugins_num; i++)
+ {
+ sfree (fi.plugins[i]);
+ }
+ sfree (fi.plugins);
+
return (0);
} /* int handle_flush */