summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bc70ba8)
raw | patch | inline | side by side (parent: bc70ba8)
author | Florian Forster <octo@huhu.verplant.org> | |
Wed, 27 Feb 2008 09:16:31 +0000 (10:16 +0100) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Wed, 27 Feb 2008 09:16:31 +0000 (10:16 +0100) |
src/Makefile.am | patch | blob | history | |
src/unixsock.c | patch | blob | history | |
src/utils_cmd_getval.c | [new file with mode: 0644] | patch | blob |
src/utils_cmd_getval.h | [new file with mode: 0644] | patch | blob |
diff --git a/src/Makefile.am b/src/Makefile.am
index c3d0b1d3a02049525b875c26db20fb037f0a5f79..da9ca9b4413a7a26370e7c11c1f6245a8f159ec2 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
if BUILD_PLUGIN_UNIXSOCK
pkglib_LTLIBRARIES += unixsock.la
-unixsock_la_SOURCES = unixsock.c utils_cmd_putval.h utils_cmd_putval.c utils_cmd_putnotif.h utils_cmd_putnotif.c
+unixsock_la_SOURCES = unixsock.c \
+ utils_cmd_getval.h utils_cmd_getval.c \
+ utils_cmd_putval.h utils_cmd_putval.c \
+ utils_cmd_putnotif.h utils_cmd_putnotif.c
unixsock_la_LDFLAGS = -module -avoid-version -lpthread
collectd_LDADD += "-dlopen" unixsock.la
collectd_DEPENDENCIES += unixsock.la
diff --git a/src/unixsock.c b/src/unixsock.c
index ca7aa2e6ed77fb513be6b82ef7980562069c8ab5..5f859b3fc8bdb3035b5d86b28df2ea0028446216 100644 (file)
--- a/src/unixsock.c
+++ b/src/unixsock.c
#include "plugin.h"
#include "configfile.h"
-/* FIXME: Replace this with "utils_cmd_getval.h" asap */
-#include "utils_cache.h"
-
+#include "utils_cmd_getval.h"
#include "utils_cmd_putval.h"
#include "utils_cmd_putnotif.h"
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;
- gauge_t *values;
- size_t values_num;
-
- const data_set_t *ds;
-
- 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]);
-
- if (strlen (fields[1]) < strlen ("h/p/t"))
- {
- fprintf (fh, "-1 Invalied identifier, %s", fields[1]);
- fflush (fh);
- return (-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);
- }
-
- ds = plugin_get_ds (type);
- if (ds == NULL)
- {
- DEBUG ("unixsock plugin: plugin_get_ds (%s) == NULL;", type);
- fprintf (fh, "-1 Type `%s' is unknown.\n", type);
- fflush (fh);
- return (-1);
- }
-
- values = NULL;
- values_num = 0;
- status = uc_get_rate_by_name (fields[1], &values, &values_num);
- if (status != 0)
- {
- fprintf (fh, "-1 No such value");
- fflush (fh);
- return (-1);
- }
-
- if (ds->ds_num != values_num)
- {
- ERROR ("ds[%s]->ds_num = %i, "
- "but uc_get_rate_by_name returned %i values.",
- ds->type, ds->ds_num, values_num);
- fprintf (fh, "-1 Error reading value from cache.\n");
- fflush (fh);
- sfree (values);
- return (-1);
- }
-
- fprintf (fh, "%u", (unsigned int) values_num);
- for (i = 0; i < values_num; i++)
- {
- fprintf (fh, " %s=", ds->ds[i].name);
- if (isnan (values[i]))
- fprintf (fh, "NaN");
- else
- fprintf (fh, "%12e", values[i]);
- }
-
- fprintf (fh, "\n");
- fflush (fh);
-
- sfree (values);
-
- return (0);
-} /* int us_handle_getval */
-
static int us_handle_listval (FILE *fh, char **fields, int fields_num)
{
char buffer[1024];
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)
{
diff --git a/src/utils_cmd_getval.c b/src/utils_cmd_getval.c
--- /dev/null
+++ b/src/utils_cmd_getval.c
@@ -0,0 +1,119 @@
+/**
+ * collectd - src/utils_cms_getval.c
+ * Copyright (C) 2008 Florian octo 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
+ * Free Software Foundation; only version 2 of the License is applicable.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Florian octo Forster <octo at verplant.org>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#include "utils_cache.h"
+
+int handle_getval (FILE *fh, char **fields, int fields_num)
+{
+ char *hostname;
+ char *plugin;
+ char *plugin_instance;
+ char *type;
+ char *type_instance;
+ gauge_t *values;
+ size_t values_num;
+
+ const data_set_t *ds;
+
+ 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]);
+
+ if (strlen (fields[1]) < strlen ("h/p/t"))
+ {
+ fprintf (fh, "-1 Invalied identifier, %s", fields[1]);
+ fflush (fh);
+ return (-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);
+ }
+
+ ds = plugin_get_ds (type);
+ if (ds == NULL)
+ {
+ DEBUG ("unixsock plugin: plugin_get_ds (%s) == NULL;", type);
+ fprintf (fh, "-1 Type `%s' is unknown.\n", type);
+ fflush (fh);
+ return (-1);
+ }
+
+ values = NULL;
+ values_num = 0;
+ status = uc_get_rate_by_name (fields[1], &values, &values_num);
+ if (status != 0)
+ {
+ fprintf (fh, "-1 No such value");
+ fflush (fh);
+ return (-1);
+ }
+
+ if (ds->ds_num != values_num)
+ {
+ ERROR ("ds[%s]->ds_num = %i, "
+ "but uc_get_rate_by_name returned %i values.",
+ ds->type, ds->ds_num, values_num);
+ fprintf (fh, "-1 Error reading value from cache.\n");
+ fflush (fh);
+ sfree (values);
+ return (-1);
+ }
+
+ fprintf (fh, "%u", (unsigned int) values_num);
+ for (i = 0; i < values_num; i++)
+ {
+ fprintf (fh, " %s=", ds->ds[i].name);
+ if (isnan (values[i]))
+ fprintf (fh, "NaN");
+ else
+ fprintf (fh, "%12e", values[i]);
+ }
+
+ fprintf (fh, "\n");
+ fflush (fh);
+
+ sfree (values);
+
+ return (0);
+} /* int handle_getval */
+
+/* vim: set sw=2 sts=2 ts=8 : */
diff --git a/src/utils_cmd_getval.h b/src/utils_cmd_getval.h
--- /dev/null
+++ b/src/utils_cmd_getval.h
@@ -0,0 +1,29 @@
+/**
+ * collectd - src/utils_cms_getval.h
+ * Copyright (C) 2008 Florian octo 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
+ * Free Software Foundation; only version 2 of the License is applicable.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Florian octo Forster <octo at verplant.org>
+ **/
+
+#ifndef UTILS_CMD_GETVAL_H
+#define UTILS_CMD_GETVAL_H 1
+
+int handle_getval (FILE *fh, char **fields, int fields_num);
+
+#endif /* UTILS_CMD_GETVAL_H */
+
+/* vim: set sw=2 sts=2 ts=8 : */