~ubuntu-branches/ubuntu/saucy/rrdtool/saucy-proposed

« back to all changes in this revision

Viewing changes to src/rrd_tune.c

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2010-07-22 08:07:01 UTC
  • mfrom: (1.2.8 upstream) (3.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100722080701-k46mgdfz6euxwqsm
Tags: 1.4.3-1ubuntu1
* Merge from debian unstable, Remaining changes:
  - debian/control: Don't build against ruby1.9 as we don't want
    it in main.
* require libdbi >= 0.8.3 to prevent aborts when using dbi datasources

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
 
 * RRDtool 1.3.8  Copyright by Tobi Oetiker, 1997-2009
 
2
 * RRDtool 1.4.3  Copyright by Tobi Oetiker, 1997-2010
3
3
 *****************************************************************************
4
4
 * change header parameters of an rrd
5
5
 *****************************************************************************
6
 
 * $Id: rrd_tune.c 1801 2009-05-19 13:45:05Z oetiker $
 
6
 * $Id: rrd_tune.c 2042 2010-03-22 16:05:55Z oetiker $
7
7
 * $Log$
8
8
 * Revision 1.6  2004/05/26 22:11:12  oetiker
9
9
 * reduce compiler warnings. Many small fixes. -- Mike Slifcak <slif@bellsouth.net>
39
39
 *
40
40
 *****************************************************************************/
41
41
 
 
42
#include <stdlib.h>
 
43
#include <locale.h>
 
44
 
42
45
#include "rrd_tool.h"
43
46
#include "rrd_rpncalc.h"
44
47
#include "rrd_hw.h"
45
 
#include <locale.h>
46
 
 
47
 
#ifdef WIN32
48
 
#include <stdlib.h>
49
 
#endif
50
48
 
51
49
int       set_hwarg(
52
50
    rrd_t *rrd,
62
60
    enum rra_par_en,
63
61
    char *arg);
64
62
 
 
63
int set_hwsmootharg(
 
64
    rrd_t *rrd,
 
65
    enum cf_en cf,
 
66
    enum rra_par_en rra_par,
 
67
    char *arg);
 
68
 
65
69
int rrd_tune(
66
70
    int argc,
67
71
    char **argv)
102
106
    opterr = 0;         /* initialize getopt */
103
107
 
104
108
 
 
109
    rrd_init(&rrd);
105
110
    rrd_file = rrd_open(argv[1], &rrd, RRD_READWRITE);
106
111
    if (rrd_file == NULL) {
107
112
        rrd_free(&rrd);
306
311
            break;
307
312
        case 's':
308
313
            strcpy(rrd.stat_head->version, RRD_VERSION);    /* smoothing_window causes Version 4 */
309
 
            if (set_hwarg
 
314
            if (set_hwsmootharg
310
315
                (&rrd, CF_SEASONAL, RRA_seasonal_smoothing_window, optarg)) {
311
316
                rrd_free(&rrd);
312
317
                return -1;
314
319
            break;
315
320
        case 'S':
316
321
            strcpy(rrd.stat_head->version, RRD_VERSION);    /* smoothing_window causes Version 4 */
317
 
            if (set_hwarg
 
322
            if (set_hwsmootharg
318
323
                (&rrd, CF_DEVSEASONAL, RRA_seasonal_smoothing_window,
319
324
                 optarg)) {
320
325
                rrd_free(&rrd);
399
404
    return 0;
400
405
}
401
406
 
 
407
int set_hwsmootharg(
 
408
    rrd_t *rrd,
 
409
    enum cf_en cf,
 
410
    enum rra_par_en rra_par,
 
411
    char *arg)
 
412
{
 
413
    double    param;
 
414
    unsigned long i;
 
415
    signed short rra_idx = -1;
 
416
 
 
417
    /* read the value */
 
418
    param = atof(arg);
 
419
    /* in order to avoid smoothing of SEASONAL or DEVSEASONAL, we need to 
 
420
     * the 0.0 value*/
 
421
    if (param < 0.0 || param > 1.0) {
 
422
        rrd_set_error("Holt-Winters parameter must be between 0 and 1");
 
423
        return -1;
 
424
    }
 
425
    /* does the appropriate RRA exist?  */
 
426
    for (i = 0; i < rrd->stat_head->rra_cnt; ++i) {
 
427
        if (cf_conv(rrd->rra_def[i].cf_nam) == cf) {
 
428
            rra_idx = i;
 
429
            break;
 
430
        }
 
431
    }
 
432
    if (rra_idx == -1) {
 
433
        rrd_set_error("Holt-Winters RRA does not exist in this RRD");
 
434
        return -1;
 
435
    }
 
436
 
 
437
    /* set the value */
 
438
    rrd->rra_def[rra_idx].par[rra_par].u_val = param;
 
439
    return 0;
 
440
}
 
441
 
402
442
int set_deltaarg(
403
443
    rrd_t *rrd,
404
444
    enum rra_par_en rra_par,