diff options
author | Valentin Rakush <52716954+alpes214@users.noreply.github.com> | 2019-08-20 12:11:43 +0300 |
---|---|---|
committer | Chris Akritidis <43294513+cakrit@users.noreply.github.com> | 2019-08-20 11:11:43 +0200 |
commit | 92642269f19f585b04d439a3bbe4e60d33918974 (patch) | |
tree | a507dfe903ebacafb4e485a2ee6edcb54867448a /database/rrdvar.c | |
parent | d52c20ec4c632459d90797725214be8ffeb66251 (diff) |
Add alarm variables to the response of chart and data (#6615)
##### Summary
Implements feature #6054
Now requests like
http://localhost:19999/api/v1/chart?chart=example.random
http://localhost:19999/api/v1/data?chart=example.random&options=jsonwrap&options=showcustomvars
- return chart variables in their responses. Chart variables include only those with options set to RRDVAR_OPTION_CUSTOM_CHART_VAR
- for /api/v1/data requests chart variables are returned when parameter options=jsonwrap and options=showcustomvars
##### Component Name
[/database](https://github.com/netdata/netdata/tree/master/database/)
[/web/api/formatters](https://github.com/netdata/netdata/tree/master/web/api/formatters)
Diffstat (limited to 'database/rrdvar.c')
-rw-r--r-- | database/rrdvar.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/database/rrdvar.c b/database/rrdvar.c index 95ab6859ea..0858d0bdcd 100644 --- a/database/rrdvar.c +++ b/database/rrdvar.c @@ -248,6 +248,7 @@ int health_variable_lookup(const char *variable, uint32_t hash, RRDCALC *rc, cal struct variable2json_helper { BUFFER *buf; size_t counter; + RRDVAR_OPTIONS options; }; static int single_variable2json(void *entry, void *data) { @@ -255,22 +256,37 @@ static int single_variable2json(void *entry, void *data) { RRDVAR *rv = (RRDVAR *)entry; calculated_number value = rrdvar2number(rv); - if(unlikely(isnan(value) || isinf(value))) - buffer_sprintf(helper->buf, "%s\n\t\t\"%s\": null", helper->counter?",":"", rv->name); - else - buffer_sprintf(helper->buf, "%s\n\t\t\"%s\": %0.5" LONG_DOUBLE_MODIFIER, helper->counter?",":"", rv->name, (LONG_DOUBLE)value); + if (helper->options == RRDVAR_OPTION_DEFAULT || rv->options & helper->options) { + if(unlikely(isnan(value) || isinf(value))) + buffer_sprintf(helper->buf, "%s\n\t\t\"%s\": null", helper->counter?",":"", rv->name); + else + buffer_sprintf(helper->buf, "%s\n\t\t\"%s\": %0.5" LONG_DOUBLE_MODIFIER, helper->counter?",":"", rv->name, (LONG_DOUBLE)value); - helper->counter++; + helper->counter++; + } return 0; } +void health_api_v1_chart_custom_variables2json(RRDSET *st, BUFFER *buf) { + struct variable2json_helper helper = { + .buf = buf, + .counter = 0, + .options = RRDVAR_OPTION_CUSTOM_CHART_VAR + }; + + buffer_sprintf(buf, "{"); + avl_traverse_lock(&st->rrdvar_root_index, single_variable2json, (void *)&helper); + buffer_strcat(buf, "\n\t\t\t}"); +} + void health_api_v1_chart_variables2json(RRDSET *st, BUFFER *buf) { RRDHOST *host = st->rrdhost; struct variable2json_helper helper = { .buf = buf, - .counter = 0 + .counter = 0, + .options = RRDVAR_OPTION_DEFAULT }; buffer_sprintf(buf, "{\n\t\"chart\": \"%s\",\n\t\"chart_name\": \"%s\",\n\t\"chart_context\": \"%s\",\n\t\"chart_variables\": {", st->id, st->name, st->context); |