From 6fb6dc410c337ff97d242cfc6c75e2b55bc85cde Mon Sep 17 00:00:00 2001 From: oetiker Date: Sat, 7 Mar 2009 10:31:51 +0000 Subject: [PATCH] This 2-patch series exposes 'flush' methods to the various language bindings. git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@1756 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/NEWS | 4 ++++ program/bindings/lua/rrdlua.c | 7 ++++++ program/bindings/perl-shared/RRDs.pm | 1 + program/bindings/perl-shared/RRDs.xs | 10 +++++++++ program/bindings/python/rrdtoolmodule.c | 29 +++++++++++++++++++++++++ program/bindings/ruby/main.c | 8 +++++++ program/bindings/tcl/tclrrd.c | 25 +++++++++++++++++++++ program/doc/rrdflush.pod | 14 +++++++----- program/src/rrd_flush.c | 12 +++++++--- 9 files changed, 101 insertions(+), 9 deletions(-) diff --git a/program/NEWS b/program/NEWS index 2c26f685..7d0c9204 100644 --- a/program/NEWS +++ b/program/NEWS @@ -18,3 +18,7 @@ RRDdump RRDgraph -------- * VDEF PERCENTNAN (PRECENT that ignores NAN) + +RRDflush +-------- +* instruct the rrdcached to flush all its data diff --git a/program/bindings/lua/rrdlua.c b/program/bindings/lua/rrdlua.c index a5b9fb75..2060f3bf 100644 --- a/program/bindings/lua/rrdlua.c +++ b/program/bindings/lua/rrdlua.c @@ -292,6 +292,12 @@ lua_rrd_graph (lua_State * L) return 3; } +static int +lua_rrd_flush(lua_State *L) +{ + return rrd_common_call(L, "flush", rrd_cmd_flush); +} + #if defined(DINF) static int lua_rrd_info (lua_State * L) @@ -347,6 +353,7 @@ static const struct luaL_reg rrd[] = { {"restore", lua_rrd_restore}, {"tune", lua_rrd_tune}, {"update", lua_rrd_update}, + {"flush", lua_rrd_flush}, #if defined(DINF) {"info", lua_rrd_info}, {"updatev", lua_rrd_updatev}, diff --git a/program/bindings/perl-shared/RRDs.pm b/program/bindings/perl-shared/RRDs.pm index ba2abfbf..3f88c92b 100644 --- a/program/bindings/perl-shared/RRDs.pm +++ b/program/bindings/perl-shared/RRDs.pm @@ -33,6 +33,7 @@ RRDs - Access RRDtool as a shared module RRDs::times(start, end) RRDs::dump ... RRDs::restore ... + RRDs::flush ... =head1 DESCRIPTION diff --git a/program/bindings/perl-shared/RRDs.xs b/program/bindings/perl-shared/RRDs.xs index 25d44a51..3cf1d247 100644 --- a/program/bindings/perl-shared/RRDs.xs +++ b/program/bindings/perl-shared/RRDs.xs @@ -444,3 +444,13 @@ rrd_restore(...) OUTPUT: RETVAL +int +rrd_flush(...) + PROTOTYPE: @ + PREINIT: + int i; + char **argv; + CODE: + rrdcode(rrd_cmd_flush); + OUTPUT: + RETVAL diff --git a/program/bindings/python/rrdtoolmodule.c b/program/bindings/python/rrdtoolmodule.c index 27717207..bd16da17 100644 --- a/program/bindings/python/rrdtoolmodule.c +++ b/program/bindings/python/rrdtoolmodule.c @@ -516,6 +516,34 @@ static PyObject *PyRRD_updatev( return r; } +static char PyRRD_flush__doc__[] = + "flush(args..): flush RRD files from memory\n" + " flush [--daemon address] file [file ...]"; + +static PyObject *PyRRD_flush( + PyObject UNUSED(*self), + PyObject * args) +{ + PyObject *r; + int argc; + char **argv; + + if (create_args("flush", args, &argc, &argv) < 0) + return NULL; + + if (rrd_cmd_flush(argc, argv) != 0) { + PyErr_SetString(ErrorObject, rrd_get_error()); + rrd_clear_error(); + r = NULL; + } else { + Py_INCREF(Py_None); + r = Py_None; + } + + destroy_args(&argv); + return r; +} + /* List of methods defined in the module */ #define meth(name, func, doc) {name, (PyCFunction)func, METH_VARARGS, doc} @@ -531,6 +559,7 @@ static PyMethodDef _rrdtool_methods[] = { meth("info", PyRRD_info, PyRRD_info__doc__), meth("graphv", PyRRD_graphv, PyRRD_graphv__doc__), meth("updatev", PyRRD_updatev, PyRRD_updatev__doc__), + meth("flush", PyRRD_flush, PyRRD_flush__doc__), {NULL, NULL, 0, NULL} }; diff --git a/program/bindings/ruby/main.c b/program/bindings/ruby/main.c index 551203bf..408994f1 100644 --- a/program/bindings/ruby/main.c +++ b/program/bindings/ruby/main.c @@ -144,6 +144,13 @@ VALUE rb_rrd_update( return rrd_call(rrd_update, args); } +VALUE rb_rrd_flush( + VALUE self, + VALUE args) +{ + return rrd_call(rrd_cmd_flush, args); +} + /* Calls Returning Data via the Info Interface */ @@ -327,6 +334,7 @@ void Init_RRD( rb_define_module_function(mRRD, "restore", rb_rrd_restore, -2); rb_define_module_function(mRRD, "tune", rb_rrd_tune, -2); rb_define_module_function(mRRD, "update", rb_rrd_update, -2); + rb_define_module_function(mRRD, "flush", rb_rrd_flush, -2); rb_define_module_function(mRRD, "info", rb_rrd_info, -2); rb_define_module_function(mRRD, "updatev", rb_rrd_updatev, -2); rb_define_module_function(mRRD, "graphv", rb_rrd_graphv, -2); diff --git a/program/bindings/tcl/tclrrd.c b/program/bindings/tcl/tclrrd.c index 7f604d98..f8a3c845 100644 --- a/program/bindings/tcl/tclrrd.c +++ b/program/bindings/tcl/tclrrd.c @@ -230,6 +230,30 @@ static int Rrd_Dump( return TCL_OK; } +/* Thread-safe version */ +static int Rrd_Flush( + ClientData __attribute__((unused)) clientData, + Tcl_Interp *interp, + int argc, + CONST84 char *argv[]) +{ + if (argc < 2) { + Tcl_AppendResult(interp, "RRD Error: needs rrd filename", + (char *) NULL); + return TCL_ERROR; + } + + rrd_cmd_flush(argc, (char**)argv); + + if (rrd_test_error()) { + Tcl_AppendResult(interp, "RRD Error: ", + rrd_get_error(), (char *) NULL); + rrd_clear_error(); + return TCL_ERROR; + } + + return TCL_OK; +} /* Thread-safe version */ @@ -626,6 +650,7 @@ typedef struct { static CmdInfo rrdCmds[] = { {"Rrd::create", Rrd_Create, 1}, /* Thread-safe version */ {"Rrd::dump", Rrd_Dump, 0}, /* Thread-safe version */ + {"Rrd::flush", Rrd_Flush, 0}, {"Rrd::last", Rrd_Last, 0}, /* Thread-safe version */ {"Rrd::lastupdate", Rrd_Lastupdate, 0}, /* Thread-safe version */ {"Rrd::update", Rrd_Update, 1}, /* Thread-safe version */ diff --git a/program/doc/rrdflush.pod b/program/doc/rrdflush.pod index 514bd35f..5dbc60a7 100644 --- a/program/doc/rrdflush.pod +++ b/program/doc/rrdflush.pod @@ -4,21 +4,23 @@ rrdflush - Flush the values for a spcific RRD file from memory. =head1 SYNOPSIS -B B I +B B S<[B<--daemon> I
]> +I [I ...] =head1 DESCRIPTION -The B function connects to L, the RRD caching daemon, and -issues a "flush" command for the given file. The daemon will put this file to -the head of the update queue so it is written "soon". The status will be -returned only after the file's pending updates have been written to disk. +The B function connects to L, the RRD caching daemon, +and issues a "flush" command for the given files. The daemon will put the +files to the head of the update queue so they are written "soon". The +status will be returned only after the files' pending updates have been +written to disk. =over 8 =item I -The name of the B that is to be written to disk. +The name(s) of the B file(s) that are to be written to disk. =item B<--daemon> I
diff --git a/program/src/rrd_flush.c b/program/src/rrd_flush.c index 218a65a4..2d8df3ae 100644 --- a/program/src/rrd_flush.c +++ b/program/src/rrd_flush.c @@ -26,6 +26,7 @@ int rrd_cmd_flush (int argc, char **argv) { char *opt_daemon = NULL; int status; + int i; /* initialize getopt */ optind = 0; @@ -65,9 +66,9 @@ int rrd_cmd_flush (int argc, char **argv) } } /* while (42) */ - if ((argc - optind) != 1) + if ((argc - optind) < 1) { - rrd_set_error ("Usage: rrdtool %s [--daemon ] ", argv[0]); + rrd_set_error ("Usage: rrdtool %s [--daemon ] [ ...]", argv[0]); return (-1); } @@ -85,7 +86,12 @@ int rrd_cmd_flush (int argc, char **argv) return (-1); } - status = rrdc_flush(argv[optind]); + status = 0; + for (int i = optind; i < argc; i++) + { + status = rrdc_flush(argv[i]); + if (status) break; + } return ((status == 0) ? 0 : -1); } /* int rrd_flush */ -- 2.30.2