summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/rrd2json.c18
-rw-r--r--src/rrd2json.h3
-rw-r--r--src/web_client.c4
-rw-r--r--web/netdata-swagger.yaml12
4 files changed, 16 insertions, 21 deletions
diff --git a/src/rrd2json.c b/src/rrd2json.c
index 5adaab05b3..3614792858 100644
--- a/src/rrd2json.c
+++ b/src/rrd2json.c
@@ -1224,7 +1224,7 @@ cleanup:
return NULL;
}
-RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int group_method)
+RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int group_method, int aligned)
{
int debug = st->debug;
int absolute_period_requested = -1;
@@ -1253,10 +1253,10 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
absolute_period_requested = 1;
// make sure they are within our timeframe
- if(before > last_entry_t) before = last_entry_t;
+ if(before > last_entry_t) before = last_entry_t;
if(before < first_entry_t) before = first_entry_t;
- if(after > last_entry_t) after = last_entry_t;
+ if(after > last_entry_t) after = last_entry_t;
if(after < first_entry_t) after = first_entry_t;
// check if they are upside down
@@ -1285,13 +1285,13 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
// round group to the closest integer
if(available_points % points > points / 2) group++;
- time_t after_new = after - (after % (group * st->update_every));
- time_t before_new = before - (before % (group * st->update_every));
- long points_new = (before_new - after_new) / st->update_every / group;
+ time_t after_new = (aligned) ? (after - (after % (group * st->update_every))) : after;
+ time_t before_new = (aligned) ? (before - (before % (group * st->update_every))) : before;
+ long points_new = (before_new - after_new) / st->update_every / group;
// find the starting and ending slots in our round robin db
long start_at_slot = rrdset_time2slot(st, before_new),
- stop_at_slot = rrdset_time2slot(st, after_new);
+ stop_at_slot = rrdset_time2slot(st, after_new);
#ifdef NETDATA_INTERNAL_CHECKS
if(after_new < first_entry_t) {
@@ -1532,7 +1532,7 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
int rrd2value(RRDSET *st, BUFFER *wb, calculated_number *n, BUFFER *dimensions, long points, long long after, long long before, int group_method, uint32_t options, time_t *latest_timestamp, int *value_is_null)
{
- RRDR *r = rrd2rrdr(st, points, after, before, group_method);
+ RRDR *r = rrd2rrdr(st, points, after, before, group_method, !(options & RRDR_OPTION_NOT_ALIGNED));
if(!r) {
if(value_is_null) *value_is_null = 1;
return 500;
@@ -1566,7 +1566,7 @@ int rrd2value(RRDSET *st, BUFFER *wb, calculated_number *n, BUFFER *dimensions,
int rrd2format(RRDSET *st, BUFFER *wb, BUFFER *dimensions, uint32_t format, long points, long long after, long long before, int group_method, uint32_t options, time_t *latest_timestamp)
{
- RRDR *r = rrd2rrdr(st, points, after, before, group_method);
+ RRDR *r = rrd2rrdr(st, points, after, before, group_method, !(options & RRDR_OPTION_NOT_ALIGNED));
if(!r) {
buffer_strcat(wb, "Cannot generate output with these parameters on this chart.");
return 500;
diff --git a/src/rrd2json.h b/src/rrd2json.h
index 6ba9fb7fda..57b11b5b25 100644
--- a/src/rrd2json.h
+++ b/src/rrd2json.h
@@ -42,7 +42,7 @@ extern char *hostname;
#define RRDR_OPTION_NONZERO 0x00000001 // don't output dimensions will just zero values
#define RRDR_OPTION_REVERSED 0x00000002 // output the rows in reverse order (oldest to newest)
#define RRDR_OPTION_ABSOLUTE 0x00000004 // values positive, for DATASOURCE_SSV before summing
-#define RRDR_OPTION_MIN2MAX 0x00000008 // for DATASOURCE_SSV, out max - min, instead of sum
+#define RRDR_OPTION_MIN2MAX 0x00000008 // when adding dimensions, use max - min, instead of sum
#define RRDR_OPTION_SECONDS 0x00000010 // output seconds, instead of dates
#define RRDR_OPTION_MILLISECONDS 0x00000020 // output milliseconds, instead of dates
#define RRDR_OPTION_NULL2ZERO 0x00000040 // do not show nulls, convert them to zeros
@@ -51,6 +51,7 @@ extern char *hostname;
#define RRDR_OPTION_JSON_WRAP 0x00000200 // wrap the response in a JSON header with info about the result
#define RRDR_OPTION_LABEL_QUOTES 0x00000400 // in CSV output, wrap header labels in double quotes
#define RRDR_OPTION_PERCENTAGE 0x00000800 // give values as percentage of total
+#define RRDR_OPTION_NOT_ALIGNED 0x00001000 // do not align charts for persistant timeframes
extern void rrd_stats_api_v1_chart(RRDSET *st, BUFFER *wb);
extern void rrd_stats_api_v1_charts(BUFFER *wb);
diff --git a/src/web_client.c b/src/web_client.c
index b127b163ec..a41ccbb5d7 100644
--- a/src/web_client.c
+++ b/src/web_client.c
@@ -559,6 +559,8 @@ uint32_t web_client_api_request_v1_data_options(char *o)
ret |= RRDR_OPTION_GOOGLE_JSON;
else if(!strcmp(tok, "percentage"))
ret |= RRDR_OPTION_PERCENTAGE;
+ else if(!strcmp(tok, "unaligned"))
+ ret |= RRDR_OPTION_NOT_ALIGNED;
}
return ret;
@@ -802,7 +804,7 @@ int web_client_api_v1_badge(struct web_client *w, char *url) {
ret = 500;
// if the collected value is too old, don't calculate its value
- if(st->last_updated.tv_sec >= (time(NULL) - (st->update_every * st->gap_when_lost_iterations_above)))
+ if(rrdset_last_entry_t(st) >= (time(NULL) - (st->update_every * st->gap_when_lost_iterations_above)))
ret = rrd2value(st, w->response.data, &n, dimensions, points, after, before, group, options, &latest_timestamp, &value_is_null);
// if the value cannot be calculated, show empty badge
diff --git a/web/netdata-swagger.yaml b/web/netdata-swagger.yaml
index 55211b39de..2a80d4cd92 100644
--- a/web/netdata-swagger.yaml
+++ b/web/netdata-swagger.yaml
@@ -110,7 +110,7 @@ paths:
type: array
items:
type: string
- enum: [ 'nonzero', 'flip', 'jsonwrap', 'min2max', 'seconds', 'milliseconds', 'abs', 'absolute', 'absolute-sum', 'null2zero', 'objectrows', 'google_json', 'percentage' ]
+ enum: [ 'nonzero', 'flip', 'jsonwrap', 'min2max', 'seconds', 'milliseconds', 'abs', 'absolute', 'absolute-sum', 'null2zero', 'objectrows', 'google_json', 'percentage', 'unaligned' ]
collectionFormat: pipes
default: [seconds, jsonwrap]
allowEmptyValue: false
@@ -182,14 +182,6 @@ paths:
type: number
format: integer
default: 0
- - name: points
- in: query
- description: 'The number of points to be returned. If not given, or it is <= 0, or it is bigger than the points stored in the round robin database for this chart for the given duration, all the available collected values for the given duration are returned.'
- required: true
- type: number
- format: integer
- allowEmptyValue: false
- default: 20
- name: group
in: query
description: 'The grouping method. If multiple collected values are to be grouped in order to return fewer points, this parameters defines the method of grouping. Two methods are supported, "max" and "average". "max" is actually calculated on the absolute value collected (so it works for both positive and negative dimesions to return the most extreme value in either direction).'
@@ -205,7 +197,7 @@ paths:
type: array
items:
type: string
- enum: [ 'nonzero', 'flip', 'abs', 'absolute', 'absolute-sum', 'null2zero', 'percentage' ]
+ enum: [ 'abs', 'absolute', 'absolute-sum', 'null2zero', 'percentage', 'unaligned' ]
collectionFormat: pipes
default: ['absolute']
allowEmptyValue: true