X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_fetch.c;h=26c33246ccccd31072cbbfab6e7e91b1607b83c3;hb=dbc110514529603f430259064a0bdc067a11b9f5;hp=6ff81b59d36ef51fd2a4d0747b81c7c9b23bab52;hpb=a5eb18ad8c70e530a2e28ed435a0f52da0f5bee0;p=rrdtool.git diff --git a/src/rrd_fetch.c b/src/rrd_fetch.c index 6ff81b5..26c3324 100644 --- a/src/rrd_fetch.c +++ b/src/rrd_fetch.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.3rc8 Copyright by Tobi Oetiker, 1997-2008 + * RRDtool 1.3.0 Copyright by Tobi Oetiker, 1997-2008 ***************************************************************************** * rrd_fetch.c read date from an rrd to use for further processing ***************************************************************************** @@ -53,6 +53,7 @@ *****************************************************************************/ #include "rrd_tool.h" +#include "rrd_client.h" #include "rrd_is_thread_safe.h" /*#define DEBUG*/ @@ -72,6 +73,7 @@ int rrd_fetch( long step_tmp = 1; time_t start_tmp = 0, end_tmp = 0; const char *cf; + char *daemon = NULL; rrd_time_value_t start_tv, end_tv; char *parsetime_error = NULL; @@ -79,6 +81,7 @@ int rrd_fetch( {"resolution", required_argument, 0, 'r'}, {"start", required_argument, 0, 's'}, {"end", required_argument, 0, 'e'}, + {"daemon", required_argument, 0, 'd'}, {0, 0, 0, 0} }; @@ -93,7 +96,7 @@ int rrd_fetch( int option_index = 0; int opt; - opt = getopt_long(argc, argv, "r:s:e:", long_options, &option_index); + opt = getopt_long(argc, argv, "r:s:e:d:", long_options, &option_index); if (opt == EOF) break; @@ -114,6 +117,18 @@ int rrd_fetch( case 'r': step_tmp = atol(optarg); break; + + case 'd': + if (daemon != NULL) + free (daemon); + daemon = strdup (optarg); + if (daemon == NULL) + { + rrd_set_error ("strdup failed."); + return (-1); + } + break; + case '?': rrd_set_error("unknown option '-%c'", optopt); return (-1); @@ -151,10 +166,26 @@ int rrd_fetch( return -1; } + if (daemon == NULL) + { + char *temp; + + temp = getenv (ENV_RRDCACHED_ADDRESS); + if (temp != NULL) + { + daemon = strdup (temp); + if (daemon == NULL) + { + rrd_set_error("strdup failed."); + return (-1); + } + } + } + cf = argv[optind + 1]; - if (rrd_fetch_r(argv[optind], cf, start, end, step, ds_cnt, ds_namv, data) - != 0) + if (rrd_fetch_r(argv[optind], cf, start, end, step, daemon, ds_cnt, + ds_namv, data) != 0) return (-1); return (0); } @@ -167,19 +198,36 @@ int rrd_fetch_r( * will be changed to represent reality */ unsigned long *step, /* which stepsize do you want? * will be changed to represent reality */ + const char *daemon, unsigned long *ds_cnt, /* number of data sources in file */ char ***ds_namv, /* names of data_sources */ rrd_value_t **data) { /* two dimensional array containing the data */ enum cf_en cf_idx; + int status; if ((int) (cf_idx = cf_conv(cf)) == -1) { return -1; } - return (rrd_fetch_fn - (filename, cf_idx, start, end, step, ds_cnt, ds_namv, data)); -} + if (daemon != NULL) + { + status = rrdc_connect (daemon); + if (status != 0) + { + rrd_set_error ("rrdc_connect failed with status %i.", status); + return (-1); + } + } + + status = rrd_fetch_fn (filename, cf_idx, start, end, step, + (daemon == NULL) ? 0 : 1, + ds_cnt, ds_namv, data); + + rrdc_disconnect (); + + return (status); +} /* int rrd_fetch_r */ int rrd_fetch_fn( const char *filename, /* name of the rrd */ @@ -189,6 +237,7 @@ int rrd_fetch_fn( * will be changed to represent reality */ unsigned long *step, /* which stepsize do you want? * will be changed to represent reality */ + int use_rrdcached, unsigned long *ds_cnt, /* number of data sources in file */ char ***ds_namv, /* names of data_sources */ rrd_value_t **data) @@ -208,6 +257,18 @@ int rrd_fetch_fn( rrd_value_t *data_ptr; unsigned long rows; + if (use_rrdcached) + { + int status; + + status = rrdc_flush (filename); + if (status != 0) + { + rrd_set_error ("rrdc_flush failed with status %i.", status); + return (-1); + } + } + #ifdef DEBUG fprintf(stderr, "Entered rrd_fetch_fn() searching for the best match\n"); fprintf(stderr, "Looking for: start %10lu end %10lu step %5lu\n",