X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdp_rrdtool.c;h=78554c71d36cdf2fbfb3b07bf139d200ae1a9806;hb=e0b8e6b3289ee56fba4dbee099f8fd25d5028639;hp=6db02059d6a95ebfe87fd17b2a0b98e5bd6f8eeb;hpb=9e7f6711d2cebfec79c8038c51037ba79810323c;p=collection4.git diff --git a/src/dp_rrdtool.c b/src/dp_rrdtool.c index 6db0205..78554c7 100644 --- a/src/dp_rrdtool.c +++ b/src/dp_rrdtool.c @@ -21,12 +21,7 @@ * Florian octo Forster **/ -#include "graph_types.h" -#include "graph_ident.h" -#include "data_provider.h" -#include "filesystem.h" -#include "oconfig.h" -#include "common.h" +#include "config.h" #include #include @@ -37,6 +32,17 @@ #include +#include "graph_types.h" +#include "graph_config.h" +#include "graph_ident.h" +#include "data_provider.h" +#include "filesystem.h" +#include "oconfig.h" +#include "common.h" + +#include +#include + struct dp_rrdtool_s { char *data_dir; @@ -52,23 +58,27 @@ struct dp_get_idents_data_s typedef struct dp_get_idents_data_s dp_get_idents_data_t; static int scan_type_cb (__attribute__((unused)) const char *base_dir, - const char *sub_dir, void *ud) + const char *file, void *ud) { /* {{{ */ dp_get_idents_data_t *data = ud; - size_t sub_dir_len; + size_t file_len; char type_copy[1024]; + size_t type_copy_len; char *type_inst; - sub_dir_len = strlen (sub_dir); - if (sub_dir_len < 5) + file_len = strlen (file); + if (file_len < 5) return (0); /* Ignore files that don't end in ".rrd". */ - if (strcasecmp (".rrd", sub_dir + (sub_dir_len - 4)) != 0) + if (strcasecmp (".rrd", file + (file_len - 4)) != 0) return (0); - strncpy (type_copy, sub_dir, sizeof (type_copy)); - type_copy[sub_dir_len - 4] = 0; + strncpy (type_copy, file, sizeof (type_copy)); + type_copy_len = file_len - 4; + if (type_copy_len > (sizeof (type_copy) - 1)) + type_copy_len = sizeof (type_copy) - 1; + type_copy[type_copy_len] = 0; type_inst = strchr (type_copy, '-'); if (type_inst != NULL) @@ -217,7 +227,8 @@ static int get_ident_ds_names (void *priv, graph_ident_t *ident, info = rrd_info (rrd_argc, rrd_argv); if (info == NULL) { - printf ("%s: rrd_info (%s) failed.\n", __func__, file); + fprintf (stderr, "%s: rrd_info (%s) failed.\n", __func__, file); + fflush (stderr); return (-1); } @@ -234,13 +245,13 @@ static int get_ident_ds_names (void *priv, graph_ident_t *ident, continue; keylen = strlen (ptr->key); - if (keylen < strlen ("ds[?].index")) + if (keylen < strlen ("ds[?].type")) continue; - dslen = keylen - strlen ("ds[].index"); + dslen = keylen - strlen ("ds[].type"); assert (dslen >= 1); - if (strcmp ("].index", ptr->key + (strlen ("ds[") + dslen)) != 0) + if (strcmp ("].type", ptr->key + (strlen ("ds[") + dslen)) != 0) continue; ds = malloc (dslen + 1); @@ -284,6 +295,9 @@ static int get_ident_data (void *priv, unsigned long data_index; unsigned long data_length; + dp_data_point_t *dp = NULL; + size_t dp_num = 0; + status = ident_to_rrdfile (ident, config, filename, sizeof (filename)); if (status != 0) return (status); @@ -308,6 +322,7 @@ static int get_ident_data (void *priv, free (ds_namv[i]); \ free (ds_namv); \ free (data); \ + free (dp); \ return (ret_status); \ } while (0) @@ -321,21 +336,24 @@ static int get_ident_data (void *priv, /* Number of data points returned. */ data_length = (rrd_end - rrd_start) / step; + dp_num = (size_t) data_length; + dp = calloc (dp_num, sizeof (*dp)); + if (dp == NULL) + BAIL_OUT (ENOMEM); + for (data_index = 0; data_index < data_length; data_index++) { - dp_data_point_t dp; unsigned long index = (ds_count * data_index) + ds_index; - memset (&dp, 0, sizeof (dp)); - dp.time.tv_sec = rrd_start + (data_index * step); - dp.time.tv_nsec = 0; - dp.value = (double) data[index]; - - status = (*cb) (ident, ds_name, &dp, ud); - if (status != 0) - BAIL_OUT (status); + dp[data_index].time.tv_sec = rrd_start + (data_index * step); + dp[data_index].time.tv_nsec = 0; + dp[data_index].value = (double) data[index]; } + status = (*cb) (ident, ds_name, dp, dp_num, ud); + if (status != 0) + BAIL_OUT (status); + BAIL_OUT (0); #undef BAIL_OUT } /* }}} int get_ident_data */ @@ -353,6 +371,7 @@ static int print_graph (void *priv, int dp_rrdtool_config (const oconfig_item_t *ci) { /* {{{ */ dp_rrdtool_t *conf; + int i; data_provider_t dp = { @@ -363,10 +382,33 @@ int dp_rrdtool_config (const oconfig_item_t *ci) /* private_data = */ NULL }; - /* FIXME: Actuelly do config parsing here. */ - ci = NULL; /* FIXME */ - conf = malloc (sizeof (dp_rrdtool_t)); - conf->data_dir = strdup ("/var/lib/collectd/rrd"); + conf = malloc (sizeof (*conf)); + if (conf == NULL) + return (ENOMEM); + memset (conf, 0, sizeof (*conf)); + conf->data_dir = NULL; + + for (i = 0; i < ci->children_num; i++) + { + oconfig_item_t *child = ci->children + i; + + if (strcasecmp ("DataDir", child->key) == 0) + graph_config_get_string (child, &conf->data_dir); + else + { + fprintf (stderr, "dp_rrdtool_config: Ignoring unknown config option " + "\"%s\"\n", child->key); + fflush (stderr); + } + } + + if (conf->data_dir == NULL) + conf->data_dir = strdup ("/var/lib/collectd/rrd"); + if (conf->data_dir == NULL) + { + free (conf); + return (ENOMEM); + } dp.private_data = conf;