1 /*****************************************************************************
2 * RRDtool 1.2.99907080300 Copyright by Tobi Oetiker, 1997-2007
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);
86 rrd_set_error("please specify an rrd");
90 info = rrd_info_r(argv[1]);
100 unsigned int i, ii = 0;
102 info_t *data = NULL, *cd;
104 rrd_file_t *rrd_file;
105 enum cf_en current_cf;
106 enum dst_en current_ds;
108 rrd_file = rrd_open(filename, &rrd, RRD_READONLY);
109 if (rrd_file == NULL)
112 info.u_str = filename;
113 cd = info_push(NULL, sprintf_alloc("filename"), RD_I_STR, info);
116 info.u_str = rrd.stat_head->version;
117 cd = info_push(cd, sprintf_alloc("rrd_version"), RD_I_STR, info);
119 info.u_cnt = rrd.stat_head->pdp_step;
120 cd = info_push(cd, sprintf_alloc("step"), RD_I_CNT, info);
122 info.u_cnt = rrd.live_head->last_up;
123 cd = info_push(cd, sprintf_alloc("last_update"), RD_I_CNT, info);
125 for (i = 0; i < rrd.stat_head->ds_cnt; i++) {
127 info.u_str = rrd.ds_def[i].dst;
128 cd = info_push(cd, sprintf_alloc("ds[%s].type", rrd.ds_def[i].ds_nam),
131 current_ds = dst_conv(rrd.ds_def[i].dst);
132 switch (current_ds) {
137 rpn_compact2str((rpn_cdefds_t *) &(rrd.ds_def[i].par[DS_cdef]),
138 rrd.ds_def, &buffer);
141 sprintf_alloc("ds[%s].cdef", rrd.ds_def[i].ds_nam),
147 info.u_cnt = rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt;
149 sprintf_alloc("ds[%s].minimal_heartbeat",
150 rrd.ds_def[i].ds_nam), RD_I_CNT,
153 info.u_val = rrd.ds_def[i].par[DS_min_val].u_val;
155 sprintf_alloc("ds[%s].min", rrd.ds_def[i].ds_nam),
158 info.u_val = rrd.ds_def[i].par[DS_max_val].u_val;
160 sprintf_alloc("ds[%s].max", rrd.ds_def[i].ds_nam),
165 info.u_str = rrd.pdp_prep[i].last_ds;
167 sprintf_alloc("ds[%s].last_ds", rrd.ds_def[i].ds_nam),
170 info.u_val = rrd.pdp_prep[i].scratch[PDP_val].u_val;
172 sprintf_alloc("ds[%s].value", rrd.ds_def[i].ds_nam),
175 info.u_cnt = rrd.pdp_prep[i].scratch[PDP_unkn_sec_cnt].u_cnt;
177 sprintf_alloc("ds[%s].unknown_sec",
178 rrd.ds_def[i].ds_nam), RD_I_CNT, info);
181 for (i = 0; i < rrd.stat_head->rra_cnt; i++) {
182 info.u_str = rrd.rra_def[i].cf_nam;
183 cd = info_push(cd, sprintf_alloc("rra[%d].cf", i), RD_I_STR, info);
184 current_cf = cf_conv(rrd.rra_def[i].cf_nam);
186 info.u_cnt = rrd.rra_def[i].row_cnt;
187 cd = info_push(cd, sprintf_alloc("rra[%d].rows", i), RD_I_CNT, info);
189 info.u_cnt = rrd.rra_def[i].pdp_cnt;
190 cd = info_push(cd, sprintf_alloc("rra[%d].pdp_per_row", i), RD_I_CNT,
193 switch (current_cf) {
196 info.u_val = rrd.rra_def[i].par[RRA_hw_alpha].u_val;
197 cd = info_push(cd, sprintf_alloc("rra[%d].alpha", i), RD_I_VAL,
199 info.u_val = rrd.rra_def[i].par[RRA_hw_beta].u_val;
200 cd = info_push(cd, sprintf_alloc("rra[%d].beta", i), RD_I_VAL,
205 info.u_val = rrd.rra_def[i].par[RRA_seasonal_gamma].u_val;
206 cd = info_push(cd, sprintf_alloc("rra[%d].gamma", i), RD_I_VAL,
208 if (atoi(rrd.stat_head->version) >= 4) {
210 rrd.rra_def[i].par[RRA_seasonal_smoothing_window].u_val;
212 sprintf_alloc("rra[%d].smoothing_window", i),
217 info.u_val = rrd.rra_def[i].par[RRA_delta_pos].u_val;
218 cd = info_push(cd, sprintf_alloc("rra[%d].delta_pos", i),
220 info.u_val = rrd.rra_def[i].par[RRA_delta_neg].u_val;
221 cd = info_push(cd, sprintf_alloc("rra[%d].delta_neg", i),
223 info.u_cnt = rrd.rra_def[i].par[RRA_failure_threshold].u_cnt;
224 cd = info_push(cd, sprintf_alloc("rra[%d].failure_threshold", i),
226 info.u_cnt = rrd.rra_def[i].par[RRA_window_len].u_cnt;
227 cd = info_push(cd, sprintf_alloc("rra[%d].window_length", i),
233 info.u_val = rrd.rra_def[i].par[RRA_cdp_xff_val].u_val;
234 cd = info_push(cd, sprintf_alloc("rra[%d].xff", i), RD_I_VAL,
239 for (ii = 0; ii < rrd.stat_head->ds_cnt; ii++) {
240 switch (current_cf) {
244 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
245 ii].scratch[CDP_hw_intercept].u_val;
247 sprintf_alloc("rra[%d].cdp_prep[%d].intercept",
248 i, ii), RD_I_VAL, info);
250 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
251 ii].scratch[CDP_hw_slope].u_val;
253 sprintf_alloc("rra[%d].cdp_prep[%d].slope", i,
254 ii), RD_I_VAL, info);
256 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
257 ii].scratch[CDP_null_count].u_cnt;
259 sprintf_alloc("rra[%d].cdp_prep[%d].NaN_count",
260 i, ii), RD_I_CNT, info);
264 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
265 ii].scratch[CDP_hw_seasonal].u_val;
267 sprintf_alloc("rra[%d].cdp_prep[%d].seasonal",
268 i, ii), RD_I_VAL, info);
272 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
273 ii].scratch[CDP_seasonal_deviation].u_val;
275 sprintf_alloc("rra[%d].cdp_prep[%d].deviation",
276 i, ii), RD_I_VAL, info);
283 char *violations_array;
284 char history[MAX_FAILURES_WINDOW_LEN + 1];
287 (char *) rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
289 for (j = 0; j < rrd.rra_def[i].par[RRA_window_len].u_cnt; ++j)
290 history[j] = (violations_array[j] == 1) ? '1' : '0';
292 info.u_str = history;
294 sprintf_alloc("rra[%d].cdp_prep[%d].history",
295 i, ii), RD_I_STR, info);
300 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
301 ii].scratch[CDP_val].u_val;
303 sprintf_alloc("rra[%d].cdp_prep[%d].value", i,
304 ii), RD_I_VAL, info);
306 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
307 ii].scratch[CDP_unkn_pdp_cnt].u_cnt;
310 ("rra[%d].cdp_prep[%d].unknown_datapoints", i,
311 ii), RD_I_CNT, info);