New functions lastupdate to efficiently get the last values fed into the rrd ......
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Wed, 17 Jan 2007 21:31:23 +0000 (21:31 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Wed, 17 Jan 2007 21:31:23 +0000 (21:31 +0000)
get stored even for ABSOLUTE and GAUGE data sources ... -- andy.riebs hp.com

git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@951 a5681a0c-68f1-0310-ab6d-d61299d08faa

acinclude.m4
bindings/tcl/tclrrd.c
doc/Makefile.am
src/Makefile.am
src/rrd_tool.c
src/rrd_tool.h
src/rrd_update.c

index d0f8c0e..b71fe8e 100644 (file)
@@ -507,3 +507,42 @@ esac
 ])
 
 
+dnl ---------------------------------------------------------------------------
+dnl CF_DISABLE_ECHO version: 10 updated: 2003/04/17 22:27:11
+dnl ---------------
+dnl stolen from xterm aclocal.m4
+dnl
+dnl You can always use "make -n" to see the actual options, but it's hard to
+dnl pick out/analyze warning messages when the compile-line is long.
+dnl
+dnl Sets:
+dnl     ECHO_LT - symbol to control if libtool is verbose
+dnl     ECHO_LD - symbol to prefix "cc -o" lines
+dnl     RULE_CC - symbol to put before implicit "cc -c" lines (e.g., .c.o)
+dnl     SHOW_CC - symbol to put before explicit "cc -c" lines
+dnl     ECHO_CC - symbol to put before any "cc" line
+dnl
+AC_DEFUN([CF_DISABLE_ECHO],[
+AC_MSG_CHECKING(if you want to see long compiling messages)
+CF_ARG_DISABLE(echo,
+        [  --disable-echo          display "compiling" commands],
+        [
+    ECHO_LT='--silent'
+    ECHO_LD='@echo linking [$]@;'
+    RULE_CC='   @echo compiling [$]<'
+    SHOW_CC='   @echo compiling [$]@'
+    ECHO_CC='@'
+],[
+    ECHO_LT=''
+    ECHO_LD=''
+    RULE_CC='# compiling'
+    SHOW_CC='# compiling'
+    ECHO_CC=''
+])
+AC_MSG_RESULT($enableval)
+AC_SUBST(ECHO_LT)
+AC_SUBST(ECHO_LD)
+AC_SUBST(RULE_CC)
+AC_SUBST(SHOW_CC)
+AC_SUBST(ECHO_CC)
+])dnl
index e9cff80..33ceb15 100644 (file)
@@ -308,7 +308,42 @@ Rrd_Update(ClientData clientData, Tcl_Interp *interp, int argc, CONST84 char *ar
     return TCL_OK;
 }
 
