1 /*****************************************************************************
2 * RRDtool 1.4.3 Copyright by Tobi Oetiker, 1997-2010
3 *****************************************************************************
5 *****************************************************************************
6 * Initial version by Burton Strauss, ntopSupport.com - 3/2005
7 *****************************************************************************/
11 #include "rrd_client.h"
18 int target_rraindex = 0;
20 char *opt_daemon = NULL;
21 struct option long_options[] = {
22 {"rraindex", required_argument, 0, 129},
23 {"daemon", required_argument, 0, 'd'},
28 opterr = 0; /* initialize getopt */
34 opt = getopt_long(argc, argv, "d:F", long_options, &option_index);
41 target_rraindex = strtol(optarg, &endptr, 0);
42 if (target_rraindex < 0) {
43 rrd_set_error("invalid rraindex number");
48 if (opt_daemon != NULL)
50 opt_daemon = strdup (optarg);
51 if (opt_daemon == NULL)
53 rrd_set_error ("strdup failed.");
58 rrd_set_error("usage rrdtool %s [--rraindex number] [--daemon <addr>] file.rrd",
65 rrd_set_error("usage rrdtool %s [--rraindex number] [--daemon <addr>] file.rrd",
70 rrdc_connect (opt_daemon);
71 if (rrdc_is_connected (opt_daemon)) {
72 return (rrdc_first (argv[optind], target_rraindex));
74 return (rrd_first_r(argv[optind], target_rraindex));
83 off_t rra_start, timer;
89 rrd_file = rrd_open(filename, &rrd, RRD_READONLY);
90 if (rrd_file == NULL) {
94 if ((rraindex < 0) || (rraindex >= (int) rrd.stat_head->rra_cnt)) {
95 rrd_set_error("invalid rraindex number");
99 rra_start = rrd_file->header_len;
102 (rrd.rra_ptr[rraindex].cur_row + 1) *
103 rrd.stat_head->ds_cnt * sizeof(rrd_value_t)), SEEK_SET);
104 timer = -(long)(rrd.rra_def[rraindex].row_cnt - 1);
105 if (rrd.rra_ptr[rraindex].cur_row + 1 > rrd.rra_def[rraindex].row_cnt) {
106 rrd_seek(rrd_file, rra_start, SEEK_SET);
108 then = (rrd.live_head->last_up -
109 rrd.live_head->last_up %
110 (rrd.rra_def[rraindex].pdp_cnt * rrd.stat_head->pdp_step)) +
111 (timer * rrd.rra_def[rraindex].pdp_cnt * rrd.stat_head->pdp_step);