1 /*****************************************************************************
2 * RRDtool 1.0.33 Copyright Tobias Oetiker, 1997 - 2000
3 *****************************************************************************
4 * change header parameters of an rrd
5 *****************************************************************************
8 * Revision 1.4 2001/08/22 22:29:07 jake
9 * Contents of this patch:
10 * (1) Adds/revises documentation for rrd tune in rrd_tool.c and pod files.
11 * (2) Moves some initialization code from rrd_create.c to rrd_hw.c.
12 * (3) Adds another pass to smoothing for SEASONAL and DEVSEASONAL RRAs.
13 * This pass computes the coefficients as deviations from an average; the
14 * average is added the baseline coefficient of HWPREDICT. Statistical texts
15 * suggest this to preserve algorithm stability. It will not invalidate
16 * RRD files created and smoothed with the old code.
17 * (4) Adds the aberrant-reset flag to rrd tune. This operation, which is
18 * specified for a single data source, causes the holt-winters algorithm to
19 * forget everthing it has learned and start over.
20 * (5) Fixes a few out-of-date code comments.
22 * Revision 1.3 2001/03/07 21:21:54 oetiker
23 * complete rewrite of rrdgraph documentation. This also includs info
24 * on upcomming/planned changes to the rrdgraph interface and functionality
25 * -- Alex van den Bogaerdt <alex@slot.hollandcasino.nl>
27 * Revision 1.2 2001/03/04 13:01:55 oetiker
28 * Aberrant Behavior Detection support. A brief overview added to rrdtool.pod.
29 * Major updates to rrd_update.c, rrd_create.c. Minor update to other core files.
30 * This is backwards compatible! But new files using the Aberrant stuff are not readable
31 * by old rrdtool versions. See http://cricket.sourceforge.net/aberrant/rrd_hw.htm
32 * -- Jake Brutlag <jakeb@corp.webtv.net>
34 *****************************************************************************/
37 #include "rrd_rpncalc.h"
40 int set_hwarg(rrd_t *rrd,enum cf_en cf,enum rra_par_en rra_par,char *arg);
41 int set_deltaarg(rrd_t *rrd,enum rra_par_en rra_par,char *arg);
42 int set_windowarg(rrd_t *rrd,enum rra_par_en,char *arg);
45 rrd_tune(int argc, char **argv)
52 char ds_nam[DS_NAM_SIZE];
53 char ds_new[DS_NAM_SIZE];
60 if(rrd_open(argv[1],&rrd_file,&rrd, RRD_READWRITE)==-1){
66 static struct option long_options[] =
68 {"heartbeat", required_argument, 0, 'h'},
69 {"minimum", required_argument, 0, 'i'},
70 {"maximum", required_argument, 0, 'a'},
71 {"data-source-type", required_argument, 0, 'd'},
72 {"data-source-rename", required_argument, 0, 'r'},
73 /* added parameter tuning options for aberrant behavior detection */
74 {"deltapos",required_argument,0,'p'},
75 {"deltaneg",required_argument,0,'n'},
76 {"window-length",required_argument,0,'w'},
77 {"failure-threshold",required_argument,0,'f'},
78 {"alpha",required_argument,0,'x'},
79 {"beta",required_argument,0,'y'},
80 {"gamma",required_argument,0,'z'},
81 {"gamma-deviation",required_argument,0,'v'},
82 {"aberrant-reset",required_argument,0,'b'},
87 opt = getopt_long(argc, argv, "h:i:a:d:r:p:n:w:f:x:y:z:v:b:",
88 long_options, &option_index);
95 if ((matches = sscanf(optarg, DS_NAM_FMT ":%ld",ds_nam,&heartbeat)) != 2){
96 rrd_set_error("invalid arguments for heartbeat");
101 if ((ds=ds_match(&rrd,ds_nam))==-1){
106 rrd.ds_def[ds].par[DS_mrhb_cnt].u_cnt = heartbeat;
110 if ((matches = sscanf(optarg,DS_NAM_FMT ":%lf",ds_nam,&min)) <1){
111 rrd_set_error("invalid arguments for minimum ds value");
116 if ((ds=ds_match(&rrd,ds_nam))==-1){
124 rrd.ds_def[ds].par[DS_min_val].u_val = min;
128 if ((matches = sscanf(optarg, DS_NAM_FMT ":%lf",ds_nam,&max)) <1){
129 rrd_set_error("invalid arguments for maximum ds value");
134 if ((ds=ds_match(&rrd,ds_nam))==-1){
141 rrd.ds_def[ds].par[DS_max_val].u_val = max;
145 if ((matches = sscanf(optarg, DS_NAM_FMT ":" DST_FMT ,ds_nam,dst)) != 2){
146 rrd_set_error("invalid arguments for data source type");
151 if ((ds=ds_match(&rrd,ds_nam))==-1){
156 if (dst_conv(dst) == -1){
161 strncpy(rrd.ds_def[ds].dst,dst,DST_SIZE-1);
162 rrd.ds_def[ds].dst[DST_SIZE-1]='\0';
164 rrd.pdp_prep[ds].last_ds[0] = 'U';
165 rrd.pdp_prep[ds].last_ds[1] = 'N';
166 rrd.pdp_prep[ds].last_ds[2] = 'K';
167 rrd.pdp_prep[ds].last_ds[3] = 'N';
168 rrd.pdp_prep[ds].last_ds[4] = '\0';
173 sscanf(optarg,DS_NAM_FMT ":" DS_NAM_FMT , ds_nam,ds_new)) != 2){
174 rrd_set_error("invalid arguments for data source type");
179 if ((ds=ds_match(&rrd,ds_nam))==-1){
184 strncpy(rrd.ds_def[ds].ds_nam,ds_new,DS_NAM_SIZE-1);
185 rrd.ds_def[ds].ds_nam[DS_NAM_SIZE-1]='\0';
188 if (set_deltaarg(&rrd,RRA_delta_pos,optarg)) {
194 if (set_deltaarg(&rrd,RRA_delta_neg,optarg)) {
200 if (set_windowarg(&rrd,RRA_failure_threshold,optarg)) {
206 if (set_windowarg(&rrd,RRA_window_len,optarg)) {
212 if (set_hwarg(&rrd,CF_HWPREDICT,RRA_hw_alpha,optarg)) {
218 if (set_hwarg(&rrd,CF_HWPREDICT,RRA_hw_beta,optarg)) {
224 if (set_hwarg(&rrd,CF_SEASONAL,RRA_seasonal_gamma,optarg)) {
230 if (set_hwarg(&rrd,CF_DEVSEASONAL,RRA_seasonal_gamma,optarg)) {
236 if (sscanf(optarg,DS_NAM_FMT,ds_nam) != 1){
237 rrd_set_error("invalid argument for aberrant-reset");
242 if ((ds=ds_match(&rrd,ds_nam))==-1){
243 /* ds_match handles it own errors */
248 reset_aberrant_coefficients(&rrd,rrd_file,(unsigned long) ds);
249 if (rrd_test_error()) {
257 rrd_set_error("unknown option '%c'", optopt);
259 rrd_set_error("unknown option '%s'",argv[optind-1]);
267 fseek(rrd_file,0,SEEK_SET);
268 fwrite(rrd.stat_head,
269 sizeof(stat_head_t),1, rrd_file);
271 sizeof(ds_def_t), rrd.stat_head->ds_cnt, rrd_file);
272 /* need to write rra_defs for RRA parameter changes */
273 fwrite(rrd.rra_def, sizeof(rra_def_t), rrd.stat_head->rra_cnt,
277 for(i=0;i< rrd.stat_head->ds_cnt;i++)
278 if (dst_conv(rrd.ds_def[i].dst) != DST_CDEF) {
279 printf("DS[%s] typ: %s\thbt: %ld\tmin: %1.4f\tmax: %1.4f\n",
280 rrd.ds_def[i].ds_nam,
282 rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt,
283 rrd.ds_def[i].par[DS_min_val].u_val,
284 rrd.ds_def[i].par[DS_max_val].u_val);
287 rpn_compact2str((rpn_cdefds_t *) &(rrd.ds_def[i].par[DS_cdef]),rrd.ds_def,&buffer);
288 printf("DS[%s] typ: %s\tcdef: %s\n", rrd.ds_def[i].ds_nam,rrd.ds_def[i].dst,buffer);
297 int set_hwarg(rrd_t *rrd,enum cf_en cf,enum rra_par_en rra_par,char *arg)
301 signed short rra_idx = -1;
304 if (param <= 0.0 || param >= 1.0)
306 rrd_set_error("Holt-Winters parameter must be between 0 and 1");
309 /* does the appropriate RRA exist? */
310 for (i = 0; i < rrd -> stat_head -> rra_cnt; ++i)
312 if (cf_conv(rrd -> rra_def[i].cf_nam) == cf)
320 rrd_set_error("Holt-Winters RRA does not exist in this RRD");
325 rrd -> rra_def[rra_idx].par[rra_par].u_val = param;
329 int set_deltaarg(rrd_t *rrd,enum rra_par_en rra_par,char *arg)
333 signed short rra_idx = -1;
338 rrd_set_error("Parameter specified is too small");
341 /* does the appropriate RRA exist? */
342 for (i = 0; i < rrd -> stat_head -> rra_cnt; ++i)
344 if (cf_conv(rrd -> rra_def[i].cf_nam) == CF_FAILURES)
352 rrd_set_error("Failures RRA does not exist in this RRD");
357 rrd -> rra_def[rra_idx].par[rra_par].u_val = param;
361 int set_windowarg(rrd_t *rrd,enum rra_par_en rra_par,char *arg)
364 unsigned long i, cdp_idx;
365 signed short rra_idx = -1;
368 if (param < 1 || param > MAX_FAILURES_WINDOW_LEN)
370 rrd_set_error("Parameter must be between %d and %d",
371 1, MAX_FAILURES_WINDOW_LEN);
374 /* does the appropriate RRA exist? */
375 for (i = 0; i < rrd -> stat_head -> rra_cnt; ++i)
377 if (cf_conv(rrd -> rra_def[i].cf_nam) == CF_FAILURES)
385 rrd_set_error("Failures RRA does not exist in this RRD");
390 rrd -> rra_def[rra_idx].par[rra_par].u_cnt = param;
392 /* erase existing violations */
393 for (i = 0; i < rrd -> stat_head -> ds_cnt; i++)
395 cdp_idx = rra_idx * (rrd -> stat_head -> ds_cnt) + i;
396 erase_violations(rrd,cdp_idx,rra_idx);