summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2a91519)
raw | patch | inline | side by side (parent: 2a91519)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Mon, 18 Jun 2007 22:08:09 +0000 (00:08 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Mon, 18 Jun 2007 22:08:09 +0000 (00:08 +0200) |
The LISTVAL command returnes a list of all available values and their timestamps.
src/collectd-unixsock.pod | patch | blob | history | |
src/unixsock.c | patch | blob | history |
index 7c0e316ef806cd3fca5a4fdb72671f57b6e47996..da4f2b22fe3764bc3c35787ec386a576c8272775 100644 (file)
-> | GETVAL myhost/cpu-0/cpu-user
<- | 1 value=1.260000e+00
+=item B<LISTVAL>
+
+Returnes a list of the values available in the value cache together with the
+time of the last update, so that querying applications can issue a B<GETVAL>
+command for the values that have changed.
+
+The first line's status number is the number of identifiers returned or less
+than zero if an error occured. Each of the following lines containes the
+update time as an epoch value and the identifier, seperated by a space.
+
+Example:
+ -> | LISTVAL
+ <- | 69 Values found
+ <- | 1182204284 leeloo/cpu-0/cpu-idle
+ <- | 1182204284 leeloo/cpu-0/cpu-nice
+ <- | 1182204284 leeloo/cpu-0/cpu-system
+ <- | 1182204284 leeloo/cpu-0/cpu-user
+ ...
+
=item B<PUTVAL> I<Identifier> I<Valuelist>
Submits a value (identified by I<Identifier>, see below) to the daemon which
diff --git a/src/unixsock.c b/src/unixsock.c
index 6302b17f4a279283fc88294091f21d1102e07d7e..82c15a82693056ebf32b503db8855eaaaa8c0dc6 100644 (file)
--- a/src/unixsock.c
+++ b/src/unixsock.c
} /* while (this != NULL) */
pthread_mutex_unlock (&cache_lock);
-} /* int cache_flush */
+} /* void cache_flush */
static int us_open_socket (void)
{
return (0);
} /* int us_handle_putval */
+static int us_handle_listval (FILE *fh, char **fields, int fields_num)
+{
+ char buffer[1024];
+ char **value_list = NULL;
+ int value_list_len = 0;
+ value_cache_t *entry;
+ int i;
+
+ if (fields_num != 1)
+ {
+ DEBUG ("unixsock plugin: us_handle_listval: "
+ "Wrong number of fields: %i", fields_num);
+ fprintf (fh, "-1 Wrong number of fields: Got %i, expected 1.\n",
+ fields_num);
+ fflush (fh);
+ return (-1);
+ }
+
+ pthread_mutex_lock (&cache_lock);
+
+ for (entry = cache_head; entry != NULL; entry = entry->next)
+ {
+ char **tmp;
+
+ snprintf (buffer, sizeof (buffer), "%u %s\n",
+ (unsigned int) entry->time, entry->name);
+ buffer[sizeof (buffer) - 1] = '\0';
+
+ tmp = realloc (value_list, sizeof (char *) * (value_list_len + 1));
+ if (tmp == NULL)
+ continue;
+ value_list = tmp;
+
+ value_list[value_list_len] = strdup (buffer);
+
+ if (value_list[value_list_len] != NULL)
+ value_list_len++;
+ } /* for (entry) */
+
+ pthread_mutex_unlock (&cache_lock);
+
+ DEBUG ("unixsock plugin: us_handle_listval: value_list_len = %i", value_list_len);
+ fprintf (fh, "%i Values found\n", value_list_len);
+ for (i = 0; i < value_list_len; i++)
+ fputs (value_list[i], fh);
+ fflush (fh);
+
+ return (0);
+} /* int us_handle_listval */
+
static void *us_handle_client (void *arg)
{
int fd;
{
us_handle_putval (fh, fields, fields_num);
}
+ else if (strcasecmp (fields[0], "listval") == 0)
+ {
+ us_handle_listval (fh, fields, fields_num);
+ }
else
{
fprintf (fh, "-1 Unknown command: %s\n", fields[0]);