summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 718d12d)
raw | patch | inline | side by side (parent: 718d12d)
author | Florian Forster <octo@noris.net> | |
Wed, 22 Dec 2010 10:49:30 +0000 (11:49 +0100) | ||
committer | Florian Forster <octo@noris.net> | |
Wed, 22 Dec 2010 10:49:30 +0000 (11:49 +0100) |
share/collection.js | patch | blob | history | |
src/data_provider.h | patch | blob | history | |
src/dp_rrdtool.c | patch | blob | history | |
src/graph_ident.c | patch | blob | history |
diff --git a/share/collection.js b/share/collection.js
index 63bfd0857993bd098ce42ed82554f71161785e69..20af9cb1033ecaa358f0f9d535ad2f6523b1df36 100644 (file)
--- a/share/collection.js
+++ b/share/collection.js
var j;
var x = [];
var y = [];
+ var x_val;
+
+ x_val = ds.first_value_time;
for (j = 0; j < ds.data.length; j++)
{
- var dp = ds.data[j];
- var t = dp[0];
- var v = dp[1];
+ var y_val = ds.data[j];
+
+ x.push (x_val);
+ y.push (y_val);
- x.push (t);
- y.push (v);
+ x_val += ds.interval;
}
x_data.push (x);
diff --git a/src/data_provider.h b/src/data_provider.h
index 87025f21ad31019c4b4c9218739f19e1f531d70c..08cff9ae014e593896aae3ed5440e6989710a753 100644 (file)
--- a/src/data_provider.h
+++ b/src/data_provider.h
/* Callback passed to the "get_ident_data" function. */
typedef int (*dp_get_ident_data_callback) (graph_ident_t *, const char *ds_name,
- const dp_data_point_t *dp, size_t dp_num,
+ dp_time_t first_value_time, dp_time_t interval,
+ size_t data_points_num, double *data_points,
void *);
struct data_provider_s
diff --git a/src/dp_rrdtool.c b/src/dp_rrdtool.c
index 78554c71d36cdf2fbfb3b07bf139d200ae1a9806..624d3ad161e658f2ab9dd9599d91927d62b02b95 100644 (file)
--- a/src/dp_rrdtool.c
+++ b/src/dp_rrdtool.c
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)
free (ds_namv[i]); \
free (ds_namv); \
free (data); \
- free (dp); \
+ free (data_points); \
return (ret_status); \
} while (0)
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);
diff --git a/src/graph_ident.c b/src/graph_ident.c
index 24f89c5e76c2003b8dd2f9dd7bc2c6742df3c084..02e1aaa3f74518075f2e8cdd558b25bf32ef15eb 100644 (file)
--- a/src/graph_ident.c
+++ b/src/graph_ident.c
static int ident_data_to_json__get_ident_data (
__attribute__((unused)) graph_ident_t *ident, /* {{{ */
__attribute__((unused)) const char *ds_name,
- const dp_data_point_t *dp, size_t dp_num,
+ dp_time_t first_value_time, dp_time_t interval,
+ size_t data_points_num, double *data_points,
void *user_data)
{
ident_data_to_json__data_t *data = user_data;
size_t i;
+ double first_value_time_double;
+ double interval_double;
+
/* TODO: Make points_num_limit configurable. */
/* points_num_limit: The number of data-points to send at least. */
size_t points_num_limit = 400;
size_t points_consolidate;
- if (dp_num <= points_num_limit)
+ first_value_time_double = ((double) first_value_time.tv_sec)
+ + (((double) first_value_time.tv_nsec) / 1000000000.0);
+ interval_double = ((double) interval.tv_sec)
+ + (((double) interval.tv_nsec) / 1000000000.0);
+
+ if (data_points_num <= points_num_limit)
points_consolidate = 1;
else
- points_consolidate = dp_num / points_num_limit;
+ points_consolidate = data_points_num / points_num_limit;
+
+ if (points_consolidate > 1)
+ {
+ size_t offset = data_points_num % points_consolidate;
+
+ first_value_time_double += ((double) offset) * interval_double;
+ interval_double *= ((double) points_consolidate);
+ }
+
+ yajl_gen_map_open (data->handler);
+
+ yajl_gen_string_cast (data->handler, "first_value_time", strlen ("first_value_time"));
+ yajl_gen_double (data->handler, first_value_time_double);
+ yajl_gen_string_cast (data->handler, "interval", strlen ("interval"));
+ yajl_gen_double (data->handler, interval_double);
+
+ yajl_gen_string_cast (data->handler, "data", strlen ("data"));
yajl_gen_array_open (data->handler);
- for (i = (dp_num % points_consolidate); i < dp_num; i += points_consolidate)
+ for (i = (data_points_num % points_consolidate);
+ i < data_points_num;
+ i += points_consolidate)
{
size_t j;
double sum = 0.0;
long num = 0;
- yajl_gen_array_open (data->handler);
- yajl_gen_integer (data->handler, (long) dp[i].time.tv_sec);
-
for (j = 0; j < points_consolidate; j++)
{
- if (isnan (dp[i+j].value))
+ if (isnan (data_points[i+j]))
continue;
- sum += dp[i+j].value;
+ sum += data_points[i+j];
num++;
}
yajl_gen_null (data->handler);
else
yajl_gen_double (data->handler, sum / ((double) num));
-
- yajl_gen_array_close (data->handler);
}
yajl_gen_array_close (data->handler);
yajl_gen_string_cast (data->handler, "data_source", strlen ("data_source"));
yajl_gen_string_cast (data->handler, ds_name, strlen (ds_name));
- yajl_gen_string_cast (data->handler, "data", strlen ("data"));
status = data_provider_get_ident_data (ident, ds_name,
data->begin, data->end,
ident_data_to_json__get_ident_data,