X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_stat.c;h=4bd9e5b631753880bdba3a79b87712026b9c1668;hb=8a21b9cb276aa9b7401533474019f4ee1251a377;hp=35d1c2753a4bf4aaf2a6e16b5c55f5361025469e;hpb=96db36a7a6ff75d2fc1353e45434a7f6b1db801b;p=rrdtool.git diff --git a/src/rrd_stat.c b/src/rrd_stat.c index 35d1c27..4bd9e5b 100644 --- a/src/rrd_stat.c +++ b/src/rrd_stat.c @@ -1,145 +1,151 @@ /***************************************************************************** - * RRDtool 1.2.7 Copyright by Tobi Oetiker, 1997-2005 + * RRDtool 1.2.23 Copyright by Tobi Oetiker, 1997-2007 ***************************************************************************** * rrd_stat Retreive the header part of an RRD *****************************************************************************/ #include "rrd_tool.h" -extern char *tzname[2]; +XXX:This file is not compiled.Is this on purpose ? extern char *tzname[2]; -stat_node -rrd_stat(int argc, char **argv) -{ - int i,ii,ix,iii=0; - time_t now; - char somestring[255]; - rrd_value_t my_cdp; - long rra_base, rra_start, rra_next; - FILE *in_file; - rrd_t rrd; +stat_node rrd_stat( + int argc, + char **argv) +{ + int i, ii, ix, iii = 0; + time_t now; + char somestring[255]; + rrd_value_t my_cdp; + long rra_base, rra_start, rra_next; + rrd_t rrd; + rrd_file_t *rrd_file; - if(rrd_open(argv[1],&in_file,&rrd, RRD_READONLY)==-1){ - return(-1); + rrd_file = rrd_open(argv[1], &rrd, RRD_READONLY); + if (rrd_file == NULL) { + return (-1); } puts(""); puts(""); - printf("\t %s \n",rrd.stat_head->version); - printf("\t %lu \n",rrd.stat_head->pdp_step); + printf("\t %s \n", rrd.stat_head->version); + printf("\t %lu \n", + rrd.stat_head->pdp_step); #if HAVE_STRFTIME - strftime(somestring,200,"%Y-%m-%d %H:%M:%S %Z", - localtime_r(&rrd.live_head->last_up, &tm)); + strftime(somestring, 200, "%Y-%m-%d %H:%M:%S %Z", + localtime_r(&rrd.live_head->last_up, &tm)); #else # error "Need strftime" #endif printf("\t %ld \n\n", - rrd.live_head->last_up,somestring); - for(i=0;ids_cnt;i++){ - printf("\t\n"); - printf("\t\t %s \n",rrd.ds_def[i].ds_nam); - printf("\t\t %s \n",rrd.ds_def[i].dst); - printf("\t\t %lu \n", - rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt); - if (isnan(rrd.ds_def[i].par[DS_min_val].u_val)){ - printf("\t\t NaN \n"); - } else { - printf("\t\t %0.10e \n",rrd.ds_def[i].par[DS_min_val].u_val); - } - if (isnan(rrd.ds_def[i].par[DS_max_val].u_val)){ - printf("\t\t NaN \n"); - } else { - printf("\t\t %0.10e \n",rrd.ds_def[i].par[DS_max_val].u_val); - } - printf("\n\t\t\n"); - printf("\t\t %s \n",rrd.pdp_prep[i].last_ds); - if (isnan(rrd.pdp_prep[i].scratch[PDP_val].u_val)){ - printf("\t\t NaN \n"); - } else { - printf("\t\t %0.10e \n",rrd.pdp_prep[i].scratch[PDP_val].u_val); - } - printf("\t\t %lu \n", - rrd.pdp_prep[i].scratch[PDP_unkn_sec_cnt].u_cnt); - - printf("\t\n\n"); + rrd.live_head->last_up, somestring); + for (i = 0; i < rrd.stat_head->ds_cnt; i++) { + printf("\t\n"); + printf("\t\t %s \n", rrd.ds_def[i].ds_nam); + printf("\t\t %s \n", rrd.ds_def[i].dst); + printf("\t\t %lu \n", + rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt); + if (isnan(rrd.ds_def[i].par[DS_min_val].u_val)) { + printf("\t\t NaN \n"); + } else { + printf("\t\t %0.10e \n", + rrd.ds_def[i].par[DS_min_val].u_val); + } + if (isnan(rrd.ds_def[i].par[DS_max_val].u_val)) { + printf("\t\t NaN \n"); + } else { + printf("\t\t %0.10e \n", + rrd.ds_def[i].par[DS_max_val].u_val); + } + printf("\n\t\t\n"); + printf("\t\t %s \n", rrd.pdp_prep[i].last_ds); + if (isnan(rrd.pdp_prep[i].scratch[PDP_val].u_val)) { + printf("\t\t NaN \n"); + } else { + printf("\t\t %0.10e \n", + rrd.pdp_prep[i].scratch[PDP_val].u_val); + } + printf("\t\t %lu \n", + rrd.pdp_prep[i].scratch[PDP_unkn_sec_cnt].u_cnt); + + printf("\t\n\n"); } puts(""); - rra_base=ftell(in_file); + rra_base = rrd_file->header_len; rra_next = rra_base; - for(i=0;irra_cnt;i++){ - - long timer=0; - rra_start= rra_next; - rra_next += ( rrd.stat_head->ds_cnt - * rrd.rra_def[i].row_cnt - * sizeof(rrd_value_t)); - printf("\t\n"); - printf("\t\t %s \n",rrd.rra_def[i].cf_nam); - printf("\t\t %lu \n\n", - rrd.rra_def[i].pdp_cnt, rrd.rra_def[i].pdp_cnt - *rrd.stat_head->pdp_step); - printf("\t\t\n"); - for(ii=0;iids_cnt;ii++){ - double value = rrd.cdp_prep[i*rrd.stat_head->ds_cnt+ii].scratch[CDP_val].u_val; - printf("\t\t\t"); - if (isnan(value)){ - printf(" NaN "); - } else { - printf(" %0.10e ", value); - } - printf(" %lu ", - rrd.cdp_prep[i*rrd.stat_head->ds_cnt+ii].scratch[CDP_unkn_pdp_cnt].u_cnt); - printf("\n"); + for (i = 0; i < rrd.stat_head->rra_cnt; i++) { + + long timer = 0; + + rra_start = rra_next; + rra_next += (rrd.stat_head->ds_cnt + * rrd.rra_def[i].row_cnt * sizeof(rrd_value_t)); + printf("\t\n"); + printf("\t\t %s \n", rrd.rra_def[i].cf_nam); + printf + ("\t\t %lu \n\n", + rrd.rra_def[i].pdp_cnt, + rrd.rra_def[i].pdp_cnt * rrd.stat_head->pdp_step); + printf("\t\t\n"); + for (ii = 0; ii < rrd.stat_head->ds_cnt; ii++) { + double value = + rrd.cdp_prep[i * rrd.stat_head->ds_cnt + + ii].scratch[CDP_val].u_val; + printf("\t\t\t"); + if (isnan(value)) { + printf(" NaN "); + } else { + printf(" %0.10e ", value); + } + printf(" %lu ", + rrd.cdp_prep[i * rrd.stat_head->ds_cnt + + ii].scratch[CDP_unkn_pdp_cnt].u_cnt); + printf("\n"); } - printf("\t\t\n"); + printf("\t\t\n"); - printf("\t\t\n"); - fseek(in_file,(rra_start - +(rrd.rra_ptr[i].cur_row+1) - * rrd.stat_head->ds_cnt - * sizeof(rrd_value_t)),SEEK_SET); - timer = - (rrd.rra_def[i].row_cnt-1); - ii=rrd.rra_ptr[i].cur_row; - for(ix=0;ix=rrd.rra_def[i].row_cnt) { - fseek(in_file,rra_start,SEEK_SET); - ii=0; /* wrap if max row cnt is reached */ - } - now = (rrd.live_head->last_up - - rrd.live_head->last_up - % (rrd.rra_def[i].pdp_cnt*rrd.stat_head->pdp_step)) - + (timer*rrd.rra_def[i].pdp_cnt*rrd.stat_head->pdp_step); + printf("\t\t\n"); + rrd_seek(rrd_file, (rra_start + (rrd.rra_ptr[i].cur_row + 1) + * rrd.stat_head->ds_cnt + * sizeof(rrd_value_t)), SEEK_SET); + timer = -(rrd.rra_def[i].row_cnt - 1); + ii = rrd.rra_ptr[i].cur_row; + for (ix = 0; ix < rrd.rra_def[i].row_cnt; ix++) { + ii++; + if (ii >= rrd.rra_def[i].row_cnt) { + rrd_seek(rrd_file, rra_start, SEEK_SET); + ii = 0; /* wrap if max row cnt is reached */ + } + now = (rrd.live_head->last_up + - rrd.live_head->last_up + % (rrd.rra_def[i].pdp_cnt * rrd.stat_head->pdp_step)) + + (timer * rrd.rra_def[i].pdp_cnt * rrd.stat_head->pdp_step); - timer++; + timer++; #if HAVE_STRFTIME - strftime(somestring,200,"%Y-%m-%d %H:%M:%S %Z", localtime_r(&now, &tm)); + strftime(somestring, 200, "%Y-%m-%d %H:%M:%S %Z", + localtime_r(&now, &tm)); #else # error "Need strftime" #endif - printf("\t\t\t ",somestring); - for(iii=0;iiids_cnt;iii++){ - fread(&my_cdp,sizeof(rrd_value_t),1,in_file); - if (isnan(my_cdp)){ - printf(" NaN "); - } else { - printf(" %0.10e ",my_cdp); - }; - } - printf("\n"); - } - printf("\t\t\n\t\n"); - + printf("\t\t\t ", somestring); + for (iii = 0; iii < rrd.stat_head->ds_cnt; iii++) { + rrd_read(rrd_file, &my_cdp, sizeof(rrd_value_t) * 1); + if (isnan(my_cdp)) { + printf(" NaN "); + } else { + printf(" %0.10e ", my_cdp); + }; + } + printf("\n"); + } + printf("\t\t\n\t\n"); + } printf("\n"); rrd_free(&rrd); - fclose(in_file); - return(0); + close(rrd_file->fd); + return (0); } - - - -