@cryptotaxi247 / netdata-1 / commits / c8ac4c1af

preparation for health API (render the alarms on the dashboard)

Costa Tsaousis committed Aug 25, 2016 at 01:39 UTC c8ac4c1af5b03c1091986e71d3f813209f7eb543
6 files changed +250 -67
src/health.c
+143 -52
@@ -415,6 +415,31 @@ void rrddimvar_free(RRDDIMVAR *rs) {
415 // ----------------------------------------------------------------------------
416 // RRDCALC management
417
418 +static inline const char *rrdcalc_status2string(int status) {
419 + switch(status) {
420 + case RRDCALC_STATUS_UNINITIALIZED:
421 + return "UNINITIALIZED";
422 +
423 + case RRDCALC_STATUS_UNDEFINED:
424 + return "UNDEFINED";
425 +
426 + case RRDCALC_STATUS_CLEAR:
427 + return "CLEAR";
428 +
429 + case RRDCALC_STATUS_RAISED:
430 + return "RAISED";
431 +
432 + case RRDCALC_STATUS_WARNING:
433 + return "WARNING";
434 +
435 + case RRDCALC_STATUS_CRITICAL:
436 + return "CRITICAL";
437 +
438 + default:
439 + return "UNKNOWN";
440 + }
441 +}
442 +
443 static void rrdsetcalc_link(RRDSET *st, RRDCALC *rc) {
444 debug(D_HEALTH, "Health linking alarm '%s.%s' to chart '%s' of host '%s'", rc->chart?rc->chart:"NOCHART", rc->name, st->id, st->rrdhost->hostname);
445
@@ -546,16 +571,22 @@ static inline void rrdcalc_create_part2(RRDHOST *host, RRDCALC *rc) {
571
572 if(rc->calculation) {
573 rc->calculation->this = &rc->value;
574 + rc->calculation->after = &rc->db_after;
575 + rc->calculation->before = &rc->db_before;
576 rc->calculation->rrdcalc = rc;
577 }
578
579 if(rc->warning) {
580 rc->warning->this = &rc->value;
581 + rc->warning->after = &rc->db_after;
582 + rc->warning->before = &rc->db_before;
583 rc->warning->rrdcalc = rc;
584 }
585
586 if(rc->critical) {
587 rc->critical->this = &rc->value;
588 + rc->critical->after = &rc->db_after;
589 + rc->critical->before = &rc->db_before;
590 rc->critical->rrdcalc = rc;
591 }
592
@@ -1380,6 +1411,91 @@ void health_init(void) {
1411 rrdhost_unlock(&localhost);
1412 }
1413
1414 +// ----------------------------------------------------------------------------
1415 +// JSON generation
1416 +
1417 +static inline void health_rrdcalc2json_nolock(BUFFER *wb, RRDCALC *rc) {
1418 + buffer_sprintf(wb,
1419 + "\t\t\"%s.%s\": {"
1420 + "\t\t\t\"name\": \"%s\",\n"
1421 + "\t\t\t\"chart\": \"%s\",\n"
1422 + "\t\t\t\"dimensions\": \"%s\",\n"
1423 + "\t\t\t\"exec\": \"%s\",\n"
1424 + "\t\t\t\"source\": \"%s\",\n"
1425 + "\t\t\t\"calc\": \"%s\",\n"
1426 + "\t\t\t\"calc_parsed\": \"%s\",\n"
1427 + "\t\t\t\"warn\": \"%s\",\n"
1428 + "\t\t\t\"warn_parsed\": \"%s\",\n"
1429 + "\t\t\t\"crit\": \"%s\",\n"
1430 + "\t\t\t\"crit_parsed\": \"%s\",\n"
1431 + "\t\t\t\"value\": %Lf,\n"
1432 + "\t\t\t\"value_after\": %lu,\n"
1433 + "\t\t\t\"value_before\": %lu,\n"
1434 + "\t\t\t\"green\": %Lf,\n"
1435 + "\t\t\t\"red\": %Lf,\n"
1436 + "\t\t\t\"status\": \"%s\",\n"
1437 + "\t\t\t\"last_status_change\": %lu,\n"
1438 + "\t\t\t\"last_updated\": %lu,\n"
1439 + "\t\t\t\"next_update\": %lu,\n"
1440 + "\t\t\t\"update_every\": %d,\n"
1441 + "\t\t\t\"lookup_method\": \"%s\",\n"
1442 + "\t\t\t\"lookup_after\": %d,\n"
1443 + "\t\t\t\"lookup_before\": %d,\n"
1444 + "\t\t\t\"lookup_options\": \""
1445 + , rc->chart, rc->name
1446 + , rc->name
1447 + , rc->chart
1448 + , rc->dimensions?rc->dimensions:""
1449 + , rc->exec?rc->exec:health_default_exec
1450 + , rc->source
1451 + , rc->calculation?rc->calculation->source:""
1452 + , rc->calculation?rc->calculation->parsed_as:""
1453 + , rc->warning?rc->warning->source:""
1454 + , rc->warning?rc->warning->parsed_as:""
1455 + , rc->critical?rc->critical->source:""
1456 + , rc->critical?rc->critical->parsed_as:""
1457 + , rc->value
1458 + , (unsigned long)rc->db_after
1459 + , (unsigned long)rc->db_before
1460 + , rc->green
1461 + , rc->red
1462 + , rrdcalc_status2string(rc->status)
1463 + , (unsigned long)rc->last_status_change
1464 + , (unsigned long)rc->last_updated
1465 + , (unsigned long)rc->next_update
1466 + , rc->update_every
1467 + , group_method2string(rc->group)
1468 + , rc->after
1469 + , rc->before
1470 + );
1471 +
1472 + buffer_data_options2string(wb, rc->options);
1473 + buffer_strcat(wb, "\"\n\t}");
1474 +}
1475 +
1476 +//void health_rrdcalctemplate2json_nolock(BUFFER *wb, RRDCALCTEMPLATE *rt) {
1477 +//
1478 +//}
1479 +
1480 +void health_json(RRDHOST *host, BUFFER *wb) {
1481 + rrdhost_rdlock(&localhost);
1482 +
1483 + buffer_strcat(wb, "{\n\t\"alarms\": {");
1484 + RRDCALC *rc;
1485 + for(rc = host->alarms; rc ; rc = rc->next)
1486 + health_rrdcalc2json_nolock(wb, rc);
1487 +
1488 + buffer_strcat(wb, "\n},\n\t\"templates\": {");
1489 +
1490 +// RRDCALCTEMPLATE *rt;
1491 +// for(rt = host->templates; rt ; rt = rt->next)
1492 +// health_rrdcalctemplate2json_nolock(wb, rt);
1493 +
1494 + buffer_strcat(wb, "\n}\n");
1495 + rrdhost_unlock(&localhost);
1496 +}
1497 +
1498 +
1499 // ----------------------------------------------------------------------------
1500 // re-load health configuration
1501
@@ -1455,31 +1571,6 @@ static inline int rrdcalc_value2status(calculated_number n) {
1571 return RRDCALC_STATUS_CLEAR;
1572 }
1573
1458 -static inline const char *rrdcalc_status2string(int status) {
1459 - switch(status) {
1460 - case RRDCALC_STATUS_UNINITIALIZED:
1461 - return "UNINITIALIZED";
1462 -
1463 - case RRDCALC_STATUS_UNDEFINED:
1464 - return "UNDEFINED";
1465 -
1466 - case RRDCALC_STATUS_CLEAR:
1467 - return "CLEAR";
1468 -
1469 - case RRDCALC_STATUS_RAISED:
1470 - return "RAISED";
1471 -
1472 - case RRDCALC_STATUS_WARNING:
1473 - return "WARNING";
1474 -
1475 - case RRDCALC_STATUS_CRITICAL:
1476 - return "CRITICAL";
1477 -
1478 - default:
1479 - return "UNKNOWN";
1480 - }
1481 -}
1482 -
1574 static inline void health_alarm_execute(ALARM_ENTRY *ae) {
1575 if(ae->old_status == RRDCALC_STATUS_UNINITIALIZED && ae->new_status == RRDCALC_STATUS_CLEAR)
1576 return;
@@ -1670,12 +1761,12 @@ void *health_main(void *ptr) {
1761 // 2. if there is calculation expression, run it
1762
1763 if (unlikely(RRDCALC_HAS_DB_LOOKUP(rc))) {
1673 - time_t old_db_timestamp = rc->db_timestamp;
1764 + time_t old_db_timestamp = rc->db_before;
1765 int value_is_null = 0;
1766
1767 int ret = rrd2value(rc->rrdset, wb, &rc->value,
1768 rc->dimensions, 1, rc->after, rc->before, rc->group,
1678 - rc->options, &rc->db_timestamp, &value_is_null);
1769 + rc->options, &rc->db_after, &rc->db_before, &value_is_null);
1770
1771 if (unlikely(ret != 200)) {
1772 // database lookup failed
@@ -1683,26 +1774,26 @@ void *health_main(void *ptr) {
1774
1775 debug(D_HEALTH, "Health alarm '%s.%s': database lookup returned error %d", rc->chart?rc->chart:"NOCHART", rc->name, ret);
1776
1686 - if (unlikely(!(rc->rrdcalc_options & RRDCALC_OPTION_DB_ERROR))) {
1687 - rc->rrdcalc_options |= RRDCALC_OPTION_DB_ERROR;
1777 + if (unlikely(!(rc->rrdcalc_flags & RRDCALC_FLAG_DB_ERROR))) {
1778 + rc->rrdcalc_flags |= RRDCALC_FLAG_DB_ERROR;
1779 error("Health alarm '%s.%s': database lookup returned error %d", rc->chart?rc->chart:"NOCHART", rc->name, ret);
1780 }
1781 }
1691 - else if (unlikely(rc->rrdcalc_options & RRDCALC_OPTION_DB_ERROR))
1692 - rc->rrdcalc_options &= ~RRDCALC_OPTION_DB_ERROR;
1782 + else if (unlikely(rc->rrdcalc_flags & RRDCALC_FLAG_DB_ERROR))
1783 + rc->rrdcalc_flags &= ~RRDCALC_FLAG_DB_ERROR;
1784
1694 - if (unlikely(old_db_timestamp == rc->db_timestamp)) {
1785 + if (unlikely(old_db_timestamp == rc->db_before)) {
1786 // database is stale
1787
1788 debug(D_HEALTH, "Health alarm '%s.%s': database is stale", rc->chart?rc->chart:"NOCHART", rc->name);
1789
1699 - if (unlikely(!(rc->rrdcalc_options & RRDCALC_OPTION_DB_STALE))) {
1700 - rc->rrdcalc_options |= RRDCALC_OPTION_DB_STALE;
1790 + if (unlikely(!(rc->rrdcalc_flags & RRDCALC_FLAG_DB_STALE))) {
1791 + rc->rrdcalc_flags |= RRDCALC_FLAG_DB_STALE;
1792 error("Health alarm '%s.%s': database is stale", rc->chart?rc->chart:"NOCHART", rc->name);
1793 }
1794 }
1704 - else if (unlikely(rc->rrdcalc_options & RRDCALC_OPTION_DB_STALE))
1705 - rc->rrdcalc_options &= ~RRDCALC_OPTION_DB_STALE;
1795 + else if (unlikely(rc->rrdcalc_flags & RRDCALC_FLAG_DB_STALE))
1796 + rc->rrdcalc_flags &= ~RRDCALC_FLAG_DB_STALE;
1797
1798 if (unlikely(value_is_null)) {
1799 // collected value is null
@@ -1712,14 +1803,14 @@ void *health_main(void *ptr) {
1803 debug(D_HEALTH, "Health alarm '%s.%s': database lookup returned empty value (possibly value is not collected yet)",
1804 rc->chart?rc->chart:"NOCHART", rc->name);
1805
1715 - if (unlikely(!(rc->rrdcalc_options & RRDCALC_OPTION_DB_NAN))) {
1716 - rc->rrdcalc_options |= RRDCALC_OPTION_DB_NAN;
1806 + if (unlikely(!(rc->rrdcalc_flags & RRDCALC_FLAG_DB_NAN))) {
1807 + rc->rrdcalc_flags |= RRDCALC_FLAG_DB_NAN;
1808 error("Health alarm '%s.%s': database lookup returned empty value (possibly value is not collected yet)",
1809 rc->chart?rc->chart:"NOCHART", rc->name);
1810 }
1811 }
1721 - else if (unlikely(rc->rrdcalc_options & RRDCALC_OPTION_DB_NAN))
1722 - rc->rrdcalc_options &= ~RRDCALC_OPTION_DB_NAN;
1812 + else if (unlikely(rc->rrdcalc_flags & RRDCALC_FLAG_DB_NAN))
1813 + rc->rrdcalc_flags &= ~RRDCALC_FLAG_DB_NAN;
1814
1815 debug(D_HEALTH, "Health alarm '%s.%s': database lookup gave value "
1816 CALCULATED_NUMBER_FORMAT, rc->chart?rc->chart:"NOCHART", rc->name, rc->value);
@@ -1734,15 +1825,15 @@ void *health_main(void *ptr) {
1825 debug(D_HEALTH, "Health alarm '%s.%s': failed to evaluate calculation with error: %s",
1826 rc->chart?rc->chart:"NOCHART", rc->name, buffer_tostring(rc->calculation->error_msg));
1827
1737 - if (unlikely(!(rc->rrdcalc_options & RRDCALC_OPTION_CALC_ERROR))) {
1738 - rc->rrdcalc_options |= RRDCALC_OPTION_CALC_ERROR;
1828 + if (unlikely(!(rc->rrdcalc_flags & RRDCALC_FLAG_CALC_ERROR))) {
1829 + rc->rrdcalc_flags |= RRDCALC_FLAG_CALC_ERROR;
1830 error("Health alarm '%s.%s': failed to evaluate calculation with error: %s",
1831 rc->chart?rc->chart:"NOCHART", rc->name, buffer_tostring(rc->calculation->error_msg));
1832 }
1833 }
1834 else {
1744 - if (unlikely(rc->rrdcalc_options & RRDCALC_OPTION_CALC_ERROR))
1745 - rc->rrdcalc_options &= ~RRDCALC_OPTION_CALC_ERROR;
1835 + if (unlikely(rc->rrdcalc_flags & RRDCALC_FLAG_CALC_ERROR))
1836 + rc->rrdcalc_flags &= ~RRDCALC_FLAG_CALC_ERROR;
1837
1838 debug(D_HEALTH, "Health alarm '%s.%s': calculation expression gave value "
1839 CALCULATED_NUMBER_FORMAT
@@ -1776,15 +1867,15 @@ void *health_main(void *ptr) {
1867 debug(D_HEALTH, "Health alarm '%s.%s': warning expression failed with error: %s",
1868 rc->chart?rc->chart:"NOCHART", rc->name, buffer_tostring(rc->warning->error_msg));
1869
1779 - if (unlikely(!(rc->rrdcalc_options & RRDCALC_OPTION_WARN_ERROR))) {
1780 - rc->rrdcalc_options |= RRDCALC_OPTION_WARN_ERROR;
1870 + if (unlikely(!(rc->rrdcalc_flags & RRDCALC_FLAG_WARN_ERROR))) {
1871 + rc->rrdcalc_flags |= RRDCALC_FLAG_WARN_ERROR;
1872 error("Health alarm '%s.%s': warning expression failed with error: %s",
1873 rc->chart?rc->chart:"NOCHART", rc->name, buffer_tostring(rc->warning->error_msg));
1874 }
1875 }
1876 else {
1786 - if(unlikely(rc->rrdcalc_options & RRDCALC_OPTION_WARN_ERROR))
1787 - rc->rrdcalc_options &= ~RRDCALC_OPTION_WARN_ERROR;
1877 + if(unlikely(rc->rrdcalc_flags & RRDCALC_FLAG_WARN_ERROR))
1878 + rc->rrdcalc_flags &= ~RRDCALC_FLAG_WARN_ERROR;
1879
1880 debug(D_HEALTH, "Health alarm '%s.%s': warning expression gave value "
1881 CALCULATED_NUMBER_FORMAT
@@ -1806,15 +1897,15 @@ void *health_main(void *ptr) {
1897 debug(D_HEALTH, "Health alarm '%s.%s': critical expression failed with error: %s",
1898 rc->chart?rc->chart:"NOCHART", rc->name, buffer_tostring(rc->critical->error_msg));
1899
1809 - if (unlikely(!(rc->rrdcalc_options & RRDCALC_OPTION_CRIT_ERROR))) {
1810 - rc->rrdcalc_options |= RRDCALC_OPTION_CRIT_ERROR;
1900 + if (unlikely(!(rc->rrdcalc_flags & RRDCALC_FLAG_CRIT_ERROR))) {
1901 + rc->rrdcalc_flags |= RRDCALC_FLAG_CRIT_ERROR;
1902 error("Health alarm '%s.%s': critical expression failed with error: %s",
1903 rc->chart?rc->chart:"NOCHART", rc->name, buffer_tostring(rc->critical->error_msg));
1904 }
1905 }
1906 else {
1816 - if(unlikely(rc->rrdcalc_options & RRDCALC_OPTION_CRIT_ERROR))
1817 - rc->rrdcalc_options &= ~RRDCALC_OPTION_CRIT_ERROR;
1907 + if(unlikely(rc->rrdcalc_flags & RRDCALC_FLAG_CRIT_ERROR))
1908 + rc->rrdcalc_flags &= ~RRDCALC_FLAG_CRIT_ERROR;
1909
1910 debug(D_HEALTH, "Health alarm '%s.%s': critical expression gave value "
1911 CALCULATED_NUMBER_FORMAT
src/health.h
+9 -10
@@ -112,12 +112,12 @@ typedef struct rrddimvar {
112 #define RRDCALC_STATUS_WARNING 3
113 #define RRDCALC_STATUS_CRITICAL 4
114
115 -#define RRDCALC_OPTION_DB_ERROR 0x00000001
116 -#define RRDCALC_OPTION_DB_NAN 0x00000002
117 -#define RRDCALC_OPTION_DB_STALE 0x00000004
118 -#define RRDCALC_OPTION_CALC_ERROR 0x00000008
119 -#define RRDCALC_OPTION_WARN_ERROR 0x00000010
120 -#define RRDCALC_OPTION_CRIT_ERROR 0x00000020
115 +#define RRDCALC_FLAG_DB_ERROR 0x00000001
116 +#define RRDCALC_FLAG_DB_NAN 0x00000002
117 +#define RRDCALC_FLAG_DB_STALE 0x00000004
118 +#define RRDCALC_FLAG_CALC_ERROR 0x00000008
119 +#define RRDCALC_FLAG_WARN_ERROR 0x00000010
120 +#define RRDCALC_FLAG_CRIT_ERROR 0x00000020
121
122 typedef struct rrdcalc {
123 char *name;
@@ -145,12 +145,11 @@ typedef struct rrdcalc {
145 EVAL_EXPRESSION *warning;
146 EVAL_EXPRESSION *critical;
147
148 - uint32_t rrdcalc_options;
148 + uint32_t rrdcalc_flags;
149 int status;
150 - int warning_status;
151 - int critical_status;
150
153 - time_t db_timestamp;
151 + time_t db_after;
152 + time_t db_before;
153 time_t last_status_change;
154
155 calculated_number value;
src/rrd2json.c
+7 -3
@@ -1548,7 +1548,7 @@ RRDR *rrd2rrdr(RRDSET *st, long points, long long after, long long before, int g
1548 return r;
1549 }
1550
1551 -int rrd2value(RRDSET *st, BUFFER *wb, calculated_number *n, const char *dimensions, long points, long long after, long long before, int group_method, uint32_t options, time_t *latest_timestamp, int *value_is_null)
1551 +int rrd2value(RRDSET *st, BUFFER *wb, calculated_number *n, const char *dimensions, long points, long long after, long long before, int group_method, uint32_t options, time_t *db_after, time_t *db_before, int *value_is_null)
1552 {
1553 RRDR *r = rrd2rrdr(st, points, after, before, group_method, !(options & RRDR_OPTION_NOT_ALIGNED));
1554 if(!r) {
@@ -1558,7 +1558,11 @@ int rrd2value(RRDSET *st, BUFFER *wb, calculated_number *n, const char *dimensio
1558
1559 if(rrdr_rows(r) == 0) {
1560 rrdr_free(r);
1561 +
1562 + if(db_after) *db_after = 0;
1563 + if(db_before) *db_before = 0;
1564 if(value_is_null) *value_is_null = 1;
1565 +
1566 return 400;
1567 }
1568
@@ -1572,8 +1576,8 @@ int rrd2value(RRDSET *st, BUFFER *wb, calculated_number *n, const char *dimensio
1576 if(dimensions)
1577 rrdr_disable_not_selected_dimensions(r, dimensions);
1578
1575 - if(latest_timestamp)
1576 - *latest_timestamp = r->before;
1579 + if(db_after) *db_after = r->after;
1580 + if(db_before) *db_before = r->before;
1581
1582 long i = (options & RRDR_OPTION_REVERSED)?rrdr_rows(r) - 1:0;
1583 *n = rrdr2value(r, i, options, value_is_null);
src/rrd2json.h
+1 -1
@@ -63,6 +63,6 @@ extern void rrd_stats_all_json(BUFFER *wb);
63 extern time_t rrd_stats_json(int type, RRDSET *st, BUFFER *wb, long entries_to_show, long group, int group_method, time_t after, time_t before, int only_non_zero);
64
65 extern int rrd2format(RRDSET *st, BUFFER *out, BUFFER *dimensions, uint32_t format, long points, long long after, long long before, int group_method, uint32_t options, time_t *latest_timestamp);
66 -extern int rrd2value(RRDSET *st, BUFFER *wb, calculated_number *n, const char *dimensions, long points, long long after, long long before, int group_method, uint32_t options, time_t *latest_timestamp, int *value_is_null);
66 +extern int rrd2value(RRDSET *st, BUFFER *wb, calculated_number *n, const char *dimensions, long points, long long after, long long before, int group_method, uint32_t options, time_t *db_before, time_t *db_after, int *value_is_null);
67
68 #endif /* NETDATA_RRD2JSON_H */
src/web_client.c
+87 -1
@@ -459,6 +459,70 @@ void web_client_enable_deflate(struct web_client *w, int gzip) {
459 }
460 #endif // NETDATA_WITH_ZLIB
461
462 +void buffer_data_options2string(BUFFER *wb, uint32_t options) {
463 + int count = 0;
464 +
465 + if(options & RRDR_OPTION_NONZERO) {
466 + if(count++) buffer_strcat(wb, " ");
467 + buffer_strcat(wb, "nonzero");
468 + }
469 +
470 + if(options & RRDR_OPTION_REVERSED) {
471 + if(count++) buffer_strcat(wb, " ");
472 + buffer_strcat(wb, "flip");
473 + }
474 +
475 + if(options & RRDR_OPTION_JSON_WRAP) {
476 + if(count++) buffer_strcat(wb, " ");
477 + buffer_strcat(wb, "jsonwrap");
478 + }
479 +
480 + if(options & RRDR_OPTION_MIN2MAX) {
481 + if(count++) buffer_strcat(wb, " ");
482 + buffer_strcat(wb, "min2max");
483 + }
484 +
485 + if(options & RRDR_OPTION_MILLISECONDS) {
486 + if(count++) buffer_strcat(wb, " ");
487 + buffer_strcat(wb, "ms");
488 + }
489 +
490 + if(options & RRDR_OPTION_ABSOLUTE) {
491 + if(count++) buffer_strcat(wb, " ");
492 + buffer_strcat(wb, "abs");
493 + }
494 +
495 + if(options & RRDR_OPTION_SECONDS) {
496 + if(count++) buffer_strcat(wb, " ");
497 + buffer_strcat(wb, "seconds");
498 + }
499 +
500 + if(options & RRDR_OPTION_NULL2ZERO) {
501 + if(count++) buffer_strcat(wb, " ");
502 + buffer_strcat(wb, "null2zero");
503 + }
504 +
505 + if(options & RRDR_OPTION_OBJECTSROWS) {
506 + if(count++) buffer_strcat(wb, " ");
507 + buffer_strcat(wb, "objectrows");
508 + }
509 +
510 + if(options & RRDR_OPTION_GOOGLE_JSON) {
511 + if(count++) buffer_strcat(wb, " ");
512 + buffer_strcat(wb, "google_json");
513 + }
514 +
515 + if(options & RRDR_OPTION_PERCENTAGE) {
516 + if(count++) buffer_strcat(wb, " ");
517 + buffer_strcat(wb, "percentage");
518 + }
519 +
520 + if(options & RRDR_OPTION_NOT_ALIGNED) {
521 + if(count++) buffer_strcat(wb, " ");
522 + buffer_strcat(wb, "unaligned");
523 + }
524 +}
525 +
526 uint32_t web_client_api_request_v1_data_options(char *o)
527 {
528 uint32_t ret = 0x00000000;
@@ -551,6 +615,28 @@ uint32_t web_client_api_request_v1_data_google_format(char *name)
615 return DATASOURCE_JSON;
616 }
617
618 +const char *group_method2string(int group) {
619 + switch(group) {
620 + case GROUP_AVERAGE:
621 + return "average";
622 +
623 + case GROUP_MIN:
624 + return "min";
625 +
626 + case GROUP_MAX:
627 + return "max";
628 +
629 + case GROUP_SUM:
630 + return "sum";
631 +
632 + case GROUP_INCREMENTAL_SUM:
633 + return "incremental-sum";
634 +
635 + default:
636 + return "unknown-group-method";
637 + }
638 +}
639 +
640 int web_client_api_request_v1_data_group(char *name, int def)
641 {
642 if(!strcmp(name, "average"))
@@ -818,7 +904,7 @@ int web_client_api_v1_badge(struct web_client *w, char *url) {
904 // if the collected value is too old, don't calculate its value
905 if (rrdset_last_entry_t(st) >= (time(NULL) - (st->update_every * st->gap_when_lost_iterations_above)))
906 ret = rrd2value(st, w->response.data, &n, (dimensions) ? buffer_tostring(dimensions) : NULL, points, after,
821 - before, group, options, &latest_timestamp, &value_is_null);
907 + before, group, options, NULL, &latest_timestamp, &value_is_null);
908
909 // if the value cannot be calculated, show empty badge
910 if (ret != 200) {
src/web_client.h
+3
@@ -104,4 +104,7 @@ extern void web_client_reset(struct web_client *w);
104 extern void *web_client_main(void *ptr);
105
106 extern int web_client_api_request_v1_data_group(char *name, int def);
107 +extern const char *group_method2string(int group);
108 +
109 +extern void buffer_data_options2string(BUFFER *wb, uint32_t options);
110 #endif