1 /*****************************************************************************
2 * RRDtool 1.0.33 Copyright Tobias Oetiker, 1997 - 2000
3 *****************************************************************************
4 * change header parameters of an rrd
5 *****************************************************************************
8 * Revision 1.3 2001/03/07 21:21:54 oetiker
9 * complete rewrite of rrdgraph documentation. This also includs info
10 * on upcomming/planned changes to the rrdgraph interface and functionality
11 * -- Alex van den Bogaerdt <alex@slot.hollandcasino.nl>
13 * Revision 1.2 2001/03/04 13:01:55 oetiker
14 * Aberrant Behavior Detection support. A brief overview added to rrdtool.pod.
15 * Major updates to rrd_update.c, rrd_create.c. Minor update to other core files.
16 * This is backwards compatible! But new files using the Aberrant stuff are not readable
17 * by old rrdtool versions. See http://cricket.sourceforge.net/aberrant/rrd_hw.htm
18 * -- Jake Brutlag <jakeb@corp.webtv.net>
20 *****************************************************************************/
24 int set_hwarg(rrd_t *rrd,enum cf_en cf,enum rra_par_en rra_par,char *arg);
25 int set_deltaarg(rrd_t *rrd,enum rra_par_en rra_par,char *arg);
26 int set_windowarg(rrd_t *rrd,enum rra_par_en,char *arg);
29 rrd_tune(int argc, char **argv)
36 char ds_nam[DS_NAM_SIZE];
37 char ds_new[DS_NAM_SIZE];
44 if(rrd_open(argv[1],&rrd_file,&rrd, RRD_READWRITE)==-1){
50 static struct option long_options[] =
52 {"heartbeat", required_argument, 0, 'h'},
53 {"minimum", required_argument, 0, 'i'},
54 {"maximum", required_argument, 0, 'a'},
55 {"data-source-type", required_argument, 0, 'd'},
56 {"data-source-rename", required_argument, 0, 'r'},
57 /* added parameter tuning options for aberrant behavior detection */
58 {"deltapos",required_argument,0,'p'},
59 {"deltaneg",required_argument,0,'n'},
60 {"window-length",required_argument,0,'w'},
61 {"failure-threshold",required_argument,0,'f'},
62 {"alpha",required_argument,0,'x'},
63 {"beta",required_argument,0,'y'},
64 {"gamma",required_argument,0,'z'},
69 opt = getopt_long(argc, argv, "h:i:a:d:r:p:n:w:f:x:y:z:",
70 long_options, &option_index);
77 if ((matches = sscanf(optarg, DS_NAM_FMT ":%ld",ds_nam,&heartbeat)) != 2){
78 rrd_set_error("invalid arguments for heartbeat");
83 if ((ds=ds_match(&rrd,ds_nam))==-1){
88 rrd.ds_def[ds].par[DS_mrhb_cnt].u_cnt = heartbeat;
92 if ((matches = sscanf(optarg,DS_NAM_FMT ":%lf",ds_nam,&min)) <1){
93 rrd_set_error("invalid arguments for minimum ds value");
98 if ((ds=ds_match(&rrd,ds_nam))==-1){
106 rrd.ds_def[ds].par[DS_min_val].u_val = min;
110 if ((matches = sscanf(optarg, DS_NAM_FMT ":%lf",ds_nam,&max)) <1){
111 rrd_set_error("invalid arguments for maximum ds value");
116 if ((ds=ds_match(&rrd,ds_nam))==-1){
123 rrd.ds_def[ds].par[DS_max_val].u_val = max;
127 if ((matches = sscanf(optarg, DS_NAM_FMT ":" DST_FMT ,ds_nam,dst)) != 2){
128 rrd_set_error("invalid arguments for data source type");
133 if ((ds=ds_match(&rrd,ds_nam))==-1){
138 if (dst_conv(dst) == -1){
143 strncpy(rrd.ds_def[ds].dst,dst,DST_SIZE-1);
144 rrd.ds_def[ds].dst[DST_SIZE-1]='\0';
146 rrd.pdp_prep[ds].last_ds[0] = 'U';
147 rrd.pdp_prep[ds].last_ds[1] = 'N';
148 rrd.pdp_prep[ds].last_ds[2] = 'K';
149 rrd.pdp_prep[ds].last_ds[3] = 'N';
150 rrd.pdp_prep[ds].last_ds[4] = '\0';
155 sscanf(optarg,DS_NAM_FMT ":" DS_NAM_FMT , ds_nam,ds_new)) != 2){
156 rrd_set_error("invalid arguments for data source type");
161 if ((ds=ds_match(&rrd,ds_nam))==-1){
166 strncpy(rrd.ds_def[ds].ds_nam,ds_new,DS_NAM_SIZE-1);
167 rrd.ds_def[ds].ds_nam[DS_NAM_SIZE-1]='\0';
170 if (set_deltaarg(&rrd,RRA_delta_pos,optarg)) {
176 if (set_deltaarg(&rrd,RRA_delta_neg,optarg)) {
182 if (set_windowarg(&rrd,RRA_failure_threshold,optarg)) {
188 if (set_windowarg(&rrd,RRA_window_len,optarg)) {
194 if (set_hwarg(&rrd,CF_HWPREDICT,RRA_hw_alpha,optarg)) {
200 if (set_hwarg(&rrd,CF_HWPREDICT,RRA_hw_beta,optarg)) {
206 if (set_hwarg(&rrd,CF_SEASONAL,RRA_seasonal_gamma,optarg)) {
213 rrd_set_error("unknown option '%c'", optopt);
215 rrd_set_error("unknown option '%s'",argv[optind-1]);
223 fseek(rrd_file,0,SEEK_SET);
224 fwrite(rrd.stat_head,
225 sizeof(stat_head_t),1, rrd_file);
227 sizeof(ds_def_t), rrd.stat_head->ds_cnt, rrd_file);
228 /* need to write rra_defs for RRA parameter changes */
229 fwrite(rrd.rra_def, sizeof(rra_def_t), rrd.stat_head->rra_cnt,
233 for(i=0;i< rrd.stat_head->ds_cnt;i++)
234 printf("DS[%s] typ: %s\thbt: %ld\tmin: %1.4f\tmax: %1.4f\n",
235 rrd.ds_def[i].ds_nam,
237 rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt,
238 rrd.ds_def[i].par[DS_min_val].u_val,
239 rrd.ds_def[i].par[DS_max_val].u_val);
246 int set_hwarg(rrd_t *rrd,enum cf_en cf,enum rra_par_en rra_par,char *arg)
250 signed short rra_idx = -1, devseasonal_idx = -1;
253 if (param <= 0.0 || param >= 1.0)
255 rrd_set_error("Holt-Winters parameter must be between 0 and 1");
258 /* does the appropriate RRA exist? */
259 for (i = 0; i < rrd -> stat_head -> rra_cnt; ++i)
261 if (cf_conv(rrd -> rra_def[i].cf_nam) == cf)
265 /* find the DEVSEASONAL index separately, as it is optional */
266 if (cf_conv(rrd -> rra_def[i].cf_nam) == CF_DEVSEASONAL)
273 rrd_set_error("Holt-Winters RRA does not exist in this RRD");
278 rrd -> rra_def[rra_idx].par[rra_par].u_val = param;
279 if (devseasonal_idx > -1)
280 rrd -> rra_def[devseasonal_idx].par[rra_par].u_val = param;
284 int set_deltaarg(rrd_t *rrd,enum rra_par_en rra_par,char *arg)
288 signed short rra_idx = -1;
293 rrd_set_error("Parameter specified is too small");
296 /* does the appropriate RRA exist? */
297 for (i = 0; i < rrd -> stat_head -> rra_cnt; ++i)
299 if (cf_conv(rrd -> rra_def[i].cf_nam) == CF_FAILURES)
307 rrd_set_error("Failures RRA does not exist in this RRD");
312 rrd -> rra_def[rra_idx].par[rra_par].u_val = param;
316 int set_windowarg(rrd_t *rrd,enum rra_par_en rra_par,char *arg)
319 unsigned long i, cdp_idx;
320 signed short rra_idx = -1;
323 /* there are 4 chars to a long, reserve on CDP entry for future
325 if (param < 1 || param > MAX_FAILURES_WINDOW_LEN)
327 rrd_set_error("Parameter must be between %d and %d",
328 1, MAX_CDP_PAR_EN - 1);
331 /* does the appropriate RRA exist? */
332 for (i = 0; i < rrd -> stat_head -> rra_cnt; ++i)
334 if (cf_conv(rrd -> rra_def[i].cf_nam) == CF_FAILURES)
342 rrd_set_error("Failures RRA does not exist in this RRD");
347 rrd -> rra_def[rra_idx].par[rra_par].u_cnt = param;
349 /* erase existing violations */
350 for (i = 0; i < rrd -> stat_head -> ds_cnt; i++)
352 cdp_idx = rra_idx * (rrd -> stat_head -> ds_cnt) + i;
353 erase_violations(rrd,cdp_idx,rra_idx);