1 /*****************************************************************************
2 * RRDtool 1.3rc4 Copyright by Tobi Oetiker, 1997-2008
3 *****************************************************************************
4 * rrd_info Get Information about the configuration of an RRD
5 *****************************************************************************/
8 #include "rrd_rpncalc.h"
18 /* allocate memory for string */
30 str = malloc(sizeof(char) * (strlen(fmt) + maxlen));
34 vsnprintf(str, maxlen - 1, fmt, argp);
36 vsprintf(str, fmt, argp);
43 /* the function formerly known as push was renamed info_push because
44 * it is now used outside the scope of this file */
54 next = malloc(sizeof(*next));
55 next->next = (info_t *) 0;
62 next->value.u_val = value.u_val;
65 next->value.u_cnt = value.u_cnt;
68 next->value.u_int = value.u_int;
71 next->value.u_str = malloc(sizeof(char) * (strlen(value.u_str) + 1));
72 strcpy(next->value.u_str, value.u_str);
75 next->value.u_blo.size = value.u_blo.size;
76 next->value.u_blo.ptr =
77 malloc(sizeof(unsigned char) * value.u_blo.size);
78 memcpy(next->value.u_blo.ptr, value.u_blo.ptr, value.u_blo.size);
92 rrd_set_error("please specify an rrd");
96 info = rrd_info_r(argv[1]);
106 unsigned int i, ii = 0;
108 info_t *data = NULL, *cd;
110 rrd_file_t *rrd_file;
111 enum cf_en current_cf;
112 enum dst_en current_ds;
114 rrd_file = rrd_open(filename, &rrd, RRD_READONLY);
115 if (rrd_file == NULL)
118 info.u_str = filename;
119 cd = info_push(NULL, sprintf_alloc("filename"), RD_I_STR, info);
122 info.u_str = rrd.stat_head->version;
123 cd = info_push(cd, sprintf_alloc("rrd_version"), RD_I_STR, info);
125 info.u_cnt = rrd.stat_head->pdp_step;
126 cd = info_push(cd, sprintf_alloc("step"), RD_I_CNT, info);
128 info.u_cnt = rrd.live_head->last_up;
129 cd = info_push(cd, sprintf_alloc("last_update"), RD_I_CNT, info);
131 for (i = 0; i < rrd.stat_head->ds_cnt; i++) {
133 info.u_str = rrd.ds_def[i].dst;
134 cd = info_push(cd, sprintf_alloc("ds[%s].type", rrd.ds_def[i].ds_nam),
137 current_ds = dst_conv(rrd.ds_def[i].dst);
138 switch (current_ds) {
143 rpn_compact2str((rpn_cdefds_t *) &(rrd.ds_def[i].par[DS_cdef]),
144 rrd.ds_def, &buffer);
147 sprintf_alloc("ds[%s].cdef", rrd.ds_def[i].ds_nam),
153 info.u_cnt = rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt;
155 sprintf_alloc("ds[%s].minimal_heartbeat",
156 rrd.ds_def[i].ds_nam), RD_I_CNT,
159 info.u_val = rrd.ds_def[i].par[DS_min_val].u_val;
161 sprintf_alloc("ds[%s].min", rrd.ds_def[i].ds_nam),
164 info.u_val = rrd.ds_def[i].par[DS_max_val].u_val;
166 sprintf_alloc("ds[%s].max", rrd.ds_def[i].ds_nam),
171 info.u_str = rrd.pdp_prep[i].last_ds;
173 sprintf_alloc("ds[%s].last_ds", rrd.ds_def[i].ds_nam),
176 info.u_val = rrd.pdp_prep[i].scratch[PDP_val].u_val;
178 sprintf_alloc("ds[%s].value", rrd.ds_def[i].ds_nam),
181 info.u_cnt = rrd.pdp_prep[i].scratch[PDP_unkn_sec_cnt].u_cnt;
183 sprintf_alloc("ds[%s].unknown_sec",
184 rrd.ds_def[i].ds_nam), RD_I_CNT, info);
187 for (i = 0; i < rrd.stat_head->rra_cnt; i++) {
188 info.u_str = rrd.rra_def[i].cf_nam;
189 cd = info_push(cd, sprintf_alloc("rra[%d].cf", i), RD_I_STR, info);
190 current_cf = cf_conv(rrd.rra_def[i].cf_nam);
192 info.u_cnt = rrd.rra_def[i].row_cnt;
193 cd = info_push(cd, sprintf_alloc("rra[%d].rows", i), RD_I_CNT, info);
195 info.u_cnt = rrd.rra_ptr[i].cur_row;
196 cd = info_push(cd, sprintf_alloc("rra[%d].cur_row", i), RD_I_CNT,
199 info.u_cnt = rrd.rra_def[i].pdp_cnt;
200 cd = info_push(cd, sprintf_alloc("rra[%d].pdp_per_row", i), RD_I_CNT,
203 switch (current_cf) {
206 info.u_val = rrd.rra_def[i].par[RRA_hw_alpha].u_val;
207 cd = info_push(cd, sprintf_alloc("rra[%d].alpha", i), RD_I_VAL,
209 info.u_val = rrd.rra_def[i].par[RRA_hw_beta].u_val;
210 cd = info_push(cd, sprintf_alloc("rra[%d].beta", i), RD_I_VAL,
215 info.u_val = rrd.rra_def[i].par[RRA_seasonal_gamma].u_val;
216 cd = info_push(cd, sprintf_alloc("rra[%d].gamma", i), RD_I_VAL,
218 if (atoi(rrd.stat_head->version) >= 4) {
220 rrd.rra_def[i].par[RRA_seasonal_smoothing_window].u_val;
222 sprintf_alloc("rra[%d].smoothing_window", i),
227 info.u_val = rrd.rra_def[i].par[RRA_delta_pos].u_val;
228 cd = info_push(cd, sprintf_alloc("rra[%d].delta_pos", i),
230 info.u_val = rrd.rra_def[i].par[RRA_delta_neg].u_val;
231 cd = info_push(cd, sprintf_alloc("rra[%d].delta_neg", i),
233 info.u_cnt = rrd.rra_def[i].par[RRA_failure_threshold].u_cnt;
234 cd = info_push(cd, sprintf_alloc("rra[%d].failure_threshold", i),
236 info.u_cnt = rrd.rra_def[i].par[RRA_window_len].u_cnt;
237 cd = info_push(cd, sprintf_alloc("rra[%d].window_length", i),
243 info.u_val = rrd.rra_def[i].par[RRA_cdp_xff_val].u_val;
244 cd = info_push(cd, sprintf_alloc("rra[%d].xff", i), RD_I_VAL,
249 for (ii = 0; ii < rrd.stat_head->ds_cnt; ii++) {
250 switch (current_cf) {
254 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
255 ii].scratch[CDP_hw_intercept].u_val;
257 sprintf_alloc("rra[%d].cdp_prep[%d].intercept",
258 i, ii), RD_I_VAL, info);
260 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
261 ii].scratch[CDP_hw_slope].u_val;
263 sprintf_alloc("rra[%d].cdp_prep[%d].slope", i,
264 ii), RD_I_VAL, info);
266 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
267 ii].scratch[CDP_null_count].u_cnt;
269 sprintf_alloc("rra[%d].cdp_prep[%d].NaN_count",
270 i, ii), RD_I_CNT, info);
274 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
275 ii].scratch[CDP_hw_seasonal].u_val;
277 sprintf_alloc("rra[%d].cdp_prep[%d].seasonal",
278 i, ii), RD_I_VAL, info);
282 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
283 ii].scratch[CDP_seasonal_deviation].u_val;
285 sprintf_alloc("rra[%d].cdp_prep[%d].deviation",
286 i, ii), RD_I_VAL, info);
293 char *violations_array;
294 char history[MAX_FAILURES_WINDOW_LEN + 1];
297 (char *) rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
299 for (j = 0; j < rrd.rra_def[i].par[RRA_window_len].u_cnt; ++j)
300 history[j] = (violations_array[j] == 1) ? '1' : '0';
302 info.u_str = history;
304 sprintf_alloc("rra[%d].cdp_prep[%d].history",
305 i, ii), RD_I_STR, info);
310 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
311 ii].scratch[CDP_val].u_val;
313 sprintf_alloc("rra[%d].cdp_prep[%d].value", i,
314 ii), RD_I_VAL, info);
316 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
317 ii].scratch[CDP_unkn_pdp_cnt].u_cnt;
320 ("rra[%d].cdp_prep[%d].unknown_datapoints", i,
321 ii), RD_I_CNT, info);
338 printf("%s = ", data->key);
340 switch (data->type) {
342 if (isnan(data->value.u_val))
345 printf("%0.10e\n", data->value.u_val);
348 printf("%lu\n", data->value.u_cnt);
351 printf("%d\n", data->value.u_int);
354 printf("\"%s\"\n", data->value.u_str);
357 printf("BLOB_SIZE:%lu\n", data->value.u_blo.size);
358 fwrite(data->value.u_blo.ptr, data->value.u_blo.size, 1, stdout);
373 if (data->type == RD_I_STR) {
374 free(data->value.u_str);
376 if (data->type == RD_I_BLO) {
377 free(data->value.u_blo.ptr);