X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdp_rrdtool.c;h=624d3ad161e658f2ab9dd9599d91927d62b02b95;hb=c08cfbb86fc765dc9aac1e8f22548aa05da722fc;hp=61fd058279b690fea13e8dc00d786b94923295be;hpb=84dc0c7ed47ead2115755a93ff4cab9e8bf10a9f;p=collection4.git diff --git a/src/dp_rrdtool.c b/src/dp_rrdtool.c index 61fd058..624d3ad 100644 --- a/src/dp_rrdtool.c +++ b/src/dp_rrdtool.c @@ -33,6 +33,7 @@ #include #include "graph_types.h" +#include "graph_config.h" #include "graph_ident.h" #include "data_provider.h" #include "filesystem.h" @@ -244,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); @@ -290,12 +291,13 @@ static int get_ident_data (void *priv, rrd_value_t *data; int status; - unsigned long ds_index; - unsigned long data_index; - unsigned long data_length; + dp_time_t first_value_time; + dp_time_t interval; + size_t data_points_num; + double *data_points = NULL; - dp_data_point_t *dp = NULL; - size_t dp_num = 0; + unsigned long ds_index; + size_t i; status = ident_to_rrdfile (ident, config, filename, sizeof (filename)); if (status != 0) @@ -321,7 +323,7 @@ static int get_ident_data (void *priv, free (ds_namv[i]); \ free (ds_namv); \ free (data); \ - free (dp); \ + free (data_points); \ return (ret_status); \ } while (0) @@ -332,24 +334,23 @@ static int get_ident_data (void *priv, if (ds_index >= ds_count) BAIL_OUT (ENOENT); - /* 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) + memset (&first_value_time, 0, sizeof (first_value_time)); + first_value_time.tv_sec = rrd_start; + memset (&interval, 0, sizeof (interval)); + interval.tv_sec = (time_t) step; + data_points_num = (size_t) ((rrd_end - rrd_start) / step); + data_points = calloc (data_points_num, sizeof (*data_points)); + if (data_points == NULL) BAIL_OUT (ENOMEM); - for (data_index = 0; data_index < data_length; data_index++) + for (i = 0; i < data_points_num; i++) { - unsigned long index = (ds_count * data_index) + ds_index; - - 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]; + unsigned long index = (ds_count * ((unsigned long) i)) + ds_index; + data_points[i] = (double) data[index]; } - status = (*cb) (ident, ds_name, dp, dp_num, ud); + status = (*cb) (ident, ds_name, first_value_time, interval, + data_points_num, data_points, ud); if (status != 0) BAIL_OUT (status); @@ -370,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 = { @@ -380,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;