1 /*****************************************************************************
2 * RRDtool 1.0.33 Copyright Tobias Oetiker, 1997 - 2000
3 *****************************************************************************
4 * rrd_dump Display a RRD
5 *****************************************************************************
8 * Revision 1.2 2001/03/04 13:01:55 oetiker
9 * Aberrant Behavior Detection support. A brief overview added to rrdtool.pod.
10 * Major updates to rrd_update.c, rrd_create.c. Minor update to other core files.
11 * This is backwards compatible! But new files using the Aberrant stuff are not readable
12 * by old rrdtool versions. See http://cricket.sourceforge.net/aberrant/rrd_hw.htm
13 * -- Jake Brutlag <jakeb@corp.webtv.net>
15 * Revision 1.1.1.1 2001/02/25 22:25:05 oetiker
18 *****************************************************************************/
22 extern char *tzname[2];
25 rrd_dump(int argc, char **argv)
31 long rra_base, rra_start, rra_next;
36 if(rrd_open(argv[1],&in_file,&rrd, RRD_READONLY)==-1){
40 puts("<!-- Round Robin Database Dump -->");
42 printf("\t<version> %s </version>\n",RRD_VERSION);
43 printf("\t<step> %lu </step> <!-- Seconds -->\n",rrd.stat_head->pdp_step);
45 strftime(somestring,200,"%Y-%m-%d %H:%M:%S %Z",
46 localtime(&rrd.live_head->last_up));
48 # error "Need strftime"
50 printf("\t<lastupdate> %ld </lastupdate> <!-- %s -->\n\n",
51 rrd.live_head->last_up,somestring);
52 for(i=0;i<rrd.stat_head->ds_cnt;i++){
54 printf("\t\t<name> %s </name>\n",rrd.ds_def[i].ds_nam);
55 printf("\t\t<type> %s </type>\n",rrd.ds_def[i].dst);
56 printf("\t\t<minimal_heartbeat> %lu </minimal_heartbeat>\n",rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt);
57 if (isnan(rrd.ds_def[i].par[DS_min_val].u_val)){
58 printf("\t\t<min> NaN </min>\n");
60 printf("\t\t<min> %0.10e </min>\n",rrd.ds_def[i].par[DS_min_val].u_val);
62 if (isnan(rrd.ds_def[i].par[DS_max_val].u_val)){
63 printf("\t\t<max> NaN </max>\n");
65 printf("\t\t<max> %0.10e </max>\n",rrd.ds_def[i].par[DS_max_val].u_val);
67 printf("\n\t\t<!-- PDP Status -->\n");
68 printf("\t\t<last_ds> %s </last_ds>\n",rrd.pdp_prep[i].last_ds);
69 if (isnan(rrd.pdp_prep[i].scratch[PDP_val].u_val)){
70 printf("\t\t<value> NaN </value>\n");
72 printf("\t\t<value> %0.10e </value>\n",rrd.pdp_prep[i].scratch[PDP_val].u_val);
74 printf("\t\t<unknown_sec> %lu </unknown_sec>\n",
75 rrd.pdp_prep[i].scratch[PDP_unkn_sec_cnt].u_cnt);
77 printf("\t</ds>\n\n");
80 puts("<!-- Round Robin Archives -->");
82 rra_base=ftell(in_file);
85 for(i=0;i<rrd.stat_head->rra_cnt;i++){
89 rra_next += ( rrd.stat_head->ds_cnt
90 * rrd.rra_def[i].row_cnt
91 * sizeof(rrd_value_t));
93 printf("\t\t<cf> %s </cf>\n",rrd.rra_def[i].cf_nam);
94 printf("\t\t<pdp_per_row> %lu </pdp_per_row> <!-- %lu seconds -->\n\n",
95 rrd.rra_def[i].pdp_cnt, rrd.rra_def[i].pdp_cnt
96 *rrd.stat_head->pdp_step);
97 /* added support for RRA parameters */
98 printf("\t\t<params>");
99 for (ii = 0; ii < MAX_RRA_PAR_EN; ii++)
101 value = rrd.rra_def[i].par[ii];
102 if (ii == RRA_dependent_rra_idx ||
103 ii == RRA_seasonal_smooth_idx ||
104 ii == RRA_failure_threshold)
105 printf("<value> %lu </value>", value.u_cnt);
107 if (isnan(value.u_val)) {
108 printf("<value> NaN </value>");
110 printf("<value> %0.10e </value>", value.u_val);
114 printf("\t\t</params>\n");
115 printf("\t\t<cdp_prep>\n");
116 for(ii=0;ii<rrd.stat_head->ds_cnt;ii++){
118 double value = rrd.cdp_prep[i*rrd.stat_head->ds_cnt+ii].scratch[CDP_val].u_val;
120 printf("\t\t\t<ds>");
121 /* added support for exporting all CDP parameters */
122 for (iii=0; iii < MAX_CDP_PAR_EN ; iii++)
124 value = rrd.cdp_prep[i*rrd.stat_head->ds_cnt + ii].scratch[iii];
125 /* handle integer values as a special case */
126 if (cf_conv(rrd.rra_def[i].cf_nam) == CF_FAILURES ||
127 iii == CDP_unkn_pdp_cnt ||
128 iii == CDP_null_count ||
129 iii == CDP_last_null_count)
130 printf("<value> %lu </value>", value.u_cnt);
132 if (isnan(value.u_val)) {
133 printf("<value> NaN </value>");
135 printf("<value> %0.10e </value>", value.u_val);
140 printf(" <unknown_datapoints> %lu </unknown_datapoints>",
141 rrd.cdp_prep[i*rrd.stat_head->ds_cnt+ii].scratch[CDP_unkn_pdp_cnt].u_cnt);
145 printf("\t\t</cdp_prep>\n");
147 printf("\t\t<database>\n");
148 fseek(in_file,(rra_start
149 +(rrd.rra_ptr[i].cur_row+1)
150 * rrd.stat_head->ds_cnt
151 * sizeof(rrd_value_t)),SEEK_SET);
152 timer = - (rrd.rra_def[i].row_cnt-1);
153 ii=rrd.rra_ptr[i].cur_row;
154 for(ix=0;ix<rrd.rra_def[i].row_cnt;ix++){
156 if (ii>=rrd.rra_def[i].row_cnt) {
157 fseek(in_file,rra_start,SEEK_SET);
158 ii=0; /* wrap if max row cnt is reached */
160 now = (rrd.live_head->last_up
161 - rrd.live_head->last_up
162 % (rrd.rra_def[i].pdp_cnt*rrd.stat_head->pdp_step))
163 + (timer*rrd.rra_def[i].pdp_cnt*rrd.stat_head->pdp_step);
167 strftime(somestring,200,"%Y-%m-%d %H:%M:%S %Z", localtime(&now));
169 # error "Need strftime"
171 printf("\t\t\t<!-- %s / %d --> <row>",somestring,(int)now);
172 for(iii=0;iii<rrd.stat_head->ds_cnt;iii++){
173 fread(&my_cdp,sizeof(rrd_value_t),1,in_file);
175 printf("<v> NaN </v>");
177 printf("<v> %0.10e </v>",my_cdp);
182 printf("\t\t</database>\n\t</rra>\n");