]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
graph: allow RRD files to be missing
authorVincent Bernat <vincent.bernat@dailymotion.com>
Fri, 5 Apr 2013 10:43:22 +0000 (12:43 +0200)
committerVincent Bernat <bernat@luffy.cx>
Thu, 20 Jun 2013 18:54:56 +0000 (20:54 +0200)
An option (-Z/--missing-ds) is added to allow RRD files to be
missing. In this case, the unknown value is assumed.

doc/rrdgraph.pod
src/rrd_graph.c
src/rrd_graph.h
src/rrd_tool.c

index e8e88450752f90a903e4826832b1ac58553dc3ab..384f5fbb9c0f934100d77d1491c3680a4ea9d951 100644 (file)
@@ -488,6 +488,12 @@ measurement, 1 kb/s is 1000 b/s.
 Adds the given string as a watermark, horizontally centered, at the bottom 
 of the graph.
 
+[B<-Z>|B<--missing-ds>]
+
+If one DS is missing, either because the RRD is not available or
+because it does not contain the requested DS name, just assume that we
+got empty values instead of raising a fatal error.
+
 =head2 Data and variables
 
 B<DEF:>I<vname>B<=>I<rrdfile>B<:>I<ds-name>B<:>I<CF>[B<:step=>I<step>][B<:start=>I<time>][B<:end=>I<time>]
index e714e4f483a651883f23a1311077697b1bbf8330..7d4a020649b7aea6819a9496b0082846e78358f9 100644 (file)
@@ -897,8 +897,13 @@ int data_fetch(
                         &im->gdes[i].ds_cnt,
                         &im->gdes[i].ds_namv,
                         &im->gdes[i].data);
-                if (status != 0)
-                    return (status);
+                if (status != 0) {
+                    if (im->extra_flags & ALLOW_MISSING_DS) {
+                        rrd_clear_error();
+                        im->gdes[i].ds_cnt = im->gdes[i].start = im->gdes[i].end = 0;
+                        ft_step = 1;
+                    } else return (status);
+                }
             }
             else
             {
@@ -910,8 +915,13 @@ int data_fetch(
                                 &im->gdes[i].ds_cnt,
                                 &im->gdes[i].ds_namv,
                                 &im->gdes[i].data)) == -1) {
-                    return -1;                      
-                }               
+                    if (im->extra_flags & ALLOW_MISSING_DS) {
+                        /* Unable to fetch data, assume fake data */
+                        rrd_clear_error();
+                        im->gdes[i].ds_cnt = im->gdes[i].start = im->gdes[i].end = 0;
+                        ft_step = 1;
+                    } else return -1;
+                }
             }
             im->gdes[i].data_first = 1;
 
@@ -937,7 +947,8 @@ int data_fetch(
                 im->gdes[i].ds = ii;
             }
         }
-        if (im->gdes[i].ds == -1) {
+        if ((im->gdes[i].ds == -1) &&
+            !(im->extra_flags & ALLOW_MISSING_DS)) {
             rrd_set_error("No DS called '%s' in '%s'",
                           im->gdes[i].ds_nam, im->gdes[i].rrd);
             return -1;
@@ -4376,6 +4387,7 @@ void rrd_graph_options(
         { "alt-y-grid",         no_argument,       0, 'Y'},
         { "y-grid",             required_argument, 0, 'y'},
         { "lazy",               no_argument,       0, 'z'},
+        { "missing-ds",         no_argument,       0, 'Z'},
         { "units",              required_argument, 0, LONGOPT_UNITS_SI},
         { "alt-y-mrtg",         no_argument,       0, 1000},    /* this has no effect it is just here to save old apps from crashing when they use it */
         { "disable-rrdtool-tag",no_argument,       0, 1001},
@@ -4403,7 +4415,7 @@ void rrd_graph_options(
         int       col_start, col_end;
 
         opt = getopt_long(argc, argv,
-                          "Aa:B:b:c:Dd:Ee:Ff:G:gh:IiJjL:l:Mm:Nn:oPR:rS:s:T:t:u:v:W:w:X:x:Yy:z",
+                          "Aa:B:b:c:Dd:Ee:Ff:G:gh:IiJjL:l:Mm:Nn:oPR:rS:s:T:t:u:v:W:w:X:x:Yy:Zz",
                           long_options, &option_index);
         if (opt == EOF)
             break;
@@ -4429,6 +4441,9 @@ void rrd_graph_options(
         case 'g':
             im->extra_flags |= NOLEGEND;
             break;
+        case 'Z':
+            im->extra_flags |= ALLOW_MISSING_DS;
+            break;
         case 1005:
             if (strcmp(optarg, "north") == 0) {
                 im->legendposition = NORTH;
index 397c5b2c7e3a908db27fbd1ef4cfbc6c0f870b14..fc9a5ceb5656411790da4355dc4592f51096c35e 100644 (file)
@@ -42,6 +42,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 gdes_fetch_key(x)  sprintf_alloc("%s:%d:%d:%d:%d",x.rrd,x.cf,x.cf_reduce,x.start_orig,x.end_orig,x.step_orig)
 
index ea585abd5dbe4d0450e76b0a909489c346c4c9b6..4b46fadfde8ce14b3651200c43c3c4f4bbbc6e66 100644 (file)
@@ -166,6 +166,7 @@ void PrintUsage(
            "\t\t[--border width\n"
            "\t\t[-t|--title string]\n"
            "\t\t[-W|--watermark string]\n"
+           "\t\t[-Z|--missing-ds]\n"
            "\t\t[DEF:vname=rrd:ds-name:CF]\n");
     const char *help_graph3 =
         N_("\t\t[CDEF:vname=rpn-expression]\n"