1 /*****************************************************************************
2 * RRDtool 1.3rc8 Copyright by Tobi Oetiker, 1997-2008
3 *****************************************************************************
4 * rrd_info Get Information about the configuration of an RRD
5 *****************************************************************************/
8 #include "rrd_rpncalc.h"
15 rrd_info_t *rrd_info_r(
18 /* allocate memory for string */
23 int maxlen = 1024 + strlen(fmt);
26 str = malloc(sizeof(char) * (maxlen + 1));
30 vsnprintf(str, maxlen, fmt, argp);
32 vsprintf(str, fmt, argp);
39 /* the function formerly known as push was renamed to info_push and later
40 * rrd_info_push because it is now used outside the scope of this file */
50 next = malloc(sizeof(*next));
51 next->next = (rrd_info_t *) 0;
58 next->value.u_val = value.u_val;
61 next->value.u_cnt = value.u_cnt;
64 next->value.u_int = value.u_int;
67 next->value.u_str = malloc(sizeof(char) * (strlen(value.u_str) + 1));
68 strcpy(next->value.u_str, value.u_str);
71 next->value.u_blo.size = value.u_blo.size;
72 next->value.u_blo.ptr =
73 malloc(sizeof(unsigned char) * value.u_blo.size);
74 memcpy(next->value.u_blo.ptr, value.u_blo.ptr, value.u_blo.size);
88 rrd_set_error("please specify an rrd");
92 info = rrd_info_r(argv[1]);
99 rrd_info_t *rrd_info_r(
102 unsigned int i, ii = 0;
104 rrd_info_t *data = NULL, *cd;
106 rrd_file_t *rrd_file;
107 enum cf_en current_cf;
108 enum dst_en current_ds;
110 rrd_file = rrd_open(filename, &rrd, RRD_READONLY);
111 if (rrd_file == NULL)
114 info.u_str = filename;
115 cd = rrd_info_push(NULL, sprintf_alloc("filename"), RD_I_STR, info);
118 info.u_str = rrd.stat_head->version;
119 cd = rrd_info_push(cd, sprintf_alloc("rrd_version"), RD_I_STR, info);
121 info.u_cnt = rrd.stat_head->pdp_step;
122 cd = rrd_info_push(cd, sprintf_alloc("step"), RD_I_CNT, info);
124 info.u_cnt = rrd.live_head->last_up;
125 cd = rrd_info_push(cd, sprintf_alloc("last_update"), RD_I_CNT, info);
127 for (i = 0; i < rrd.stat_head->ds_cnt; i++) {
129 info.u_str = rrd.ds_def[i].dst;
130 cd = rrd_info_push(cd, sprintf_alloc("ds[%s].type",
131 rrd.ds_def[i].ds_nam),
134 current_ds = dst_conv(rrd.ds_def[i].dst);
135 switch (current_ds) {
140 rpn_compact2str((rpn_cdefds_t *) &(rrd.ds_def[i].par[DS_cdef]),
141 rrd.ds_def, &buffer);
143 cd = rrd_info_push(cd,
144 sprintf_alloc("ds[%s].cdef", rrd.ds_def[i].ds_nam),
150 info.u_cnt = rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt;
151 cd = rrd_info_push(cd,
152 sprintf_alloc("ds[%s].minimal_heartbeat",
153 rrd.ds_def[i].ds_nam), RD_I_CNT,
156 info.u_val = rrd.ds_def[i].par[DS_min_val].u_val;
157 cd = rrd_info_push(cd,
158 sprintf_alloc("ds[%s].min", rrd.ds_def[i].ds_nam),
161 info.u_val = rrd.ds_def[i].par[DS_max_val].u_val;
162 cd = rrd_info_push(cd,
163 sprintf_alloc("ds[%s].max", rrd.ds_def[i].ds_nam),
168 info.u_str = rrd.pdp_prep[i].last_ds;
169 cd = rrd_info_push(cd,
170 sprintf_alloc("ds[%s].last_ds", rrd.ds_def[i].ds_nam),
173 info.u_val = rrd.pdp_prep[i].scratch[PDP_val].u_val;
174 cd = rrd_info_push(cd,
175 sprintf_alloc("ds[%s].value", rrd.ds_def[i].ds_nam),
178 info.u_cnt = rrd.pdp_prep[i].scratch[PDP_unkn_sec_cnt].u_cnt;
179 cd = rrd_info_push(cd,
180 sprintf_alloc("ds[%s].unknown_sec",
181 rrd.ds_def[i].ds_nam), RD_I_CNT, info);
184 for (i = 0; i < rrd.stat_head->rra_cnt; i++) {
185 info.u_str = rrd.rra_def[i].cf_nam;
186 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].cf", i), RD_I_STR, info);
187 current_cf = cf_conv(rrd.rra_def[i].cf_nam);
189 info.u_cnt = rrd.rra_def[i].row_cnt;
190 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].rows", i), RD_I_CNT, info);
192 info.u_cnt = rrd.rra_ptr[i].cur_row;
193 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].cur_row", i), RD_I_CNT,
196 info.u_cnt = rrd.rra_def[i].pdp_cnt;
197 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].pdp_per_row", i), RD_I_CNT,
200 switch (current_cf) {
203 info.u_val = rrd.rra_def[i].par[RRA_hw_alpha].u_val;
204 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].alpha", i), RD_I_VAL,
206 info.u_val = rrd.rra_def[i].par[RRA_hw_beta].u_val;
207 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].beta", i), RD_I_VAL,
212 info.u_val = rrd.rra_def[i].par[RRA_seasonal_gamma].u_val;
213 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].gamma", i), RD_I_VAL,
215 if (atoi(rrd.stat_head->version) >= 4) {
217 rrd.rra_def[i].par[RRA_seasonal_smoothing_window].u_val;
218 cd = rrd_info_push(cd,
219 sprintf_alloc("rra[%d].smoothing_window", i),
224 info.u_val = rrd.rra_def[i].par[RRA_delta_pos].u_val;
225 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].delta_pos", i),
227 info.u_val = rrd.rra_def[i].par[RRA_delta_neg].u_val;
228 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].delta_neg", i),
230 info.u_cnt = rrd.rra_def[i].par[RRA_failure_threshold].u_cnt;
231 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].failure_threshold", i),
233 info.u_cnt = rrd.rra_def[i].par[RRA_window_len].u_cnt;
234 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].window_length", i),
240 info.u_val = rrd.rra_def[i].par[RRA_cdp_xff_val].u_val;
241 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].xff", i), RD_I_VAL,
246 for (ii = 0; ii < rrd.stat_head->ds_cnt; ii++) {
247 switch (current_cf) {
251 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
252 ii].scratch[CDP_hw_intercept].u_val;
253 cd = rrd_info_push(cd,
254 sprintf_alloc("rra[%d].cdp_prep[%d].intercept",
255 i, ii), RD_I_VAL, info);
257 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
258 ii].scratch[CDP_hw_slope].u_val;
259 cd = rrd_info_push(cd,
260 sprintf_alloc("rra[%d].cdp_prep[%d].slope", i,
261 ii), RD_I_VAL, info);
263 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
264 ii].scratch[CDP_null_count].u_cnt;
265 cd = rrd_info_push(cd,
266 sprintf_alloc("rra[%d].cdp_prep[%d].NaN_count",
267 i, ii), RD_I_CNT, info);
271 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
272 ii].scratch[CDP_hw_seasonal].u_val;
273 cd = rrd_info_push(cd,
274 sprintf_alloc("rra[%d].cdp_prep[%d].seasonal",
275 i, ii), RD_I_VAL, info);
279 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
280 ii].scratch[CDP_seasonal_deviation].u_val;
281 cd = rrd_info_push(cd,
282 sprintf_alloc("rra[%d].cdp_prep[%d].deviation",
283 i, ii), RD_I_VAL, info);
290 char *violations_array;
291 char history[MAX_FAILURES_WINDOW_LEN + 1];
294 (char *) rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
296 for (j = 0; j < rrd.rra_def[i].par[RRA_window_len].u_cnt; ++j)
297 history[j] = (violations_array[j] == 1) ? '1' : '0';
299 info.u_str = history;
300 cd = rrd_info_push(cd,
301 sprintf_alloc("rra[%d].cdp_prep[%d].history",
302 i, ii), RD_I_STR, info);
307 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
308 ii].scratch[CDP_val].u_val;
309 cd = rrd_info_push(cd,
310 sprintf_alloc("rra[%d].cdp_prep[%d].value", i,
311 ii), RD_I_VAL, info);
313 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
314 ii].scratch[CDP_unkn_pdp_cnt].u_cnt;
315 cd = rrd_info_push(cd,
317 ("rra[%d].cdp_prep[%d].unknown_datapoints", i,
318 ii), RD_I_CNT, info);
335 printf("%s = ", data->key);
337 switch (data->type) {
339 if (isnan(data->value.u_val))
342 printf("%0.10e\n", data->value.u_val);
345 printf("%lu\n", data->value.u_cnt);
348 printf("%d\n", data->value.u_int);
351 printf("\"%s\"\n", data->value.u_str);
354 printf("BLOB_SIZE:%lu\n", data->value.u_blo.size);
355 fwrite(data->value.u_blo.ptr, data->value.u_blo.size, 1, stdout);
370 if (data->type == RD_I_STR) {
371 free(data->value.u_str);
373 if (data->type == RD_I_BLO) {
374 free(data->value.u_blo.ptr);