[rrd-users] Re: patchkit for "rrdtool last file.rrd [--time|--counters|--values]"

Tobias Oetiker oetiker at ee.ethz.ch
Fri Sep 24 06:59:23 MEST 1999


Sep 13 you sent me mail regarding [rrd-users] patchkit for "rrdtool last...:

*> 
*> See enclosed or [1].  I recken this is useful:  
*> 
*>  bash% rrdtool last --time some.rrd
*>  time:937242355
*> 
*>  bash% rrdtool last --counters some.rrd
*>  counter:input:937242355:1972629937
*>  counter:output:937242355:3028471975
*> 
*>  bash% rrdtool last --values some.rrd
*>  value:input:937242355:1.0463010000e+06
*>  value:output:937242355:3.5241593750e+05
*> 
*> The WiscNet rrdtool stuff will depend on it eventually so it'd
*> be nice if it makes it way into the source.
*> 
ok ... will add ... just a qustion thugh ... I do hope you are using the
perl shared module interface ...

cheers
tobi
*> later
*> steve
*> - - -
*> systems guy
*> wiscnet.net
*> 
*>  [1] ftp://teak.wiscnet.net/pub/src/rrd-1.0.7-last.patch
*> 
*> 
*> -- Attached file included as plaintext by Listar --
*> -- Desc: rrd-1.0.7-last.patch
*> 
*> --- rrdtool-1.0.7/src/rrd_tool.c.orig	Fri Aug 27 14:20:05 1999
*> +++ rrdtool-1.0.7/src/rrd_tool.c	Sat Sep 11 21:26:55 1999
*> @@ -36,8 +36,9 @@
*>  	   "* restore - restore an RRD file from its XML form\n\n"
*>  	   "\trrdtool restore [--range-check|-r] filename.xml filename.rrd\n\n"
*>  
*> -           "* last - show last update time for RRD\n\n"
*> -           "\trrdtool last filename.rrd\n\n"
*> +           "* last - show last update time or counters or values for an RRD\n\n"
*> +           "\trrdtool last filename.rrd\n"
*> +	   "\t\t[--time|-t --counters|-c --values|-v]\n\n"
*>  
*>  	   "* update - update an RRD\n\n"
*>  	   "\trrdtool update filename\n"
*> @@ -190,7 +191,7 @@
*>      else if (strcmp("resize", argv[1]) == 0)
*>  	rrd_resize(argc-1, &argv[1]);
*>      else if (strcmp("last", argv[1]) == 0)
*> -        printf("%ld\n",rrd_last(argc-1, &argv[1]));
*> +	rrd_last(argc-1, &argv[1]);
*>      else if (strcmp("update", argv[1]) == 0)
*>  	rrd_update(argc-1, &argv[1]);
*>      else if (strcmp("fetch", argv[1]) == 0) {
*> --- rrdtool-1.0.7/src/rrd_last.c.orig	Fri Aug 27 14:20:05 1999
*> +++ rrdtool-1.0.7/src/rrd_last.c	Sat Sep 11 21:28:44 1999
*> @@ -4,6 +4,7 @@
*>   * rrd_last.c
*>   *****************************************************************************
*>   * Initial version by Russ Wright, @Home Network, 9/28/98
*> + * Time, counters and values options added by steve rader, 9/11/99
*>   *****************************************************************************/
*>  
*>  #include "rrd_tool.h"
*> @@ -12,23 +13,81 @@
*>  rrd_last(int argc, char **argv)
*>  {
*>      FILE	*in_file;
*> -    time_t       lastup;
*> -
*>      rrd_t	 rrd;
*> +    int          i, time = 0, counters = 0, values = 0;
*> +
*> +    while (1) {
*> +        static struct option long_options[] =
*> +            {   {"time", 0 , 0, 't'},
*> +                {"counters", 0 , 0, 'c'},
*> +                {"values", 0 , 0, 'v'},
*> +                {0,0,0,0}
*> +            };
*> +        int option_index = 0;
*> +        int opt;
*> +        opt = getopt_long(argc, argv, "tcv", long_options, &option_index);
*> +
*> +        if (opt == EOF)
*> +          break;
*> +
*> +        switch(opt) {
*> +        case 't':
*> +            time = 1;
*> +            break;
*> +        case 'c':
*> +            counters = 1;
*> +            break;
*> +        case 'v':
*> +            values = 1;
*> +            break;
*> +        case '?':
*> +            rrd_set_error("unknown option '%s'",argv[optind-1]);
*> +            rrd_free(&rrd);
*> +            return(-1);
*> +        }
*> +    }
*>  
*> -    if(argc < 2){
*> -        rrd_set_error("please specify an rrd");
*> +    /* need one arg: rrd filename */
*> +    if(argc-optind < 1){
*> +        rrd_set_error("not enough arguments");
*>          return(-1);
*>      }
*> -    if(rrd_open(argv[1], &in_file, &rrd, RRD_READONLY)==-1){
*> +    /* no args defaults to old usage */
*> +    if ( time == 0 && counters == 0 && values == 0 ) {
*> +        time = 1;
*> +    }
*> +
*> +    if(rrd_open(argv[optind], &in_file, &rrd, RRD_READONLY)==-1){
*>          return(-1);
*>      }
*> -    lastup = rrd.live_head->last_up;
*> +
*> +    if ( time ) {
*> +        printf("time:%ld\n",rrd.live_head->last_up);
*> +    }
*> +    if ( counters ) {
*> +        for(i=0;i<rrd.stat_head->ds_cnt;i++){
*> +            printf("counter:%s:%ld:%s\n",
*> +                rrd.ds_def[i].ds_nam, 
*> +                rrd.live_head->last_up,
*> +                rrd.pdp_prep[i].last_ds);
*> +        }
*> +    }
*> +    if ( values ) {
*> +        for(i=0;i<rrd.stat_head->ds_cnt;i++){
*> +            if (isnan(rrd.pdp_prep[i].scratch[PDP_val].u_val)){
*> +                printf("value:%s:%ld:NaN\n",
*> +                    rrd.ds_def[i].ds_nam, 
*> +                    rrd.live_head->last_up);
*> +            } else {
*> +                printf("value:%s:%ld:%0.10e\n",
*> +                    rrd.ds_def[i].ds_nam, 
*> +                    rrd.live_head->last_up,
*> +                    rrd.pdp_prep[i].scratch[PDP_val].u_val);
*> +            }
*> +        }
*> +    }
*> +
*>      rrd_free(&rrd);
*>      fclose(in_file);
*> -    return(lastup);
*>  }
*> - 
*> -
*> -
*>  
*> 
*> 
*> --
*> * To unsubscribe from the rrd-users mailing list, send a message with the
*>   subject: unsubscribe to rrd-users-request at list.ee.ethz.ch
*> 
*> 

-- 
 ______    __   _
/_  __/_  / /  (_) Oetiker, Timelord & SysMgr @ EE-Dept ETH-Zurich
 / // _ \/ _ \/ / TEL: +41(0)1-6325286  FAX:...1517  ICQ: 10419518 
/_/ \.__/_.__/_/ oetiker at ee.ethz.ch http://ee-staff.ethz.ch/~oetiker

--
* To unsubscribe from the rrd-users mailing list, send a message with the
  subject: unsubscribe to rrd-users-request at list.ee.ethz.ch



More information about the rrd-users mailing list