-
+static int
+Rrd_Lastupdate(ClientData clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[])
+  {
+   time_t last_update;
+   char **argv2;
+   char **ds_namv;
+   char **last_ds;
+   char s[30];
+   Tcl_Obj *listPtr;
+   unsigned long ds_cnt, i;
+
+   argv2 = getopt_init(argc, argv);
+   if (rrd_lastupdate(argc-1, argv2, &last_update,
+       &ds_cnt, &ds_namv, &last_ds) == 0) {
+          listPtr = Tcl_GetObjResult(interp);
+           for (i=0; i<ds_cnt; i++) {
+              sprintf(s, " %28s", ds_namv[i]);
+              Tcl_ListObjAppendElement(interp, listPtr,
+                      Tcl_NewStringObj(s, -1));
+           sprintf(s, "\n\n%10lu:", last_update);
+              Tcl_ListObjAppendElement(interp, listPtr,
+                      Tcl_NewStringObj(s, -1));
+           for (i=0; i<ds_cnt; i++) {
+               sprintf(s, " %s", last_ds[i]);
+              Tcl_ListObjAppendElement(interp, listPtr,
+                      Tcl_NewStringObj(s, -1));
+               free(last_ds[i]);
+               free(ds_namv[i]);
+           }
+           sprintf(s, "\n");
+          Tcl_ListObjAppendElement(interp, listPtr,
+                   Tcl_NewStringObj(s, -1));
+           free(last_ds);
+           free(ds_namv);
+          }
+}
 
 static int
 Rrd_Fetch(ClientData clientData, Tcl_Interp *interp, int argc, CONST84 char *argv[])
@@ -528,20 +563,21 @@ typedef struct {
 } CmdInfo;
 
 static CmdInfo rrdCmds[] = {
-    { "Rrd::create",   Rrd_Create,     1 }, /* Thread-safe version */
-    { "Rrd::dump",     Rrd_Dump,       0 }, /* Thread-safe version */
-    { "Rrd::last",     Rrd_Last,       0 }, /* Thread-safe version */
-    { "Rrd::update",   Rrd_Update,     1 }, /* Thread-safe version */
-    { "Rrd::fetch",    Rrd_Fetch,      0 },
-    { "Rrd::graph",    Rrd_Graph,      1 }, /* Due to RRD's API, a safe
+    { "Rrd::create",    Rrd_Create,     1 }, /* Thread-safe version */
+    { "Rrd::dump",      Rrd_Dump,       0 }, /* Thread-safe version */
+    { "Rrd::last",      Rrd_Last,       0 }, /* Thread-safe version */
+    { "Rrd::lastupdate", Rrd_Lastupdate, 0 }, /* Thread-safe version */
+    { "Rrd::update",    Rrd_Update,     1 }, /* Thread-safe version */
+    { "Rrd::fetch",     Rrd_Fetch,      0 },
+    { "Rrd::graph",     Rrd_Graph,      1 }, /* Due to RRD's API, a safe
                                                interpreter cannot create
                                                a graph since it writes to
                                                a filename supplied by the
                                                caller */
-    { "Rrd::tune",     Rrd_Tune,       1 },
-    { "Rrd::resize",   Rrd_Resize,     1 },
-    { "Rrd::restore",  Rrd_Restore,    1 },
-    { (char *) NULL,   (Tcl_CmdProc *) NULL, 0 }
+    { "Rrd::tune",      Rrd_Tune,       1 },
+    { "Rrd::resize",    Rrd_Resize,     1 },
+    { "Rrd::restore",   Rrd_Restore,    1 },
+    { (char *) NULL,   (Tcl_CmdProc *)  NULL, 0        }
 };
 
 
index 19f5730..70f456c 100644 (file)
@@ -12,7 +12,7 @@ POD = bin_dec_hex.pod        rrddump.pod            rrdgraph_examples.pod  rrdre
       cdeftutorial.pod       rrdfetch.pod           rrdgraph_graph.pod     rrdthreads.pod         rrdxport.pod   \
       rpntutorial.pod        rrdfirst.pod           rrdgraph_rpn.pod       rrdtool.pod                           \
       rrd-beginners.pod      rrdinfo.pod            rrdtune.pod            rrdbuild.pod                          \
-      rrdcgi.pod             rrdgraph.pod           rrdlast.pod                                                  \
+      rrdcgi.pod             rrdgraph.pod           rrdlast.pod            rrdlastupdate.pod                     \
       rrdcreate.pod          rrdgraph_data.pod      rrdresize.pod          rrdtutorial.pod                       
 
 
index 1a1c7ed..1f5fe0c 100644 (file)
@@ -35,6 +35,7 @@ RRD_C_FILES =         \
        rrd_graph.c     \
        rrd_graph_helper.c      \
        rrd_last.c      \
+       rrd_lastupdate.c        \
        rrd_first.c     \
        rrd_resize.c    \
        rrd_restore.c   \
index f393f86..72f8fe8 100644 (file)
@@ -28,7 +28,8 @@ void PrintUsage(char *cmd)
 
     char help_list[] =
           "Valid commands: create, update, updatev, graph, dump, restore,\n"
-          "\t\tlast, first, info, fetch, tune, resize, xport\n\n";
+          "\t\tlast, lastupdate, first, info, fetch, tune,\n"
+          " resize, xport\n\n";
 
     char help_listremote[] =
            "Valid remote commands: quit, ls, cd, mkdir, pwd\n\n";
@@ -57,6 +58,11 @@ void PrintUsage(char *cmd)
            "* last - show last update time for RRD\n\n"
            "\trrdtool last filename.rrd\n\n";
 
+    char help_lastupdate[] =
+          "* lastupdate - returns the most recent datum stored for\n"
+          "  each DS in an RRD\n\n"
+          "\trrdtool lastupdate filename.rrd\n\n"; 
+
     char help_first[] =
            "* first - show first update time for RRA within an RRD\n\n"
            "\trrdtool first filename.rrd [--rraindex number]\n\n";
@@ -190,9 +196,10 @@ void PrintUsage(char *cmd)
 
           "For more information read the RRD manpages\n\n";
 
-    enum { C_NONE, C_CREATE, C_DUMP, C_INFO, C_RESTORE, C_LAST, C_FIRST,
-          C_UPDATE, C_FETCH, C_GRAPH, C_TUNE, C_RESIZE, C_XPORT,
-           C_QUIT, C_LS, C_CD, C_MKDIR, C_PWD, C_UPDATEV };
+    enum { C_NONE, C_CREATE, C_DUMP, C_INFO, C_RESTORE, C_LAST,
+          C_LASTUPDATE, C_FIRST, C_UPDATE, C_FETCH, C_GRAPH, C_TUNE,
+          C_RESIZE, C_XPORT, C_QUIT, C_LS, C_CD, C_MKDIR, C_PWD,
+          C_UPDATEV };
 
     int help_cmd = C_NONE;
 
@@ -208,6 +215,8 @@ void PrintUsage(char *cmd)
                help_cmd = C_RESTORE;
            else if (!strcmp(cmd,"last"))
                help_cmd = C_LAST;
+           else if (!strcmp(cmd,"lastupdate"))
+               help_cmd = C_LASTUPDATE;
            else if (!strcmp(cmd,"first"))
                help_cmd = C_FIRST;
            else if (!strcmp(cmd,"update"))
@@ -259,6 +268,9 @@ void PrintUsage(char *cmd)
            case C_LAST:
                fputs(help_last, stdout);
                break;
+           case C_LASTUPDATE:
+               fputs(help_lastupdate, stdout);
+               break;
            case C_FIRST:
                fputs(help_first, stdout);
                break;
@@ -607,7 +619,7 @@ int HandleInputLine(int argc, char **argv, FILE* out)
        }
        free(data);
     }
