@cryptotaxi247 / netdata-1 / commits / 21d10026b

gpoints to gtime

Costa Tsaousis (ktsaou) committed Jan 27, 2018 at 12:07 UTC 21d10026b89c7e0044325b4bc7294c24ec034556
5 files changed +59 -36
src/rrd2json.c
+49 -26
@@ -1413,9 +1413,11 @@ static RRDR *rrdr_create(RRDSET *st, long n)
1413 return r;
1414 }
1415
1416 -RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int group_method, long group_points, int aligned)
1416 +RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int group_method, long group_time, int aligned)
1417 {
1418 +#ifdef NETDATA_INTERNAL_CHECKS
1419 int debug = rrdset_flag_check(st, RRDSET_FLAG_DEBUG)?1:0;
1420 +#endif
1421 int absolute_period_requested = -1;
1422
1423 time_t first_entry_t = rrdset_first_entry_t(st);
@@ -1486,20 +1488,41 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
1488 if(unlikely(group <= 0)) group = 1;
1489 if(unlikely(available_points % points > points / 2)) group++; // rounding to the closest integer
1490
1489 - // group_points enforces a certain grouping multiple
1491 + // group_time enforces a certain grouping multiple
1492 calculated_number group_sum_divisor = 1.0;
1491 - if(likely(group_points < 1)) group_points = 1;
1492 - else {
1493 - if (unlikely(group_points > available_points)) group_points = available_points; // group_points is above all the available points
1494 - if (unlikely(group < group_points)) group = group_points; // do not allow grouping below the desired one
1495 - if (unlikely(group > group_points && (group % group_points) > 0)) // make sure group is multiple of group_points
1496 - group += group_points - (group % group_points);
1493 + long group_points = 1;
1494 + if(unlikely(group_time > st->update_every)) {
1495 + if (unlikely(group_time > duration)) {
1496 + // group_time is above the available duration
1497 +
1498 + #ifdef NETDATA_INTERNAL_CHECKS
1499 + info("INTERNAL CHECK: %s: requested gtime %ld secs, is greater than the desired duration %ld secs", st->id, group_time, duration);
1500 + #endif
1501 +
1502 + group = points; // use all the points
1503 + }
1504 + else {
1505 + // the points we should group to satisfy gtime
1506 + group_points = group_time / st->update_every;
1507 + if(unlikely(group_time % group_points)) {
1508 + #ifdef NETDATA_INTERNAL_CHECKS
1509 + info("INTERNAL CHECK: %s: requested gtime %ld secs, is not a multiple of the chart's data collection frequency %d secs", st->id, group_time, st->update_every);
1510 + #endif
1511 +
1512 + group_points++;
1513 + }
1514 +
1515 + // adapt group according to group_points
1516 + if(unlikely(group < group_points)) group = group_points; // do not allow grouping below the desired one
1517 + if(unlikely(group % group_points)) group += group_points - (group % group_points); // make sure group is multiple of group_points
1518
1498 - group_sum_divisor = group / group_points;
1519 + //group_sum_divisor = group / group_points;
1520 + group_sum_divisor = (calculated_number)(group * st->update_every) / (calculated_number)group_time;
1521 + }
1522 }
1523
1501 - time_t after_new = after - (after % ( ((aligned)?group:group_points) * st->update_every ));
1502 - time_t before_new = before - (before % ( ((aligned)?group:group_points) * st->update_every ));
1524 + time_t after_new = after - (after % ( ((aligned)?group:1) * st->update_every ));
1525 + time_t before_new = before - (before % ( ((aligned)?group:1) * st->update_every ));
1526 long points_new = (before_new - after_new) / st->update_every / group;
1527
1528 // find the starting and ending slots in our round robin db
@@ -1533,9 +1556,6 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
1556
1557 if(group > group_points && group % group_points)
1558 error("INTERNAL CHECK: group %ld is not a multiple of the desired group points %ld", group, group_points);
1536 -
1537 - if(group_points > 1 && group_points * group_sum_divisor != group)
1538 - error("INTERNAL CHECK: group_sum_divisor " CALCULATED_NUMBER_FORMAT " * group_points %ld, is not equal to group %ld", group_sum_divisor, group_points, group);
1559 #endif
1560
1561 //info("RRD2RRDR(): %s: wanted %ld points, got %ld - group=%ld, wanted duration=%u, got %u - wanted %ld - %ld, got %ld - %ld", st->id, points, points_new, group, before - after, before_new - after_new, after, before, after_new, before_new);
@@ -1558,20 +1578,21 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
1578 // initialize our result set
1579
1580 RRDR *r = rrdr_create(st, points);
1561 - if(!r) {
1581 + if(unlikely(!r)) {
1582 #ifdef NETDATA_INTERNAL_CHECKS
1583 error("INTERNAL CHECK: Cannot create RRDR for %s, after=%u, before=%u, duration=%u, points=%ld", st->id, (uint32_t)after, (uint32_t)before, (uint32_t)duration, points);
1584 #endif
1585 return NULL;
1586 }
1567 - if(!r->d) {
1587 +
1588 + if(unlikely(!r->d)) {
1589 #ifdef NETDATA_INTERNAL_CHECKS
1590 error("INTERNAL CHECK: Returning empty RRDR (no dimensions in RRDSET) for %s, after=%u, before=%u, duration=%u, points=%ld", st->id, (uint32_t)after, (uint32_t)before, (uint32_t)duration, points);
1591 #endif
1592 return r;
1593 }
1594
1574 - if(absolute_period_requested == 1)
1595 + if(unlikely(absolute_period_requested == 1))
1596 r->result_options |= RRDR_RESULT_OPTION_ABSOLUTE;
1597 else
1598 r->result_options |= RRDR_RESULT_OPTION_RELATIVE;
@@ -1582,7 +1603,7 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
1603
1604 // -------------------------------------------------------------------------
1605 // checks for debugging
1585 -
1606 +#ifdef NETDATA_INTERNAL_CHECKS
1607 if(debug) debug(D_RRD_STATS, "INFO %s first_t: %u, last_t: %u, all_duration: %u, after: %u, before: %u, duration: %u, points: %ld, group: %ld, group_points: %ld"
1608 , st->id
1609 , (uint32_t)first_entry_t
@@ -1595,7 +1616,7 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
1616 , group
1617 , group_points
1618 );
1598 -
1619 +#endif
1620
1621 // -------------------------------------------------------------------------
1622 // temp arrays for keeping values per dimension
@@ -1627,6 +1648,7 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
1648 dt = st->update_every,
1649 group_start_t = 0;
1650
1651 +#ifdef NETDATA_INTERNAL_CHECKS
1652 if(unlikely(debug)) debug(D_RRD_STATS, "BEGIN %s after_t: %u (stop_at_t: %ld), before_t: %u (start_at_t: %ld), start_t(now): %u, current_entry: %ld, entries: %ld"
1653 , st->id
1654 , (uint32_t)after
@@ -1637,6 +1659,7 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
1659 , st->current_entry
1660 , st->entries
1661 );
1662 +#endif
1663
1664 r->group = group;
1665 r->update_every = (int)group * st->update_every;
@@ -1650,6 +1673,7 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
1673 if(unlikely(slot < 0)) slot = st->entries - 1;
1674 if(unlikely(slot == stop_at_slot)) stop_now = counter;
1675
1676 +#ifdef NETDATA_INTERNAL_CHECKS
1677 if(unlikely(debug)) debug(D_RRD_STATS, "ROW %s slot: %ld, entries_counter: %ld, group_count: %ld, added: %ld, now: %ld, %s %s"
1678 , st->id
1679 , slot
@@ -1660,14 +1684,13 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
1684 , (group_count + 1 == group)?"PRINT":" - "
1685 , (now >= after && now <= before)?"RANGE":" - "
1686 );
1687 +#endif
1688
1689 // make sure we return data in the proper time range
1690 if(unlikely(now > before)) continue;
1691 if(unlikely(now < after)) break;
1692
1668 - if(unlikely(group_count == 0)) {
1669 - group_start_t = now;
1670 - }
1693 + if(unlikely(group_count == 0)) group_start_t = now;
1694 group_count++;
1695
1696 if(unlikely(group_count == group)) {
@@ -1804,13 +1827,13 @@ int rrdset2value_api_v1(
1827 , long long after
1828 , long long before
1829 , int group_method
1807 - , long group_points
1830 + , long group_time
1831 , uint32_t options
1832 , time_t *db_after
1833 , time_t *db_before
1834 , int *value_is_null
1835 ) {
1813 - RRDR *r = rrd2rrdr(st, points, after, before, group_method, group_points, !(options & RRDR_OPTION_NOT_ALIGNED));
1836 + RRDR *r = rrd2rrdr(st, points, after, before, group_method, group_time, !(options & RRDR_OPTION_NOT_ALIGNED));
1837 if(!r) {
1838 if(value_is_null) *value_is_null = 1;
1839 return 500;
@@ -1855,13 +1878,13 @@ int rrdset2anything_api_v1(
1878 , long long after
1879 , long long before
1880 , int group_method
1858 - , long group_points
1881 + , long group_time
1882 , uint32_t options
1883 , time_t *latest_timestamp
1884 ) {
1885 st->last_accessed_time = now_realtime_sec();
1886
1864 - RRDR *r = rrd2rrdr(st, points, after, before, group_method, group_points, !(options & RRDR_OPTION_NOT_ALIGNED));
1887 + RRDR *r = rrd2rrdr(st, points, after, before, group_method, group_time, !(options & RRDR_OPTION_NOT_ALIGNED));
1888 if(!r) {
1889 buffer_strcat(wb, "Cannot generate output with these parameters on this chart.");
1890 return 500;
src/rrd2json.h
+2 -2
@@ -72,11 +72,11 @@ extern void rrd_stats_api_v1_charts_allmetrics_json(RRDHOST *host, BUFFER *wb);
72 extern void rrd_stats_api_v1_charts_allmetrics_shell(RRDHOST *host, BUFFER *wb);
73
74 extern int rrdset2anything_api_v1(RRDSET *st, BUFFER *out, BUFFER *dimensions, uint32_t format, long points
75 - , long long after, long long before, int group_method, long group_points, uint32_t options
75 + , long long after, long long before, int group_method, long group_time, uint32_t options
76 , time_t *latest_timestamp);
77
78 extern int rrdset2value_api_v1(RRDSET *st, BUFFER *wb, calculated_number *n, const char *dimensions, long points
79 - , long long after, long long before, int group_method, long group_points, uint32_t options
79 + , long long after, long long before, int group_method, long group_time, uint32_t options
80 , time_t *db_after, time_t *db_before, int *value_is_null);
81
82 #endif /* NETDATA_RRD2JSON_H */
src/web_api_v1.c
+4 -4
@@ -611,7 +611,7 @@ inline int web_client_api_request_v1_data(RRDHOST *host, struct web_client *w, c
611 char *chart = NULL
612 , *before_str = NULL
613 , *after_str = NULL
614 - , *group_points_str = NULL
614 + , *group_time_str = NULL
615 , *points_str = NULL;
616
617 int group = GROUP_AVERAGE;
@@ -640,7 +640,7 @@ inline int web_client_api_request_v1_data(RRDHOST *host, struct web_client *w, c
640 else if(!strcmp(name, "after")) after_str = value;
641 else if(!strcmp(name, "before")) before_str = value;
642 else if(!strcmp(name, "points")) points_str = value;
643 - else if(!strcmp(name, "gpoints")) group_points_str = value;
643 + else if(!strcmp(name, "gtime")) group_time_str = value;
644 else if(!strcmp(name, "group")) {
645 group = web_client_api_request_v1_data_group(value, GROUP_AVERAGE);
646 }
@@ -707,7 +707,7 @@ inline int web_client_api_request_v1_data(RRDHOST *host, struct web_client *w, c
707 long long before = (before_str && *before_str)?str2l(before_str):0;
708 long long after = (after_str && *after_str) ?str2l(after_str):0;
709 int points = (points_str && *points_str)?str2i(points_str):0;
710 - long group_points = (group_points_str && *group_points_str)?str2l(group_points_str):0;
710 + long group_time = (group_time_str && *group_time_str)?str2l(group_time_str):0;
711
712 debug(D_WEB_CLIENT, "%llu: API command 'data' for chart '%s', dimensions '%s', after '%lld', before '%lld', points '%d', group '%d', format '%u', options '0x%08x'"
713 , w->id
@@ -746,7 +746,7 @@ inline int web_client_api_request_v1_data(RRDHOST *host, struct web_client *w, c
746 buffer_strcat(w->response.data, "(");
747 }
748
749 - ret = rrdset2anything_api_v1(st, w->response.data, dimensions, format, points, after, before, group, group_points
749 + ret = rrdset2anything_api_v1(st, w->response.data, dimensions, format, points, after, before, group, group_time
750 , options, &last_timestamp_in_data);
751
752 if(format == DATASOURCE_DATATABLE_JSONP) {
web/netdata-swagger.json
+2 -2
@@ -133,9 +133,9 @@
133 "allowEmptyValue": false
134 },
135 {
136 - "name": "gpoints",
136 + "name": "gtime",
137 "in": "query",
138 - "description": "The grouping number of points. This is used in conjunction with group=average to change the units of metrics (ie when the data is per-second, setting gpoints=60 will turn them to per-minute).",
138 + "description": "The grouping number of seconds. This is used in conjunction with group=average to change the units of metrics (ie when the data is per-second, setting gtime=60 will turn them to per-minute).",
139 "required": false,
140 "type": "number",
141 "format": "integer",
web/netdata-swagger.yaml
+2 -2
@@ -95,9 +95,9 @@ paths:
95 enum: [ 'min', 'max', 'average', 'sum', 'incremental-sum' ]
96 default: 'average'
97 allowEmptyValue: false
98 - - name: gpoints
98 + - name: gtime
99 in: query
100 - description: 'The grouping number of points. This is used in conjunction with group=average to change the units of metrics (ie when the data is per-second, setting gpoints=60 will turn them to per-minute).'
100 + description: 'The grouping number of seconds. This is used in conjunction with group=average to change the units of metrics (ie when the data is per-second, setting gtime=60 will turn them to per-minute).'
101 required: false
102 type: number
103 format: integer