Code

added at-style-time@value:value syntax to rrd_update
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sun, 4 Mar 2001 11:14:26 +0000 (11:14 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sun, 4 Mar 2001 11:14:26 +0000 (11:14 +0000)
--  Dave Bodenstab <imdave@mcs.net>

git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@20 a5681a0c-68f1-0310-ab6d-d61299d08faa

doc/rrdupdate.pod
src/rrd_tool.c
src/rrd_update.c

index bc4e902c87e1090203189e094ed3e84c69d30931..f1500541a23d15207737073f7bbe446d5ace6888 100644 (file)
@@ -9,6 +9,7 @@ rrdtool update - Store a new set of values into the rrd
 B<rrdtool> B<update> I<filename> 
 S<[B<--template>|B<-t> I<ds-name>[B<:>I<ds-name>]...]> 
 S<B<N>|I<timestamp>B<:>I<value>[B<:>I<value>...]> 
 B<rrdtool> B<update> I<filename> 
 S<[B<--template>|B<-t> I<ds-name>[B<:>I<ds-name>]...]> 
 S<B<N>|I<timestamp>B<:>I<value>[B<:>I<value>...]> 
+S<I<at-timestamp>B<@>I<value>[B<:>I<value>...]> 
 S<[I<timestamp>B<:>I<value>[B<:>I<value>...] ...]>
 
 =head1 DESCRIPTION
 S<[I<timestamp>B<:>I<value>[B<:>I<value>...] ...]>
 
 =head1 DESCRIPTION
@@ -40,6 +41,9 @@ The data used for updating the RRD was acquired at a certain time. This
 time can either be defined in seconds since 1970-01-01. Or by using the
 letter 'N' the update time is set to be the current time. Negative time
 values are subtracted from the current time.
 time can either be defined in seconds since 1970-01-01. Or by using the
 letter 'N' the update time is set to be the current time. Negative time
 values are subtracted from the current time.
+An AT_STYLE TIME SPECIFICATION (see the I<rrdfetch> documentation) may
+also be used by delimiting the end of the time specification with the '@' character
+instead of a ':'.
 Getting the timing right to the second is especially
 important when you are working with data-sources of type B<COUNTER>,
 B<DERIVE> or B<ABSOLUTE>. 
 Getting the timing right to the second is especially
 important when you are working with data-sources of type B<COUNTER>,
 B<DERIVE> or B<ABSOLUTE>. 
index 4d6ffc9ba39cdbe0b71ab33ff9ff7adc23c02325..a73a304240e59e980c68df55e530b41f7e624cd1 100644 (file)
@@ -53,7 +53,8 @@ void PrintUsage(char *cmd)
           "\trrdtool update filename\n"
           "\t\t--template|-t ds-name:ds-name:...\n"
           "\t\ttime|N:value[:value...]\n\n"
           "\trrdtool update filename\n"
           "\t\t--template|-t ds-name:ds-name:...\n"
           "\t\ttime|N:value[:value...]\n\n"
-          "\t\t[ time:value[:value...] ..]\n\n";
+           "\t\tat-time@value[:value...]\n\n"
+          "\t\t[ time:value[:value...] ..]\n\n";
 
     char help_fetch[] =
           "* fetch - fetch data out of an RRD\n\n"
 
     char help_fetch[] =
           "* fetch - fetch data out of an RRD\n\n"
index 94db63a6ef7aaa00152b21b5161af15b447c97c1..1e5a83e07c694c283ddd552ab3b53bd9e247e44b 100644 (file)
@@ -5,8 +5,12 @@
  *****************************************************************************
  * $Id$
  * $Log$
  *****************************************************************************
  * $Id$
  * $Log$
- * Revision 1.1  2001/02/25 22:25:06  oetiker
- * Initial revision
+ * Revision 1.2  2001/03/04 11:14:25  oetiker
+ * added at-style-time@value:value syntax to rrd_update
+ * --  Dave Bodenstab <imdave@mcs.net>
+ *
+ * Revision 1.1.1.1  2001/02/25 22:25:06  oetiker
+ * checkin
  *
  *****************************************************************************/
 
  *
  *****************************************************************************/
 
@@ -36,6 +40,7 @@ main(int argc, char **argv){
                         "Usage: rrdupdate filename\n"
                         "\t\t\t[--template|-t ds-name:ds-name:...]\n"
                         "\t\t\ttime|N:value[:value...]\n\n"
                         "Usage: rrdupdate filename\n"
                         "\t\t\t[--template|-t ds-name:ds-name:...]\n"
                         "\t\t\ttime|N:value[:value...]\n\n"
+                        "\t\t\tat-time@value[:value...]\n\n"
                         "\t\t\t[ time:value[:value...] ..]\n\n");
                                    
                 printf("ERROR: %s\n",rrd_get_error());
                         "\t\t\t[ time:value[:value...] ..]\n\n");
                                    
                 printf("ERROR: %s\n",rrd_get_error());