-       
+
     else if (strcmp("--version", argv[1]) == 0 ||
             strcmp("version", argv[1]) == 0 || 
             strcmp("v", argv[1]) == 0 ||
@@ -621,7 +633,28 @@ int HandleInputLine(int argc, char **argv, FILE* out)
        rrd_resize(argc-1, &argv[1]);
     else if (strcmp("last", argv[1]) == 0)
         printf("%ld\n",rrd_last(argc-1, &argv[1]));
-    else if (strcmp("first", argv[1]) == 0)
+    else if (strcmp("lastupdate", argv[1]) == 0) {
+          time_t      last_update;
+           char        **ds_namv;
+           char        **last_ds;
+           unsigned long ds_cnt,
+                       i;
+          if (rrd_lastupdate(argc-1, &argv[1], &last_update,
+                       &ds_cnt, &ds_namv, &last_ds) == 0) {
+               for (i=0; i<ds_cnt; i++)
+                       printf(" %s", ds_namv[i]);
+               printf("\n\n");
+               printf("%10lu:", last_update);
+               for (i=0; i<ds_cnt; i++) {
+                       printf(" %s", last_ds[i]);
+                       free(last_ds[i]);
+                       free(ds_namv[i]);
+               }
+               printf("\n");
+               free(last_ds);
+               free(ds_namv);
+          }
+    } else if (strcmp("first", argv[1]) == 0)
         printf("%ld\n",rrd_first(argc-1, &argv[1]));
     else if (strcmp("update", argv[1]) == 0)
        rrd_update(argc-1, &argv[1]);
index bb96194..df6a5a9 100644 (file)
@@ -151,6 +151,8 @@ typedef struct info_t {
 } info_t;
 
 info_t *rrd_info(int, char **);
+int rrd_lastupdate(int argc, char **argv, time_t *last_update,
+                unsigned long *ds_cnt, char ***ds_namv, char ***last_ds);
 info_t *rrd_update_v(int, char **);
 char * sprintf_alloc(char *, ...);
 info_t *info_push(info_t *, char *, enum info_type, infoval);
index 0f32121..a66f14e 100644 (file)
@@ -590,8 +590,7 @@ _rrd_update(char *filename, char *tmplt, int argc, char **argv,
            dst_idx= dst_conv(rrd.ds_def[i].dst);
 
             /* make sure we do not build diffs with old last_ds values */
-           if(rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt < interval 
-               && ( dst_idx == DST_COUNTER || dst_idx == DST_DERIVE)){
+           if(rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt < interval) {
                strncpy(rrd.pdp_prep[i].last_ds,"U",LAST_DS_LEN-1);
                rrd.pdp_prep[i].last_ds[LAST_DS_LEN-1]='\0';
            }
@@ -702,11 +701,8 @@ _rrd_update(char *filename, char *tmplt, int argc, char **argv,
                    rrd.pdp_prep[i].last_ds,
                    updvals[i+1], pdp_new[i]);
 #endif
-           if(dst_idx == DST_COUNTER || dst_idx == DST_DERIVE){
-               strncpy(rrd.pdp_prep[i].last_ds,
-                       updvals[i+1],LAST_DS_LEN-1);
-               rrd.pdp_prep[i].last_ds[LAST_DS_LEN-1]='\0';
-           }
+           strncpy(rrd.pdp_prep[i].last_ds, updvals[i+1],LAST_DS_LEN-1);
+           rrd.pdp_prep[i].last_ds[LAST_DS_LEN-1]='\0';
        }
        /* break out of the argument parsing loop if the error_string is set */
        if (rrd_test_error()){