X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Funixsock.c;h=5845f9de1c8c8514989a836683dbbd5f568b273f;hb=a813e8af8379bd0f55a2b46fc7918fa31de9522e;hp=837a902135b12e7429a767377263afb77405a04a;hpb=4f2642f86673329db9f8cf30854bf39bbdc4c2b2;p=collectd.git diff --git a/src/unixsock.c b/src/unixsock.c index 837a9021..5845f9de 100644 --- a/src/unixsock.c +++ b/src/unixsock.c @@ -24,6 +24,8 @@ #include "plugin.h" #include "configfile.h" +#include "utils_cmd_flush.h" +#include "utils_cmd_getval.h" #include "utils_cmd_putval.h" #include "utils_cmd_putnotif.h" @@ -420,80 +422,6 @@ static int us_open_socket (void) return (0); } /* int us_open_socket */ -static int us_handle_getval (FILE *fh, char **fields, int fields_num) -{ - char *hostname; - char *plugin; - char *plugin_instance; - char *type; - char *type_instance; - char name[4*DATA_MAX_NAME_LEN]; - value_cache_t *vc; - int status; - int i; - - if (fields_num != 2) - { - DEBUG ("unixsock plugin: Wrong number of fields: %i", fields_num); - fprintf (fh, "-1 Wrong number of fields: Got %i, expected 2.\n", - fields_num); - fflush (fh); - return (-1); - } - DEBUG ("unixsock plugin: Got query for `%s'", fields[1]); - - status = parse_identifier (fields[1], &hostname, - &plugin, &plugin_instance, - &type, &type_instance); - if (status != 0) - { - DEBUG ("unixsock plugin: Cannot parse `%s'", fields[1]); - fprintf (fh, "-1 Cannot parse identifier.\n"); - fflush (fh); - return (-1); - } - - status = format_name (name, sizeof (name), - hostname, plugin, plugin_instance, type, type_instance); - if (status != 0) - { - fprintf (fh, "-1 format_name failed.\n"); - return (-1); - } - - pthread_mutex_lock (&cache_lock); - - DEBUG ("vc = cache_search (%s)", name); - vc = cache_search (name); - - if (vc == NULL) - { - DEBUG ("Did not find cache entry."); - fprintf (fh, "-1 No such value"); - } - else - { - DEBUG ("Found cache entry."); - fprintf (fh, "%i", vc->values_num); - for (i = 0; i < vc->values_num; i++) - { - fprintf (fh, " %s=", vc->ds->ds[i].name); - if (isnan (vc->gauge[i])) - fprintf (fh, "NaN"); - else - fprintf (fh, "%12e", vc->gauge[i]); - } - } - - /* Free the mutex as soon as possible and definitely before flushing */ - pthread_mutex_unlock (&cache_lock); - - fprintf (fh, "\n"); - fflush (fh); - - return (0); -} /* int us_handle_getval */ - static int us_handle_listval (FILE *fh, char **fields, int fields_num) { char buffer[1024]; @@ -593,7 +521,7 @@ static void *us_handle_client (void *arg) if (strcasecmp (fields[0], "getval") == 0) { - us_handle_getval (fh, fields, fields_num); + handle_getval (fh, fields, fields_num); } else if (strcasecmp (fields[0], "putval") == 0) { @@ -607,6 +535,10 @@ static void *us_handle_client (void *arg) { handle_putnotif (fh, fields, fields_num); } + else if (strcasecmp (fields[0], "flush") == 0) + { + handle_flush (fh, fields, fields_num); + } else { fprintf (fh, "-1 Unknown command: %s\n", fields[0]);