@@ -238,6 +243,10 @@ rrd_update(int argc, char **argv)
     for(arg_i=optind+1; arg_i<argc;arg_i++) {
        char *stepper = malloc((strlen(argv[arg_i])+1)*sizeof(char));
         char *step_start = stepper;
     for(arg_i=optind+1; arg_i<argc;arg_i++) {
        char *stepper = malloc((strlen(argv[arg_i])+1)*sizeof(char));
         char *step_start = stepper;
+       char *p;
+       char *parsetime_error = NULL;
+       enum {atstyle, normal} timesyntax;
+       struct time_value ds_tv;
         if (stepper == NULL){
                 rrd_set_error("faild duplication argv entry");
                 free(updvals);
         if (stepper == NULL){
                 rrd_set_error("faild duplication argv entry");
                 free(updvals);
@@ -250,9 +259,26 @@ rrd_update(int argc, char **argv)
        /* initialize all ds input to unknown except the first one
            which has always got to be set */
        for(ii=1;ii<=rrd.stat_head->ds_cnt;ii++) updvals[ii] = "U";
        /* initialize all ds input to unknown except the first one
            which has always got to be set */
        for(ii=1;ii<=rrd.stat_head->ds_cnt;ii++) updvals[ii] = "U";
-       ii=0;
        strcpy(stepper,argv[arg_i]);
        updvals[0]=stepper;
        strcpy(stepper,argv[arg_i]);
        updvals[0]=stepper;
+       /* separate all ds elements; first must be examined separately
+          due to alternate time syntax */
+       if ((p=strchr(stepper,'@'))!=NULL) {
+           timesyntax = atstyle;
+           *p = '\0';
+           stepper = p+1;
+       } else if ((p=strchr(stepper,':'))!=NULL) {
+           timesyntax = normal;
+           *p = '\0';
+           stepper = p+1;
+       } else {
+           rrd_set_error("expected timestamp not found in data source from %s:...",
+                         argv[arg_i]);
+           free(step_start);
+           break;
+       }
+       ii=1;
+       updvals[tmpl_idx[ii]] = stepper;
        while (*stepper) {
            if (*stepper == ':') {
                *stepper = '\0';
        while (*stepper) {
            if (*stepper == ':') {
                *stepper = '\0';
@@ -272,7 +298,23 @@ rrd_update(int argc, char **argv)
        }
        
         /* get the time from the reading ... handle N */
        }
        
         /* get the time from the reading ... handle N */
-       if (strcmp(updvals[0],"N")==0){
+       if (timesyntax == atstyle) {
+            if ((parsetime_error = parsetime(updvals[0], &ds_tv))) {
+                rrd_set_error("ds time: %s: %s", updvals[0], parsetime_error );
+               free(step_start);
+               break;
+           }
+           if (ds_tv.type == RELATIVE_TO_END_TIME ||
+               ds_tv.type == RELATIVE_TO_START_TIME) {
+               rrd_set_error("specifying time relative to the 'start' "
+                              "or 'end' makes no sense here: %s",
+                             updvals[0]);
+               free(step_start);
+               break;
+           }
+
+           current_time = mktime(&ds_tv.tm) + ds_tv.offset;
+       } else if (strcmp(updvals[0],"N")==0){
            current_time = time(NULL);
        } else {
            current_time = atol(updvals[0]);
            current_time = time(NULL);
        } else {
            current_time = atol(updvals[0]);