2 * collectd - src/utils_cms_getval.c
3 * Copyright (C) 2008 Florian octo Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Florian octo Forster <octo at verplant.org>
26 #include "utils_cache.h"
28 int handle_getval (FILE *fh, char **fields, int fields_num)
32 char *plugin_instance;
45 DEBUG ("unixsock plugin: Wrong number of fields: %i", fields_num);
46 fprintf (fh, "-1 Wrong number of fields: Got %i, expected 2.\n",
51 DEBUG ("unixsock plugin: Got query for `%s'", fields[1]);
53 if (strlen (fields[1]) < strlen ("h/p/t"))
55 fprintf (fh, "-1 Invalied identifier, %s", fields[1]);
60 status = parse_identifier (fields[1], &hostname,
61 &plugin, &plugin_instance,
62 &type, &type_instance);
65 DEBUG ("unixsock plugin: Cannot parse `%s'", fields[1]);
66 fprintf (fh, "-1 Cannot parse identifier.\n");
71 ds = plugin_get_ds (type);
74 DEBUG ("unixsock plugin: plugin_get_ds (%s) == NULL;", type);
75 fprintf (fh, "-1 Type `%s' is unknown.\n", type);
82 status = uc_get_rate_by_name (fields[1], &values, &values_num);
85 fprintf (fh, "-1 No such value");
90 if (ds->ds_num != values_num)
92 ERROR ("ds[%s]->ds_num = %i, "
93 "but uc_get_rate_by_name returned %i values.",
94 ds->type, ds->ds_num, values_num);
95 fprintf (fh, "-1 Error reading value from cache.\n");
101 fprintf (fh, "%u", (unsigned int) values_num);
102 for (i = 0; i < values_num; i++)
104 fprintf (fh, " %s=", ds->ds[i].name);
105 if (isnan (values[i]))
108 fprintf (fh, "%12e", values[i]);
117 } /* int handle_getval */
119 /* vim: set sw=2 sts=2 ts=8 : */