1 /*****************************************************************************
2 * RRDtool 1.1.x Copyright Tobias Oetiker, 1997 - 2002
3 *****************************************************************************
4 * change header parameters of an rrd
5 *****************************************************************************
8 * Revision 1.5 2002/02/01 20:34:49 oetiker
9 * fixed version number and date/time
11 * Revision 1.4 2001/08/22 22:29:07 jake
12 * Contents of this patch:
13 * (1) Adds/revises documentation for rrd tune in rrd_tool.c and pod files.
14 * (2) Moves some initialization code from rrd_create.c to rrd_hw.c.
15 * (3) Adds another pass to smoothing for SEASONAL and DEVSEASONAL RRAs.
16 * This pass computes the coefficients as deviations from an average; the
17 * average is added the baseline coefficient of HWPREDICT. Statistical texts
18 * suggest this to preserve algorithm stability. It will not invalidate
19 * RRD files created and smoothed with the old code.
20 * (4) Adds the aberrant-reset flag to rrd tune. This operation, which is
21 * specified for a single data source, causes the holt-winters algorithm to
22 * forget everthing it has learned and start over.
23 * (5) Fixes a few out-of-date code comments.
25 * Revision 1.3 2001/03/07 21:21:54 oetiker
26 * complete rewrite of rrdgraph documentation. This also includs info
27 * on upcomming/planned changes to the rrdgraph interface and functionality
28 * -- Alex van den Bogaerdt <alex@slot.hollandcasino.nl>
30 * Revision 1.2 2001/03/04 13:01:55 oetiker
31 * Aberrant Behavior Detection support. A brief overview added to rrdtool.pod.
32 * Major updates to rrd_update.c, rrd_create.c. Minor update to other core files.
33 * This is backwards compatible! But new files using the Aberrant stuff are not readable
34 * by old rrdtool versions. See http://cricket.sourceforge.net/aberrant/rrd_hw.htm
35 * -- Jake Brutlag <jakeb@corp.webtv.net>
37 *****************************************************************************/
40 #include "rrd_rpncalc.h"
43 int set_hwarg(rrd_t *rrd,enum cf_en cf,enum rra_par_en rra_par,char *arg);
44 int set_deltaarg(rrd_t *rrd,enum rra_par_en rra_par,char *arg);
45 int set_windowarg(rrd_t *rrd,enum rra_par_en,char *arg);
48 rrd_tune(int argc, char **argv)
55 char ds_nam[DS_NAM_SIZE];
56 char ds_new[DS_NAM_SIZE];
63 if(rrd_open(argv[1],&rrd_file,&rrd, RRD_READWRITE)==-1){
69 static struct option long_options[] =
71 {"heartbeat", required_argument, 0, 'h'},
72 {"minimum", required_argument, 0, 'i'},
73 {"maximum", required_argument, 0, 'a'},
74 {"data-source-type", required_argument, 0, 'd'},
75 {"data-source-rename", required_argument, 0, 'r'},
76 /* added parameter tuning options for aberrant behavior detection */
77 {"deltapos",required_argument,0,'p'},
78 {"deltaneg",required_argument,0,'n'},
79 {"window-length",required_argument,0,'w'},
80 {"failure-threshold",required_argument,0,'f'},
81 {"alpha",required_argument,0,'x'},
82 {"beta",required_argument,0,'y'},
83 {"gamma",required_argument,0,'z'},
84 {"gamma-deviation",required_argument,0,'v'},
85 {"aberrant-reset",required_argument,0,'b'},
90 opt = getopt_long(argc, argv, "h:i:a:d:r:p:n:w:f:x:y:z:v:b:",
91 long_options, &option_index);
98 if ((matches = sscanf(optarg, DS_NAM_FMT ":%ld",ds_nam,&heartbeat)) != 2){
99 rrd_set_error("invalid arguments for heartbeat");
104 if ((ds=ds_match(&rrd,ds_nam))==-1){
109 rrd.ds_def[ds].par[DS_mrhb_cnt].u_cnt = heartbeat;
113 if ((matches = sscanf(optarg,DS_NAM_FMT ":%lf",ds_nam,&min)) <1){
114 rrd_set_error("invalid arguments for minimum ds value");
119 if ((ds=ds_match(&rrd,ds_nam))==-1){
127 rrd.ds_def[ds].par[DS_min_val].u_val = min;
131 if ((matches = sscanf(optarg, DS_NAM_FMT ":%lf",ds_nam,&max)) <1){
132 rrd_set_error("invalid arguments for maximum ds value");
137 if ((ds=ds_match(&rrd,ds_nam))==-1){
144 rrd.ds_def[ds].par[DS_max_val].u_val = max;
148 if ((matches = sscanf(optarg, DS_NAM_FMT ":" DST_FMT ,ds_nam,dst)) != 2){
149 rrd_set_error("invalid arguments for data source type");
154 if ((ds=ds_match(&rrd,ds_nam))==-1){
159 if (dst_conv(dst) == -1){
164 strncpy(rrd.ds_def[ds].dst,dst,DST_SIZE-1);
165 rrd.ds_def[ds].dst[DST_SIZE-1]='\0';
167 rrd.pdp_prep[ds].last_ds[0] = 'U';
168 rrd.pdp_prep[ds].last_ds[1] = 'N';
169 rrd.pdp_prep[ds].last_ds[2] = 'K';
170 rrd.pdp_prep[ds].last_ds[3] = 'N';
171 rrd.pdp_prep[ds].last_ds[4] = '\0';
176 sscanf(optarg,DS_NAM_FMT ":" DS_NAM_FMT , ds_nam,ds_new)) != 2){
177 rrd_set_error("invalid arguments for data source type");
182 if ((ds=ds_match(&rrd,ds_nam))==-1){
187 strncpy(rrd.ds_def[ds].ds_nam,ds_new,DS_NAM_SIZE-1);
188 rrd.ds_def[ds].ds_nam[DS_NAM_SIZE-1]='\0';
191 if (set_deltaarg(&rrd,RRA_delta_pos,optarg)) {
197 if (set_deltaarg(&rrd,RRA_delta_neg,optarg)) {
203 if (set_windowarg(&rrd,RRA_failure_threshold,optarg)) {
209 if (set_windowarg(&rrd,RRA_window_len,optarg)) {
215 if (set_hwarg(&rrd,CF_HWPREDICT,RRA_hw_alpha,optarg)) {
221 if (set_hwarg(&rrd,CF_HWPREDICT,RRA_hw_beta,optarg)) {
227 if (set_hwarg(&rrd,CF_SEASONAL,RRA_seasonal_gamma,optarg)) {
233 if (set_hwarg(&rrd,CF_DEVSEASONAL,RRA_seasonal_gamma,optarg)) {
239 if (sscanf(optarg,DS_NAM_FMT,ds_nam) != 1){
240 rrd_set_error("invalid argument for aberrant-reset");
245 if ((ds=ds_match(&rrd,ds_nam))==-1){
246 /* ds_match handles it own errors */
251 reset_aberrant_coefficients(&rrd,rrd_file,(unsigned long) ds);
252 if (rrd_test_error()) {
260 rrd_set_error("unknown option '%c'", optopt);
262 rrd_set_error("unknown option '%s'",argv[optind-1]);
270 fseek(rrd_file,0,SEEK_SET);
271 fwrite(rrd.stat_head,
272 sizeof(stat_head_t),1, rrd_file);
274 sizeof(ds_def_t), rrd.stat_head->ds_cnt, rrd_file);
275 /* need to write rra_defs for RRA parameter changes */
276 fwrite(rrd.rra_def, sizeof(rra_def_t), rrd.stat_head->rra_cnt,
280 for(i=0;i< rrd.stat_head->ds_cnt;i++)
281 if (dst_conv(rrd.ds_def[i].dst) != DST_CDEF) {
282 printf("DS[%s] typ: %s\thbt: %ld\tmin: %1.4f\tmax: %1.4f\n",
283 rrd.ds_def[i].ds_nam,
285 rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt,
286 rrd.ds_def[i].par[DS_min_val].u_val,
287 rrd.ds_def[i].par[DS_max_val].u_val);
290 rpn_compact2str((rpn_cdefds_t *) &(rrd.ds_def[i].par[DS_cdef]),rrd.ds_def,&buffer);
291 printf("DS[%s] typ: %s\tcdef: %s\n", rrd.ds_def[i].ds_nam,rrd.ds_def[i].dst,buffer);
300 int set_hwarg(rrd_t *rrd,enum cf_en cf,enum rra_par_en rra_par,char *arg)
304 signed short rra_idx = -1;
307 if (param <= 0.0 || param >= 1.0)
309 rrd_set_error("Holt-Winters parameter must be between 0 and 1");
312 /* does the appropriate RRA exist? */
313 for (i = 0; i < rrd -> stat_head -> rra_cnt; ++i)
315 if (cf_conv(rrd -> rra_def[i].cf_nam) == cf)
323 rrd_set_error("Holt-Winters RRA does not exist in this RRD");
328 rrd -> rra_def[rra_idx].par[rra_par].u_val = param;
332 int set_deltaarg(rrd_t *rrd,enum rra_par_en rra_par,char *arg)
336 signed short rra_idx = -1;
341 rrd_set_error("Parameter specified is too small");
344 /* does the appropriate RRA exist? */
345 for (i = 0; i < rrd -> stat_head -> rra_cnt; ++i)
347 if (cf_conv(rrd -> rra_def[i].cf_nam) == CF_FAILURES)
355 rrd_set_error("Failures RRA does not exist in this RRD");
360 rrd -> rra_def[rra_idx].par[rra_par].u_val = param;
364 int set_windowarg(rrd_t *rrd,enum rra_par_en rra_par,char *arg)
367 unsigned long i, cdp_idx;
368 signed short rra_idx = -1;
371 if (param < 1 || param > MAX_FAILURES_WINDOW_LEN)
373 rrd_set_error("Parameter must be between %d and %d",
374 1, MAX_FAILURES_WINDOW_LEN);
377 /* does the appropriate RRA exist? */
378 for (i = 0; i < rrd -> stat_head -> rra_cnt; ++i)
380 if (cf_conv(rrd -> rra_def[i].cf_nam) == CF_FAILURES)
388 rrd_set_error("Failures RRA does not exist in this RRD");
393 rrd -> rra_def[rra_idx].par[rra_par].u_cnt = param;
395 /* erase existing violations */
396 for (i = 0; i < rrd -> stat_head -> ds_cnt; i++)
398 cdp_idx = rra_idx * (rrd -> stat_head -> ds_cnt) + i;
399 erase_violations(rrd,cdp_idx,rra_idx);