#include "rrd_client.h"
#include "rrd_is_thread_safe.h"
-static int opt_no_overwrite = 0;
#ifdef WIN32
# include <process.h>
static void rrd_free2(
rrd_t *rrd); /* our onwn copy, immmune to mmap */
-void rrd_create_set_no_overwrite(
- int opt )
-{
- opt_no_overwrite = (opt?1:0);
-}
-
int rrd_create(
int argc,
char **argv)
long long_tmp;
int rc;
char * opt_daemon = NULL;
+ int opt_no_overwrite = 0;
optind = 0;
opterr = 0; /* initialize getopt */
pdp_step, last_up, opt_no_overwrite,
argc - optind - 1, (const char **) (argv + optind + 1));
} else {
- rc = rrd_create_r(argv[optind],
- pdp_step, last_up,
+ rc = rrd_create_r2(argv[optind],
+ pdp_step, last_up, opt_no_overwrite,
argc - optind - 1, (const char **) (argv + optind + 1));
}
}
/* #define DEBUG */
+/* For backwards compatibility with previous API. Use rrd_create_r2 if you
+ need to have the no_overwrite parameter. */
int rrd_create_r(
const char *filename,
unsigned long pdp_step,
int argc,
const char **argv)
{
+ return rrd_create_r2(filename,pdp_step,last_up,0,argc,argv);
+}
+int rrd_create_r2(
+ const char *filename,
+ unsigned long pdp_step,
+ time_t last_up,
+ int no_overwrite,
+ int argc,
+ const char **argv)
+{
rrd_t rrd;
long i;
int offset;
rrd_free2(&rrd);
return (-1);
}
- return rrd_create_fn(filename, &rrd);
+ return rrd_create_fn(filename, &rrd, no_overwrite);
}
void parseGENERIC_DS(
int rrd_create_fn(
const char *file_name,
- rrd_t *rrd)
+ rrd_t *rrd,
+ int no_overwrite )
{
unsigned long i, ii;
rrd_value_t *unknown;
rrd_t rrd_dn;
unsigned rrd_flags = RRD_READWRITE | RRD_CREAT;
- if (opt_no_overwrite) {
+ if (no_overwrite) {
rrd_flags |= RRD_EXCL ;
}
#endif
#endif
-#include "rrd.h"
+#include "rrd_tool.h"
#include "rrd_client.h"
#include "unused.h"
static uint64_t stats_journal_rotate = 0;
static pthread_mutex_t stats_lock = PTHREAD_MUTEX_INITIALIZER;
-static int opt_no_overwrite = 0;
+static int opt_no_overwrite = 0; /* default for the daemon */
/* Journaled updates */
#define JOURNAL_REPLAY(s) ((s) == NULL)
return send_response(sock, RESP_ERR, "RRD Error: %s\n", rrd_get_error());
}
return send_response(sock, RESP_OK, "%lu\n",(unsigned)t);
-} /* }}} static int handle_request_last */
+} /* }}} static int handle_request_first */
+
static int handle_request_last (HANDLER_PROTO) /* {{{ */
{
char *file, file_tmp[PATH_MAX];
int status;
- time_t t;
+ time_t t, from_file, step;
+ rrd_file_t * rrd_file;
+ cache_item_t * ci;
+ rrd_t rrd;
/* obtain filename */
status = buffer_get_field(&buffer, &buffer_size, &file);
if (!check_file_access(file, sock)) {
return send_response(sock, RESP_ERR, "Cannot read: %s\n", file);
}
- /* get data */
- rrd_clear_error ();
- t = rrd_last_r(file);
- if(t<1) {
+ rrd_clear_error();
+ rrd_init(&rrd);
+ rrd_file = rrd_open(file,&rrd,RRD_READONLY);
+ if(!rrd_file) {
return send_response(sock, RESP_ERR, "RRD Error: %s\n", rrd_get_error());
}
+ from_file = rrd.live_head->last_up;
+ step = rrd.stat_head->pdp_step;
+ rrd_close(rrd_file);
+ pthread_mutex_lock(&cache_lock);
+ ci = g_tree_lookup(cache_tree, file);
+ if (ci)
+ t = ci->last_update_stamp;
+ else
+ t = from_file;
+ pthread_mutex_unlock(&cache_lock);
+ t -= t % step;
+ rrd_free(&rrd);
+ if(t<1) {
+ return send_response(sock, RESP_ERR, "Error: rrdcached: Invalid timestamp returned\n");
+ }
return send_response(sock, RESP_OK, "%lu\n",(unsigned)t);
} /* }}} static int handle_request_last */
int ac = 0;
char *av[128];
int status;
- ulong step = 300;
+ unsigned long step = 300;
time_t last_up = time(NULL)-10;
- rrd_time_value_t last_up_tv;
- char *parsetime_error = NULL;
int no_overwrite = opt_no_overwrite;
}
RRDD_LOG(LOG_INFO, "rrdcreate request for %s",file);
- status = buffer_get_field(&buffer, &buffer_size, &tok );
- for(;(tok && !status);status = buffer_get_field(&buffer, &buffer_size, &tok )) {
+ while ((status = buffer_get_field(&buffer, &buffer_size, &tok)) == 0 && tok) {
if( ! strncmp(tok,"-b",2) ) {
status = buffer_get_field(&buffer, &buffer_size, &tok );
if (status != 0) return syntax_error(sock,cmd);
- if ((parsetime_error = rrd_parsetime(tok, &last_up_tv)))
- return send_response(sock, RESP_ERR, "start time: %s\n", parsetime_error);
- if (last_up_tv.type == RELATIVE_TO_END_TIME ||
- last_up_tv.type == RELATIVE_TO_START_TIME) {
- return send_response(sock, RESP_ERR, "Cannot specify time relative to start or end here.\n");
- }
- last_up = mktime(&last_up_tv.tm) +last_up_tv.offset;
-
+ last_up = (time_t) atol(tok);
continue;
}
if( ! strncmp(tok,"-s",2) ) {
return send_response(sock, RESP_ERR, "The first entry must be after 1980.\n");
}
- rrd_create_set_no_overwrite(no_overwrite);
rrd_clear_error ();
- status = rrd_create_r(file,step,last_up,ac,(const char **)av);
+ status = rrd_create_r2(file,step,last_up,no_overwrite,ac,(const char **)av);
if(!status) {
return send_response(sock, RESP_OK, "RRD created OK\n");
"CREATE <filename> [-b start] [-s step] [-O] <DS definitions> <RRA definitions>\n",
"The CREATE command will create an RRD file, overwriting any existing file\n"
"unless the -O option is given or rrdcached was started with the -O option.\n"
+ "The start parameter needs to be in seconds since 1/1/70 (AT-style syntax is\n"
+ "not acceptable) and the step is in seconds (default is 300).\n"
"The DS and RRA definitions are as for the 'rrdtool create' command.\n"
},
{
char **argv)
{
char *opt_daemon = NULL;
- int status;
time_t lastupdate;
- int flushfirst = 1;
optind = 0;
opterr = 0; /* initialize getopt */
int option_index = 0;
static struct option long_options[] = {
{"daemon", required_argument, 0, 'd'},
- {"noflush", no_argument, 0, 'F'},
{0, 0, 0, 0}
};
- opt = getopt_long(argc, argv, "d:F", long_options, &option_index);
+ opt = getopt_long(argc, argv, "d:", long_options, &option_index);
if (opt == EOF)
break;
}
break;
- case 'F':
- flushfirst = 0;
- break;
-
default:
- rrd_set_error ("Usage: rrdtool %s [--daemon <addr> [--noflush]] <file>",
+ rrd_set_error ("Usage: rrdtool %s [--daemon <addr>] <file>",
argv[0]);
return (-1);
break;
} /* while (42) */
if ((argc - optind) != 1) {
- rrd_set_error ("Usage: rrdtool %s [--daemon <addr> [--noflush]] <file>",
+ rrd_set_error ("Usage: rrdtool %s [--daemon <addr>] <file>",
argv[0]);
return (-1);
}
- if(flushfirst) {
- status = rrdc_flush_if_daemon(opt_daemon, argv[optind]);
- if (status) return (-1);
- }
-
rrdc_connect (opt_daemon);
if (rrdc_is_connected (opt_daemon))
lastupdate = rrdc_last (argv[optind]);
else
lastupdate = rrd_last_r(argv[optind]);
+ if (opt_daemon) free(opt_daemon);
return (lastupdate);
}