1 /*****************************************************************************
2 * RRDtool 1.0.33 Copyright Tobias Oetiker, 1997 - 2000
3 *****************************************************************************
4 * rrd_info Get Information about the configuration of an RRD
5 *****************************************************************************/
11 static char * sprintf_alloc(char *, ...);
12 static info_t *push(info_t *, char *, enum info_type, infoval);
13 info_t *rrd_info(int, char **);
15 /* allocate memory for string */
17 sprintf_alloc(char *fmt, ...) {
25 str = malloc(sizeof(char)*(strlen(fmt)+maxlen));
29 vsnprintf(str, maxlen-1, fmt, argp);
31 vsprintf(str, fmt, argp);
39 *push(info_t *info, char *key, enum info_type type, infoval value){
41 next = malloc(sizeof(*next));
42 next->next = (info_t *) 0;
49 next->value.u_val = value.u_val;
52 next->value.u_cnt = value.u_cnt;
55 next->value.u_str = malloc(sizeof(char)*(strlen(value.u_str)+1));
56 strcpy(next->value.u_str,value.u_str);
64 rrd_info(int argc, char **argv) {
71 if(rrd_open(argv[1],&in_file,&rrd, RRD_READONLY)==-1){
77 cd=push(NULL,sprintf_alloc("filename"), RD_I_STR, info);
80 info.u_str=rrd.stat_head->version;
81 cd=push(cd,sprintf_alloc("rrd_version"), RD_I_STR, info);
83 info.u_cnt=rrd.stat_head->pdp_step;
84 cd=push(cd,sprintf_alloc("step"), RD_I_CNT, info);
86 info.u_cnt=rrd.live_head->last_up;
87 cd=push(cd,sprintf_alloc("last_update"), RD_I_CNT, info);
89 for(i=0;i<rrd.stat_head->ds_cnt;i++){
91 info.u_str=rrd.ds_def[i].dst;
92 cd=push(cd,sprintf_alloc("ds[%s].type", rrd.ds_def[i].ds_nam), RD_I_STR, info);
94 info.u_cnt=rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt;
95 cd=push(cd,sprintf_alloc("ds[%s].minimal_heartbeat",rrd.ds_def[i].ds_nam), RD_I_CNT, info);
97 info.u_val=rrd.ds_def[i].par[DS_min_val].u_val;
98 cd=push(cd,sprintf_alloc("ds[%s].min", rrd.ds_def[i].ds_nam), RD_I_VAL, info);
100 info.u_val=rrd.ds_def[i].par[DS_max_val].u_val;
101 cd=push(cd,sprintf_alloc("ds[%s].max", rrd.ds_def[i].ds_nam), RD_I_VAL, info);
103 info.u_str=rrd.pdp_prep[i].last_ds;
104 cd=push(cd,sprintf_alloc("ds[%s].last_ds", rrd.ds_def[i].ds_nam), RD_I_STR, info);
106 info.u_val=rrd.pdp_prep[i].scratch[PDP_val].u_val;
107 cd=push(cd,sprintf_alloc("ds[%s].value", rrd.ds_def[i].ds_nam), RD_I_VAL, info);
109 info.u_cnt=rrd.pdp_prep[i].scratch[PDP_unkn_sec_cnt].u_cnt;
110 cd=push(cd,sprintf_alloc("ds[%s].unknown_sec", rrd.ds_def[i].ds_nam), RD_I_CNT, info);
113 for(i=0;i<rrd.stat_head->rra_cnt;i++){
114 info.u_str=rrd.rra_def[i].cf_nam;
115 cd=push(cd,sprintf_alloc("rra[%d].cf", i), RD_I_STR, info);
117 info.u_cnt=rrd.rra_def[i].row_cnt;
118 cd=push(cd,sprintf_alloc("rra[%d].rows",i), RD_I_CNT, info);
120 info.u_cnt=rrd.rra_def[i].pdp_cnt;
121 cd=push(cd,sprintf_alloc("rra[%d].pdp_per_row",i), RD_I_CNT, info);
123 info.u_val=rrd.rra_def[i].par[RRA_cdp_xff_val].u_val;
124 cd=push(cd,sprintf_alloc("rra[%d].xff",i), RD_I_VAL, info);
126 for(ii=0;ii<rrd.stat_head->ds_cnt;ii++){
127 info.u_val=rrd.cdp_prep[i*rrd.stat_head->ds_cnt+ii].scratch[CDP_val].u_val;
128 cd=push(cd,sprintf_alloc("rra[%d].cdp_prep[%d].value",i,ii), RD_I_VAL, info);
130 info.u_cnt=rrd.cdp_prep[i*rrd.stat_head->ds_cnt+ii].scratch[CDP_unkn_pdp_cnt].u_cnt;
131 cd=push(cd,sprintf_alloc("rra[%d].cdp_prep[%d].unknown_datapoints",i,ii), RD_I_CNT, info);