1 /*****************************************************************************
2 * RRDtool 1.3.2 Copyright by Tobi Oetiker, 1997-2008
3 *****************************************************************************
5 *****************************************************************************
6 * Initial version by Burton Strauss, ntopSupport.com - 3/2005
7 *****************************************************************************/
16 int target_rraindex = 0;
18 struct option long_options[] = {
19 {"rraindex", required_argument, 0, 129},
24 opterr = 0; /* initialize getopt */
30 opt = getopt_long(argc, argv, "", long_options, &option_index);
37 target_rraindex = strtol(optarg, &endptr, 0);
38 if (target_rraindex < 0) {
39 rrd_set_error("invalid rraindex number");
44 rrd_set_error("usage rrdtool %s [--rraindex number] file.rrd",
51 rrd_set_error("not enough arguments");
55 return (rrd_first_r(argv[optind], target_rraindex));
63 off_t rra_start, timer;
69 rrd_file = rrd_open(filename, &rrd, RRD_READONLY);
70 if (rrd_file == NULL) {
74 if ((rraindex < 0) || (rraindex >= (int) rrd.stat_head->rra_cnt)) {
75 rrd_set_error("invalid rraindex number");
79 rra_start = rrd_file->header_len;
82 (rrd.rra_ptr[rraindex].cur_row + 1) *
83 rrd.stat_head->ds_cnt * sizeof(rrd_value_t)), SEEK_SET);
84 timer = -(rrd.rra_def[rraindex].row_cnt - 1);
85 if (rrd.rra_ptr[rraindex].cur_row + 1 > rrd.rra_def[rraindex].row_cnt) {
86 rrd_seek(rrd_file, rra_start, SEEK_SET);
88 then = (rrd.live_head->last_up -
89 rrd.live_head->last_up %
90 (rrd.rra_def[rraindex].pdp_cnt * rrd.stat_head->pdp_step)) +
91 (timer * rrd.rra_def[rraindex].pdp_cnt * rrd.stat_head->pdp_step);