X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_tool.c;h=24abcdce9c36a4ad445e4cc9ddd3bd8509fbdf45;hp=4dd4cae1f1c6524cbe6b56a8cf74e7a1681ed96b;hb=d85e6bdfe82fdc4d16898df43f8a5371503816ae;hpb=598d28c0200dddef0e3a8309e95958a5980bd2ea diff --git a/src/rrd_tool.c b/src/rrd_tool.c index 4dd4cae..24abcdc 100644 --- a/src/rrd_tool.c +++ b/src/rrd_tool.c @@ -704,146 +704,13 @@ int HandleInputLine( } } else if (strcmp("xport", argv[1]) == 0) { #ifdef HAVE_RRD_GRAPH - int xxsize; - unsigned long int j = 0; - time_t start, end, ti; - unsigned long step, col_cnt, row_cnt; - rrd_value_t *data, *ptr; - char **legend_v; - int enumds = 0; - int json = 0; - int i; - size_t vtag_s = strlen(COL_DATA_TAG) + 10; - char *vtag = malloc(vtag_s); - - for (i = 2; i < argc; i++) { - if (strcmp("--enumds", argv[i]) == 0) - enumds = 1; - if (strcmp("--json", argv[i]) == 0) - json = 1; - } - - if (rrd_xport - (argc - 1, &argv[1], &xxsize, &start, &end, &step, &col_cnt, - &legend_v, &data) == 0) { - char *old_locale = setlocale(LC_NUMERIC,NULL); - setlocale(LC_NUMERIC, "C"); - row_cnt = (end - start) / step; - ptr = data; - if (json == 0){ - printf("\n\n", - XML_ENCODING); - printf("<%s>\n", ROOT_TAG); - printf(" <%s>\n", META_TAG); - } - else { - printf("{ about: 'RRDtool xport JSON output',\n meta: {\n"); - } - - -#define pXJV(indent,fmt,tag,value) \ - if (json) { \ - printf(indent "\"%s\": " fmt ",\n",tag,value); \ - } else { \ - printf(indent "<%s>" fmt "\n",tag,value,tag); \ - } - - pXJV(" ","%lld",META_START_TAG,(long long int) start + step); - pXJV(" ","%lu", META_STEP_TAG, step); - pXJV(" ","%lld",META_END_TAG,(long long int) start + step); - if (! json){ - pXJV(" ","%lu", META_ROWS_TAG, row_cnt); - pXJV(" ","%lu", META_COLS_TAG, col_cnt); - } - - if (json){ - printf(" \"%s\": [\n", LEGEND_TAG); - } - else { - printf(" <%s>\n", LEGEND_TAG); - } - for (j = 0; j < col_cnt; j++) { - char *entry = NULL; - entry = legend_v[j]; - if (json){ - printf(" '%s'", entry); - if (j < col_cnt -1){ - printf(","); - } - printf("\n"); - } - else { - printf(" <%s>%s\n", LEGEND_ENTRY_TAG, entry, - LEGEND_ENTRY_TAG); - } - free(entry); - } - free(legend_v); - if (json){ - printf(" ]\n },\n"); - } - else { - printf(" \n", LEGEND_TAG); - printf(" \n", META_TAG); - } - - if (json){ - printf(" \"%s\": [\n",DATA_TAG); - } else { - printf(" <%s>\n", DATA_TAG); - } - for (ti = start + step; ti <= end; ti += step) { - if (json){ - printf(" [ "); - } - else { - printf(" <%s>", DATA_ROW_TAG); - printf("<%s>%lld", COL_TIME_TAG, (long long int)ti, COL_TIME_TAG); - } - for (j = 0; j < col_cnt; j++) { - rrd_value_t newval = DNAN; - newval = *ptr; - if (json){ - if (isnan(newval)){ - printf("null"); - } else { - printf("%0.10e",newval); - } - if (j < col_cnt -1){ - printf(", "); - } - } - else { - if (enumds == 1) - snprintf(vtag, vtag_s, "%s%lu", COL_DATA_TAG, j); - else - snprintf(vtag, vtag_s, "%s", COL_DATA_TAG); - if (isnan(newval)) { - printf("<%s>NaN", vtag, vtag); - } else { - printf("<%s>%0.10e", vtag, newval, vtag); - }; - } - ptr++; - } - if (json){ - printf(ti < end ? " ],\n" : " ]\n"); - } - else { - printf("\n", DATA_ROW_TAG); - } - } - free(data); - if (json){ - printf(" ]\n}\n"); - } - else { - printf(" \n", DATA_TAG); - printf("\n", ROOT_TAG); - } - setlocale(LC_NUMERIC, old_locale); - } - free(vtag); + time_t start, end; + unsigned long step, col_cnt; + rrd_value_t *data; + char **legend_v; + rrd_xport + (argc - 1, &argv[1], NULL, &start, &end, &step, &col_cnt, + &legend_v, &data); #else rrd_set_error("the instance of rrdtool has been compiled without graphics"); #endif