@cryptotaxi247 / netdata-1 / commits / 8f7512663

proper defaults for badges

Costa Tsaousis (ktsaou) committed Jun 5, 2016 at 10:12 UTC 8f75126632ddb4de6f59f1172c1bc4cf6cff6731
1 file changed +17 -6
src/web_client.c
+17 -6
@@ -710,7 +710,6 @@ int web_client_api_v1_badge(struct web_client *w, char *url) {
710 , *value_color = NULL;
711
712 int group = GROUP_MAX;
713 - uint32_t format = DATASOURCE_JSON;
713 uint32_t options = 0x00000000;
714
715 while(url) {
@@ -767,8 +766,8 @@ int web_client_api_v1_badge(struct web_client *w, char *url) {
766 long long multiply = (multiply_str && *multiply_str)?atol(multiply_str):1;
767 long long divide = (divide_str && *divide_str )?atol(divide_str):1;
768 long long before = (before_str && *before_str )?atol(before_str):0;
770 - long long after = (after_str && *after_str )?atol(after_str):0;
771 - int points = (points_str && *points_str )?atoi(points_str):0;
769 + long long after = (after_str && *after_str )?atol(after_str):-st->update_every;
770 + int points = (points_str && *points_str )?atoi(points_str):1;
771
772 if(!label) {
773 if(dimensions) {
@@ -786,7 +785,7 @@ int web_client_api_v1_badge(struct web_client *w, char *url) {
785 units = st->units;
786 }
787
789 - debug(D_WEB_CLIENT, "%llu: API command 'badge.svg' for chart '%s', dimensions '%s', after '%lld', before '%lld', points '%d', group '%u', format '%u', options '0x%08x'"
788 + debug(D_WEB_CLIENT, "%llu: API command 'badge.svg' for chart '%s', dimensions '%s', after '%lld', before '%lld', points '%d', group '%u', options '0x%08x'"
789 , w->id
790 , chart
791 , (dimensions)?buffer_tostring(dimensions):""
@@ -794,14 +793,26 @@ int web_client_api_v1_badge(struct web_client *w, char *url) {
793 , before
794 , points
795 , group
797 - , format
796 , options
797 );
798
799 time_t latest_timestamp = 0;
800 int value_is_null = 1;
801 calculated_number n = 0;
804 - ret = rrd2value(st, w->response.data, &n, dimensions, points, after, before, group, options, &latest_timestamp, &value_is_null);
802 + ret = 500;
803 +
804 + // if the collected value is too old, don't calculate its value
805 + if(st->last_updated.tv_sec >= (time(NULL) - (st->update_every * st->gap_when_lost_iterations_above)))
806 + ret = rrd2value(st, w->response.data, &n, dimensions, points, after, before, group, options, &latest_timestamp, &value_is_null);
807 +
808 + // if the value cannot be calculated, show empty badge
809 + if(ret != 200) {
810 + value_is_null = 1;
811 + n = 0;
812 + ret = 200;
813 + }
814 +
815 + // render the badge
816 buffer_svg(w->response.data, label, n * multiply / divide, units, label_color, value_color, value_is_null);
817 return ret;
818