summaryrefslogtreecommitdiffstats
path: root/database/rrdfunctions.c
diff options
context:
space:
mode:
Diffstat (limited to 'database/rrdfunctions.c')
-rw-r--r--database/rrdfunctions.c55
1 files changed, 28 insertions, 27 deletions
diff --git a/database/rrdfunctions.c b/database/rrdfunctions.c
index 6c5baf34..2659130f 100644
--- a/database/rrdfunctions.c
+++ b/database/rrdfunctions.c
@@ -991,7 +991,7 @@ int rrd_function_run(RRDHOST *host, BUFFER *result_wb, int timeout, const char *
// the caller has to wait
code = rdcf->execute_cb(result_wb, timeout, sanitized_cmd, rdcf->execute_cb_data,
- NULL, NULL, // no callback needed, it is synchronous
+ result_cb, result_cb_data,
is_cancelled_cb, is_cancelled_cb_data, // it is ok to pass these, we block the caller
NULL, NULL); // no need to pass, we will wait
@@ -1007,11 +1007,11 @@ int rrd_function_run(RRDHOST *host, BUFFER *result_wb, int timeout, const char *
// the function can only be executed in async mode
// put the function into the inflight requests
- char uuid_str[UUID_STR_LEN];
+ char uuid_str[UUID_COMPACT_STR_LEN];
if(!transaction) {
uuid_t uuid;
uuid_generate_random(uuid);
- uuid_unparse_lower(uuid, uuid_str);
+ uuid_unparse_lower_compact(uuid, uuid_str);
transaction = uuid_str;
}
@@ -1097,35 +1097,36 @@ cleanup:
// ----------------------------------------------------------------------------
-static void functions2json(DICTIONARY *functions, BUFFER *wb, const char *ident, const char *kq, const char *sq) {
+static void functions2json(DICTIONARY *functions, BUFFER *wb)
+{
struct rrd_host_function *t;
- dfe_start_read(functions, t) {
- if(!rrd_collector_running(t->collector)) continue;
-
- if(t_dfe.counter)
- buffer_strcat(wb, ",\n");
+ dfe_start_read(functions, t)
+ {
+ if (!rrd_collector_running(t->collector))
+ continue;
- buffer_sprintf(wb, "%s%s%s%s: {", ident, kq, t_dfe.name, kq);
- buffer_sprintf(wb, "\n\t%s%shelp%s: %s%s%s", ident, kq, kq, sq, string2str(t->help), sq);
- buffer_sprintf(wb, ",\n\t%s%stimeout%s: %d", ident, kq, kq, t->timeout);
- buffer_sprintf(wb, ",\n\t%s%soptions%s: \"%s%s\"", ident, kq, kq
- , (t->options & RRD_FUNCTION_LOCAL)?"LOCAL ":""
- , (t->options & RRD_FUNCTION_GLOBAL)?"GLOBAL ":""
- );
- buffer_sprintf(wb, "\n%s}", ident);
+ buffer_json_member_add_object(wb, t_dfe.name);
+ buffer_json_member_add_string_or_empty(wb, "help", string2str(t->help));
+ buffer_json_member_add_int64(wb, "timeout", (int64_t)t->timeout);
+
+ char options[65];
+ snprintfz(
+ options,
+ 64,
+ "%s%s",
+ (t->options & RRD_FUNCTION_LOCAL) ? "LOCAL " : "",
+ (t->options & RRD_FUNCTION_GLOBAL) ? "GLOBAL" : "");
+
+ buffer_json_member_add_string_or_empty(wb, "options", options);
+ buffer_json_object_close(wb);
}
dfe_done(t);
- buffer_strcat(wb, "\n");
}
-void chart_functions2json(RRDSET *st, BUFFER *wb, int tabs, const char *kq, const char *sq) {
+void chart_functions2json(RRDSET *st, BUFFER *wb) {
if(!st || !st->functions_view) return;
- char ident[tabs + 1];
- ident[tabs] = '\0';
- while(tabs) ident[--tabs] = '\t';
-
- functions2json(st->functions_view, wb, ident, kq, sq);
+ functions2json(st->functions_view, wb);
}
void host_functions2json(RRDHOST *host, BUFFER *wb) {
@@ -1372,19 +1373,19 @@ int rrdhost_function_streaming(BUFFER *wb, int timeout __maybe_unused, const cha
RRDF_FIELD_TYPE_TIMESTAMP, RRDF_FIELD_VISUAL_VALUE, RRDF_FIELD_TRANSFORM_DATETIME_MS,
0, NULL, NAN, RRDF_FIELD_SORT_ASCENDING, NULL,
RRDF_FIELD_SUMMARY_MIN, RRDF_FIELD_FILTER_RANGE,
- RRDF_FIELD_OPTS_VISIBLE, NULL);
+ RRDF_FIELD_OPTS_NONE, NULL);
buffer_rrdf_table_add_field(wb, field_id++, "dbTo", "DB Data Retention To",
RRDF_FIELD_TYPE_TIMESTAMP, RRDF_FIELD_VISUAL_VALUE, RRDF_FIELD_TRANSFORM_DATETIME_MS,
0, NULL, NAN, RRDF_FIELD_SORT_ASCENDING, NULL,
RRDF_FIELD_SUMMARY_MAX, RRDF_FIELD_FILTER_RANGE,
- RRDF_FIELD_OPTS_VISIBLE, NULL);
+ RRDF_FIELD_OPTS_NONE, NULL);
buffer_rrdf_table_add_field(wb, field_id++, "dbDuration", "DB Data Retention Duration",
RRDF_FIELD_TYPE_DURATION, RRDF_FIELD_VISUAL_VALUE, RRDF_FIELD_TRANSFORM_DURATION_S,
0, NULL, NAN, RRDF_FIELD_SORT_ASCENDING, NULL,
RRDF_FIELD_SUMMARY_MAX, RRDF_FIELD_FILTER_RANGE,
- RRDF_FIELD_OPTS_NONE, NULL);
+ RRDF_FIELD_OPTS_VISIBLE, NULL);
buffer_rrdf_table_add_field(wb, field_id++, "dbMetrics", "Time-series Metrics in the DB",
RRDF_FIELD_TYPE_INTEGER, RRDF_FIELD_VISUAL_VALUE, RRDF_FIELD_TRANSFORM_NUMBER,