1 /*****************************************************************************
2 * RRDtool 1.3.1 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 */
42 * rrd_info_push(rrd_info_t * info,
43 char *key, rrd_info_type_t type, rrd_infoval_t value)
47 next = malloc(sizeof(*next));
48 next->next = (rrd_info_t *) 0;
55 next->value.u_val = value.u_val;
58 next->value.u_cnt = value.u_cnt;
61 next->value.u_int = value.u_int;
64 next->value.u_str = malloc(sizeof(char) * (strlen(value.u_str) + 1));
65 strcpy(next->value.u_str, value.u_str);
68 next->value.u_blo.size = value.u_blo.size;
69 next->value.u_blo.ptr =
70 malloc(sizeof(unsigned char) * value.u_blo.size);
71 memcpy(next->value.u_blo.ptr, value.u_blo.ptr, value.u_blo.size);
85 rrd_set_error("please specify an rrd");
89 info = rrd_info_r(argv[1]);
96 rrd_info_t *rrd_info_r(
99 unsigned int i, ii = 0;
101 rrd_info_t *data = NULL, *cd;
103 rrd_file_t *rrd_file;
104 enum cf_en current_cf;
105 enum dst_en current_ds;
107 rrd_file = rrd_open(filename, &rrd, RRD_READONLY);
108 if (rrd_file == NULL)
111 info.u_str = filename;
112 cd = rrd_info_push(NULL, sprintf_alloc("filename"), RD_I_STR, info);
115 info.u_str = rrd.stat_head->version;
116 cd = rrd_info_push(cd, sprintf_alloc("rrd_version"), RD_I_STR, info);
118 info.u_cnt = rrd.stat_head->pdp_step;
119 cd = rrd_info_push(cd, sprintf_alloc("step"), RD_I_CNT, info);
121 info.u_cnt = rrd.live_head->last_up;
122 cd = rrd_info_push(cd, sprintf_alloc("last_update"), RD_I_CNT, info);
124 for (i = 0; i < rrd.stat_head->ds_cnt; i++) {
126 info.u_str = rrd.ds_def[i].dst;
127 cd = rrd_info_push(cd, sprintf_alloc("ds[%s].type",
128 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);
140 cd = rrd_info_push(cd,
141 sprintf_alloc("ds[%s].cdef",
142 rrd.ds_def[i].ds_nam), RD_I_STR,
148 info.u_cnt = rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt;
149 cd = rrd_info_push(cd,
150 sprintf_alloc("ds[%s].minimal_heartbeat",
151 rrd.ds_def[i].ds_nam), RD_I_CNT,
154 info.u_val = rrd.ds_def[i].par[DS_min_val].u_val;
155 cd = rrd_info_push(cd,
156 sprintf_alloc("ds[%s].min",
157 rrd.ds_def[i].ds_nam), RD_I_VAL,
160 info.u_val = rrd.ds_def[i].par[DS_max_val].u_val;
161 cd = rrd_info_push(cd,
162 sprintf_alloc("ds[%s].max",
163 rrd.ds_def[i].ds_nam), RD_I_VAL,
168 info.u_str = rrd.pdp_prep[i].last_ds;
169 cd = rrd_info_push(cd,
170 sprintf_alloc("ds[%s].last_ds",
171 rrd.ds_def[i].ds_nam), RD_I_STR,
174 info.u_val = rrd.pdp_prep[i].scratch[PDP_val].u_val;
175 cd = rrd_info_push(cd,
176 sprintf_alloc("ds[%s].value",
177 rrd.ds_def[i].ds_nam), RD_I_VAL,
180 info.u_cnt = rrd.pdp_prep[i].scratch[PDP_unkn_sec_cnt].u_cnt;
181 cd = rrd_info_push(cd,
182 sprintf_alloc("ds[%s].unknown_sec",
183 rrd.ds_def[i].ds_nam), RD_I_CNT,
187 for (i = 0; i < rrd.stat_head->rra_cnt; i++) {
188 info.u_str = rrd.rra_def[i].cf_nam;
189 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].cf", i), RD_I_STR,
191 current_cf = cf_conv(rrd.rra_def[i].cf_nam);
193 info.u_cnt = rrd.rra_def[i].row_cnt;
194 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].rows", i), RD_I_CNT,
197 info.u_cnt = rrd.rra_ptr[i].cur_row;
198 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].cur_row", i), RD_I_CNT,
201 info.u_cnt = rrd.rra_def[i].pdp_cnt;
202 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].pdp_per_row", i),
205 switch (current_cf) {
208 info.u_val = rrd.rra_def[i].par[RRA_hw_alpha].u_val;
209 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].alpha", i),
211 info.u_val = rrd.rra_def[i].par[RRA_hw_beta].u_val;
212 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].beta", i), RD_I_VAL,
217 info.u_val = rrd.rra_def[i].par[RRA_seasonal_gamma].u_val;
218 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].gamma", i),
220 if (atoi(rrd.stat_head->version) >= 4) {
222 rrd.rra_def[i].par[RRA_seasonal_smoothing_window].u_val;
223 cd = rrd_info_push(cd,
224 sprintf_alloc("rra[%d].smoothing_window",
229 info.u_val = rrd.rra_def[i].par[RRA_delta_pos].u_val;
230 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].delta_pos", i),
232 info.u_val = rrd.rra_def[i].par[RRA_delta_neg].u_val;
233 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].delta_neg", i),
235 info.u_cnt = rrd.rra_def[i].par[RRA_failure_threshold].u_cnt;
236 cd = rrd_info_push(cd,
237 sprintf_alloc("rra[%d].failure_threshold", i),
239 info.u_cnt = rrd.rra_def[i].par[RRA_window_len].u_cnt;
240 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].window_length", i),
246 info.u_val = rrd.rra_def[i].par[RRA_cdp_xff_val].u_val;
247 cd = rrd_info_push(cd, sprintf_alloc("rra[%d].xff", i), RD_I_VAL,
252 for (ii = 0; ii < rrd.stat_head->ds_cnt; ii++) {
253 switch (current_cf) {
257 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
258 ii].scratch[CDP_hw_intercept].u_val;
259 cd = rrd_info_push(cd,
261 ("rra[%d].cdp_prep[%d].intercept", i, ii),
264 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
265 ii].scratch[CDP_hw_slope].u_val;
266 cd = rrd_info_push(cd,
267 sprintf_alloc("rra[%d].cdp_prep[%d].slope",
268 i, ii), RD_I_VAL, info);
270 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
271 ii].scratch[CDP_null_count].u_cnt;
272 cd = rrd_info_push(cd,
274 ("rra[%d].cdp_prep[%d].NaN_count", i, ii),
279 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
280 ii].scratch[CDP_hw_seasonal].u_val;
281 cd = rrd_info_push(cd,
283 ("rra[%d].cdp_prep[%d].seasonal", i, ii),
288 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
289 ii].scratch[CDP_seasonal_deviation].u_val;
290 cd = rrd_info_push(cd,
292 ("rra[%d].cdp_prep[%d].deviation", i, ii),
300 char *violations_array;
301 char history[MAX_FAILURES_WINDOW_LEN + 1];
304 (char *) rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
306 for (j = 0; j < rrd.rra_def[i].par[RRA_window_len].u_cnt; ++j)
307 history[j] = (violations_array[j] == 1) ? '1' : '0';
309 info.u_str = history;
310 cd = rrd_info_push(cd,
312 ("rra[%d].cdp_prep[%d].history", i, ii),
318 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
319 ii].scratch[CDP_val].u_val;
320 cd = rrd_info_push(cd,
321 sprintf_alloc("rra[%d].cdp_prep[%d].value",
322 i, ii), RD_I_VAL, info);
324 rrd.cdp_prep[i * rrd.stat_head->ds_cnt +
325 ii].scratch[CDP_unkn_pdp_cnt].u_cnt;
326 cd = rrd_info_push(cd,
328 ("rra[%d].cdp_prep[%d].unknown_datapoints",
329 i, ii), RD_I_CNT, info);
346 printf("%s = ", data->key);
348 switch (data->type) {
350 if (isnan(data->value.u_val))
353 printf("%0.10e\n", data->value.u_val);
356 printf("%lu\n", data->value.u_cnt);
359 printf("%d\n", data->value.u_int);
362 printf("\"%s\"\n", data->value.u_str);
365 printf("BLOB_SIZE:%lu\n", data->value.u_blo.size);
366 fwrite(data->value.u_blo.ptr, data->value.u_blo.size, 1, stdout);
381 if (data->type == RD_I_STR) {
382 free(data->value.u_str);
384 if (data->type == RD_I_BLO) {
385 free(data->value.u_blo.ptr);