]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Allow JSONTIME to be added to graphv output
authornetniV <netniv@hotmail.com>
Sun, 5 Jul 2020 11:59:21 +0000 (11:59 +0000)
committernetniV <netniv@hotmail.com>
Sun, 5 Jul 2020 11:59:21 +0000 (11:59 +0000)
src/rrd_graph.c
src/rrd_graph.h

index bf7742923624279370b668f659c9b9bb49722ff7..4c574656a7469c5aeea18acefa033d9258e66a82 100644 (file)
@@ -4755,6 +4755,16 @@ rrd_info_t *rrd_graph_v(
         img.u_blo.ptr = im.rendered_image;
         grinfo_push(&im, sprintf_alloc("image"), RD_I_BLO, img);
     }
+    if (im.extra_flags & FORCE_JSONTIME) {
+        im.imgformat = IF_JSONTIME;
+        if (rrd_graph_xport(&im)) {
+               rrd_infoval_t img;
+
+               img.u_blo.size = im.rendered_image_size;
+               img.u_blo.ptr = im.rendered_image;
+               grinfo_push(&im, sprintf_alloc("datapoints"), RD_I_BLO, img);
+        }
+    }
     grinfo = im.grinfo;
     im_free(&im);
     return grinfo;
@@ -4948,6 +4958,7 @@ void rrd_graph_options(
     /* defines for long options without a short equivalent. should be bytes,
        and may not collide with (the ASCII value of) short options */
 #define LONGOPT_UNITS_SI 255
+#define LONGOPT_ADD_JSONTIME 254
 
 /* *INDENT-OFF* */
     struct optparse_long longopts[] = {
@@ -4994,6 +5005,7 @@ void rrd_graph_options(
         {"lazy",               'z', OPTPARSE_NONE},
         {"use-nan-for-all-missing-data", 'Z', OPTPARSE_NONE},
         {"units",              LONGOPT_UNITS_SI, OPTPARSE_REQUIRED},
+        {"add-jsontime",       LONGOPT_ADD_JSONTIME, OPTPARSE_NONE},
         {"alt-y-mrtg",         1000, OPTPARSE_NONE},    /* this has no effect it is just here to save old apps from crashing when they use it */
         {"disable-rrdtool-tag",1001, OPTPARSE_NONE},
         {"right-axis",         1002, OPTPARSE_REQUIRED},
@@ -5094,6 +5106,13 @@ void rrd_graph_options(
                 return;
             }
             break;
+        case LONGOPT_ADD_JSONTIME:
+            if (im->extra_flags & FORCE_JSONTIME) {
+                rrd_set_error("--units can only be used once!");
+                return;
+            }
+            im->extra_flags |= FORCE_JSONTIME;
+            break;
         case 'X':
             im->unitsexponent = atoi(poptions->optarg);
             break;
index a2f4faa4bf7f0629bf8b9b1b2564ed1821e620f8..958d087481110d67eec18c433f237664a0853287 100644 (file)
@@ -45,6 +45,7 @@
 #define FULL_SIZE_MODE     0x200    /* -width and -height indicate the total size of the image */
 #define NO_RRDTOOL_TAG 0x400  /* disable the rrdtool tag */
 #define ALLOW_MISSING_DS 0x800  /* missing DS is not fatal */
+#define FORCE_JSONTIME 0x1000  /* add jsontime to graphv output */
 
 #define gdes_fetch_key(x)  sprintf_alloc("%s:%s:%d:%d:%d:%d:%d:%d",x.rrd,x.daemon,x.cf,x.cf_reduce,x.start_orig,x.end_orig,x.step_orig,x.step)