added badge option "refresh=auto" or "refresh=SECONDS" to generate HTTP header requesting from the web client auto-refresh
Costa Tsaousis (ktsaou) committed
Jun 5, 2016 at 20:43 UTC
cfe4316c83aaa3e126b1eea44c832d6dbe853b93
2 files changed
+24
-4
src/web_buffer_svg.c
+1
-1
@@ -509,7 +509,7 @@ void buffer_svg(BUFFER *wb, const char *label, calculated_number value, const ch
509
int label_width, value_width, total_width;
510
511
if(!label_color || !*label_color) label_color = "#555";
512
- if(!value_color || !*value_color) value_color = "#4c1";
512
+ if(!value_color || !*value_color) value_color = (value_is_null)?"#999":"#4c1";
513
514
units = fix_units(units);
515
calc_colorz(value_color, value_color_buffer, 256, value, value_is_null);
src/web_client.c
+23
-3
@@ -715,7 +715,8 @@ int web_client_api_v1_badge(struct web_client *w, char *url) {
715
, *label = NULL
716
, *units = NULL
717
, *label_color = NULL
718
- , *value_color = NULL;
718
+ , *value_color = NULL
719
+ , *refresh_str = NULL;
720
721
int group = GROUP_AVERAGE;
722
uint32_t options = 0x00000000;
@@ -756,6 +757,7 @@ int web_client_api_v1_badge(struct web_client *w, char *url) {
757
else if(!strcmp(name, "value_color")) value_color = value;
758
else if(!strcmp(name, "multiply")) multiply_str = value;
759
else if(!strcmp(name, "divide")) divide_str = value;
760
+ else if(!strcmp(name, "refresh")) refresh_str = value;
761
}
762
763
if(!chart || !*chart) {
@@ -766,8 +768,8 @@ int web_client_api_v1_badge(struct web_client *w, char *url) {
768
RRDSET *st = rrdset_find(chart);
769
if(!st) st = rrdset_find_byname(chart);
770
if(!st) {
769
- buffer_sprintf(w->response.data, "Chart '%s' is not found.", chart);
770
- ret = 404;
771
+ buffer_svg(w->response.data, "chart not found", 0, "", NULL, NULL, 1);
772
+ ret = 200;
773
goto cleanup;
774
}
775
@@ -777,6 +779,22 @@ int web_client_api_v1_badge(struct web_client *w, char *url) {
779
long long after = (after_str && *after_str )?atol(after_str):-st->update_every;
780
int points = (points_str && *points_str )?atoi(points_str):1;
781
782
+ int refresh = 0;
783
+ if(refresh_str && *refresh_str) {
784
+ if(!strcmp(refresh_str, "auto")) {
785
+ if(options & RRDR_OPTION_NOT_ALIGNED)
786
+ refresh = st->update_every;
787
+ else {
788
+ refresh = (before - after);
789
+ if(refresh < 0) refresh = -refresh;
790
+ }
791
+ }
792
+ else {
793
+ refresh = atoi(refresh_str);
794
+ if(refresh < 0) refresh = -refresh;
795
+ }
796
+ }
797
+
798
if(!label) {
799
if(dimensions) {
800
const char *dim = buffer_tostring(dimensions);
@@ -819,6 +837,8 @@ int web_client_api_v1_badge(struct web_client *w, char *url) {
837
n = 0;
838
ret = 200;
839
}
840
+ else if(refresh > 0)
841
+ buffer_sprintf(w->response.header, "Refresh: %d\r\n", refresh);
842
843
// render the badge
844
buffer_svg(w->response.data, label, n * multiply / divide, units, label_color, value_color, value_is_null);