From: oetiker Date: Sat, 7 Mar 2009 10:31:51 +0000 (+0000) Subject: This 2-patch series exposes 'flush' methods to the various language X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=commitdiff_plain;h=4d2717c87ff413758caaa7942d211e642846b9b0;ds=sidebyside This 2-patch series exposes 'flush' methods to the various language bindings. git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1756 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/NEWS b/NEWS index 2c26f68..7d0c920 100644 --- a/NEWS +++ b/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/bindings/lua/rrdlua.c b/bindings/lua/rrdlua.c index a5b9fb7..2060f3b 100644 --- a/bindings/lua/rrdlua.c +++ b/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/bindings/perl-shared/RRDs.pm b/bindings/perl-shared/RRDs.pm index ba2abfb..3f88c92 100644 --- a/bindings/perl-shared/RRDs.pm +++ b/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/bindings/perl-shared/RRDs.xs b/bindings/perl-shared/RRDs.xs index 25d44a5..3cf1d24 100644 --- a/bindings/perl-shared/RRDs.xs +++ b/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/bindings/python/rrdtoolmodule.c b/bindings/python/rrdtoolmodule.c index 2771720..bd16da1 100644 --- a/bindings/python/rrdtoolmodule.c +++ b/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/bindings/ruby/main.c b/bindings/ruby/main.c index 551203b..408994f 100644 --- a/bindings/ruby/main.c +++ b/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/bindings/tcl/tclrrd.c b/bindings/tcl/tclrrd.c index 7f604d9..f8a3c84 100644 --- a/bindings/tcl/tclrrd.c +++ b/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/doc/rrdflush.pod b/doc/rrdflush.pod index 514bd35..5dbc60a 100644 --- a/doc/rrdflush.pod +++ b/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/src/rrd_flush.c b/src/rrd_flush.c index 218a65a..2d8df3a 100644 --- a/src/rrd_flush.c +++ b/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 */