1 /*****************************************************************************
2 * RRDtool 1.3.2 Copyright by Tobi Oetiker, 1997-2008
3 *****************************************************************************
4 * change header parameters of an rrd
5 *****************************************************************************
8 * Revision 1.6 2004/05/26 22:11:12 oetiker
9 * reduce compiler warnings. Many small fixes. -- Mike Slifcak <slif@bellsouth.net>
11 * Revision 1.5 2002/02/01 20:34:49 oetiker
12 * fixed version number and date/time
14 * Revision 1.4 2001/08/22 22:29:07 jake
15 * Contents of this patch:
16 * (1) Adds/revises documentation for rrd tune in rrd_tool.c and pod files.
17 * (2) Moves some initialization code from rrd_create.c to rrd_hw.c.
18 * (3) Adds another pass to smoothing for SEASONAL and DEVSEASONAL RRAs.
19 * This pass computes the coefficients as deviations from an average; the
20 * average is added the baseline coefficient of HWPREDICT. Statistical texts
21 * suggest this to preserve algorithm stability. It will not invalidate
22 * RRD files created and smoothed with the old code.
23 * (4) Adds the aberrant-reset flag to rrd tune. This operation, which is
24 * specified for a single data source, causes the holt-winters algorithm to
25 * forget everthing it has learned and start over.
26 * (5) Fixes a few out-of-date code comments.
28 * Revision 1.3 2001/03/07 21:21:54 oetiker
29 * complete rewrite of rrdgraph documentation. This also includs info
30 * on upcomming/planned changes to the rrdgraph interface and functionality
31 * -- Alex van den Bogaerdt <alex@slot.hollandcasino.nl>
33 * Revision 1.2 2001/03/04 13:01:55 oetiker
34 * Aberrant Behavior Detection support. A brief overview added to rrdtool.pod.
35 * Major updates to rrd_update.c, rrd_create.c. Minor update to other core files.
36 * This is backwards compatible! But new files using the Aberrant stuff are not readable
37 * by old rrdtool versions. See http://cricket.sourceforge.net/aberrant/rrd_hw.htm
38 * -- Jake Brutlag <jakeb@corp.webtv.net>
40 *****************************************************************************/
43 #include "rrd_rpncalc.h"
50 enum rra_par_en rra_par,
54 enum rra_par_en rra_par,
69 char ds_nam[DS_NAM_SIZE];
70 char ds_new[DS_NAM_SIZE];
76 struct option long_options[] = {
77 {"heartbeat", required_argument, 0, 'h'},
78 {"minimum", required_argument, 0, 'i'},
79 {"maximum", required_argument, 0, 'a'},
80 {"data-source-type", required_argument, 0, 'd'},
81 {"data-source-rename", required_argument, 0, 'r'},
82 /* added parameter tuning options for aberrant behavior detection */
83 {"deltapos", required_argument, 0, 'p'},
84 {"deltaneg", required_argument, 0, 'n'},
85 {"window-length", required_argument, 0, 'w'},
86 {"failure-threshold", required_argument, 0, 'f'},
87 {"alpha", required_argument, 0, 'x'},
88 {"beta", required_argument, 0, 'y'},
89 {"gamma", required_argument, 0, 'z'},
90 {"gamma-deviation", required_argument, 0, 'v'},
91 {"smoothing-window", required_argument, 0, 's'},
92 {"smoothing-window-deviation", required_argument, 0, 'S'},
93 {"aberrant-reset", required_argument, 0, 'b'},
98 opterr = 0; /* initialize getopt */
102 rrd_file = rrd_open(argv[1], &rrd, RRD_READWRITE);
103 if (rrd_file == NULL) {
109 int option_index = 0;
111 char *old_locale = "";
113 opt = getopt_long(argc, argv, "h:i:a:d:r:p:n:w:f:x:y:z:v:b:",
114 long_options, &option_index);
121 old_locale = setlocale(LC_NUMERIC, "C");
123 sscanf(optarg, DS_NAM_FMT ":%ld", ds_nam,
125 rrd_set_error("invalid arguments for heartbeat");
128 setlocale(LC_NUMERIC, old_locale);
131 setlocale(LC_NUMERIC, old_locale);
132 if ((ds = ds_match(&rrd, ds_nam)) == -1) {
137 rrd.ds_def[ds].par[DS_mrhb_cnt].u_cnt = heartbeat;
141 old_locale = setlocale(LC_NUMERIC, "C");
143 sscanf(optarg, DS_NAM_FMT ":%lf", ds_nam, &min)) < 1) {
144 rrd_set_error("invalid arguments for minimum ds value");
147 setlocale(LC_NUMERIC, old_locale);
150 setlocale(LC_NUMERIC, old_locale);
151 if ((ds = ds_match(&rrd, ds_nam)) == -1) {
159 rrd.ds_def[ds].par[DS_min_val].u_val = min;
163 old_locale = setlocale(LC_NUMERIC, "C");
165 sscanf(optarg, DS_NAM_FMT ":%lf", ds_nam, &max)) < 1) {
166 rrd_set_error("invalid arguments for maximum ds value");
169 setlocale(LC_NUMERIC, old_locale);
172 setlocale(LC_NUMERIC, old_locale);
173 if ((ds = ds_match(&rrd, ds_nam)) == -1) {
180 rrd.ds_def[ds].par[DS_max_val].u_val = max;
185 sscanf(optarg, DS_NAM_FMT ":" DST_FMT, ds_nam, dst)) != 2) {
186 rrd_set_error("invalid arguments for data source type");
191 if ((ds = ds_match(&rrd, ds_nam)) == -1) {
196 if ((int) dst_conv(dst) == -1) {
201 /* only reset when something is changed */
202 if (strncmp(rrd.ds_def[ds].dst, dst, DST_SIZE - 1) != 0) {
203 strncpy(rrd.ds_def[ds].dst, dst, DST_SIZE - 1);
204 rrd.ds_def[ds].dst[DST_SIZE - 1] = '\0';
206 rrd.pdp_prep[ds].last_ds[0] = 'U';
207 rrd.pdp_prep[ds].last_ds[1] = 'N';
208 rrd.pdp_prep[ds].last_ds[2] = 'K';
209 rrd.pdp_prep[ds].last_ds[3] = 'N';
210 rrd.pdp_prep[ds].last_ds[4] = '\0';
215 sscanf(optarg, DS_NAM_FMT ":" DS_NAM_FMT, ds_nam,
217 rrd_set_error("invalid arguments for data source type");
222 if ((ds = ds_match(&rrd, ds_nam)) == -1) {
227 strncpy(rrd.ds_def[ds].ds_nam, ds_new, DS_NAM_SIZE - 1);
228 rrd.ds_def[ds].ds_nam[DS_NAM_SIZE - 1] = '\0';
231 if (set_deltaarg(&rrd, RRA_delta_pos, optarg)) {
237 if (set_deltaarg(&rrd, RRA_delta_neg, optarg)) {
243 if (set_windowarg(&rrd, RRA_failure_threshold, optarg)) {
249 if (set_windowarg(&rrd, RRA_window_len, optarg)) {
255 if (set_hwarg(&rrd, CF_HWPREDICT, RRA_hw_alpha, optarg)) {
256 if (set_hwarg(&rrd, CF_MHWPREDICT, RRA_hw_alpha, optarg)) {
264 if (set_hwarg(&rrd, CF_HWPREDICT, RRA_hw_beta, optarg)) {
265 if (set_hwarg(&rrd, CF_MHWPREDICT, RRA_hw_beta, optarg)) {
273 if (set_hwarg(&rrd, CF_SEASONAL, RRA_seasonal_gamma, optarg)) {
279 if (set_hwarg(&rrd, CF_DEVSEASONAL, RRA_seasonal_gamma, optarg)) {
285 if (sscanf(optarg, DS_NAM_FMT, ds_nam) != 1) {
286 rrd_set_error("invalid argument for aberrant-reset");
291 if ((ds = ds_match(&rrd, ds_nam)) == -1) {
292 /* ds_match handles it own errors */
297 reset_aberrant_coefficients(&rrd, rrd_file, (unsigned long) ds);
298 if (rrd_test_error()) {
305 strcpy(rrd.stat_head->version, RRD_VERSION); /* smoothing_window causes Version 4 */
307 (&rrd, CF_SEASONAL, RRA_seasonal_smoothing_window, optarg)) {
313 strcpy(rrd.stat_head->version, RRD_VERSION); /* smoothing_window causes Version 4 */
315 (&rrd, CF_DEVSEASONAL, RRA_seasonal_smoothing_window,
323 rrd_set_error("unknown option '%c'", optopt);
325 rrd_set_error("unknown option '%s'", argv[optind - 1]);
332 rrd_seek(rrd_file, 0, SEEK_SET);
333 rrd_write(rrd_file, rrd.stat_head, sizeof(stat_head_t) * 1);
334 rrd_write(rrd_file, rrd.ds_def,
335 sizeof(ds_def_t) * rrd.stat_head->ds_cnt);
336 /* need to write rra_defs for RRA parameter changes */
337 rrd_write(rrd_file, rrd.rra_def,
338 sizeof(rra_def_t) * rrd.stat_head->rra_cnt);
342 for (i = 0; i < (int) rrd.stat_head->ds_cnt; i++)
343 if (dst_conv(rrd.ds_def[i].dst) != DST_CDEF) {
344 printf("DS[%s] typ: %s\thbt: %ld\tmin: %1.4f\tmax: %1.4f\n",
345 rrd.ds_def[i].ds_nam,
347 rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt,
348 rrd.ds_def[i].par[DS_min_val].u_val,
349 rrd.ds_def[i].par[DS_max_val].u_val);
353 rpn_compact2str((rpn_cdefds_t *) &
354 (rrd.ds_def[i].par[DS_cdef]), rrd.ds_def,
356 printf("DS[%s] typ: %s\tcdef: %s\n", rrd.ds_def[i].ds_nam,
357 rrd.ds_def[i].dst, buffer);
369 enum rra_par_en rra_par,
374 signed short rra_idx = -1;
378 if (param <= 0.0 || param >= 1.0) {
379 rrd_set_error("Holt-Winters parameter must be between 0 and 1");
382 /* does the appropriate RRA exist? */
383 for (i = 0; i < rrd->stat_head->rra_cnt; ++i) {
384 if (cf_conv(rrd->rra_def[i].cf_nam) == cf) {
390 rrd_set_error("Holt-Winters RRA does not exist in this RRD");
395 rrd->rra_def[rra_idx].par[rra_par].u_val = param;
401 enum rra_par_en rra_par,
406 signed short rra_idx = -1;
410 rrd_set_error("Parameter specified is too small");
413 /* does the appropriate RRA exist? */
414 for (i = 0; i < rrd->stat_head->rra_cnt; ++i) {
415 if (cf_conv(rrd->rra_def[i].cf_nam) == CF_FAILURES) {
421 rrd_set_error("Failures RRA does not exist in this RRD");
426 rrd->rra_def[rra_idx].par[rra_par].u_val = param;
432 enum rra_par_en rra_par,
436 unsigned long i, cdp_idx;
437 signed short rra_idx = -1;
441 if (param < 1 || param > MAX_FAILURES_WINDOW_LEN) {
442 rrd_set_error("Parameter must be between %d and %d",
443 1, MAX_FAILURES_WINDOW_LEN);
446 /* does the appropriate RRA exist? */
447 for (i = 0; i < rrd->stat_head->rra_cnt; ++i) {
448 if (cf_conv(rrd->rra_def[i].cf_nam) == CF_FAILURES) {
454 rrd_set_error("Failures RRA does not exist in this RRD");
459 rrd->rra_def[rra_idx].par[rra_par].u_cnt = param;
461 /* erase existing violations */
462 for (i = 0; i < rrd->stat_head->ds_cnt; i++) {
463 cdp_idx = rra_idx * (rrd->stat_head->ds_cnt) + i;
464 erase_violations(rrd, cdp_idx, rra_idx);