From: oetiker Date: Fri, 7 Nov 2008 14:07:53 +0000 (+0000) Subject: As some of you may know that I have created a patch for rrdtool 1.2 a few years... X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=commitdiff_plain;h=caa9411848390bf066b02588c4525731bee190c5 As some of you may know that I have created a patch for rrdtool 1.2 a few years ago, so that a database could be queried for values for graphing. The patch has been mostly rewritten and the following changes have been made: * high dependency on mysql has been reduced by avoiding the temporary tables (which was bad for mysql replication) * The number of executed SQL-Statements for one CDEF has been reduced to 1 compared to 11 SQLs (including CREATE TEMPORARY TABLE) - for patch against version 1.2 * All consolidation is done in rrdtool itself (MIN,MAX,AVERAGE) * Additional consolidation functions are COUNT and SIGMA, which give information on statistics on a per "time-bin" basis. * All these consolidation values are always returned as separate columns, that are returned by RRD and the consolidation function given as Argument is ignored. Main reason is that this way there is only one call to rrd_fetcht and thus the database even if we need to fetch for example min, avg and max. Compare this to 3 calls in case of different consolidation functions - and if you want to get SIGMA and COUNT as well it is still only one call to the backend and the database. * Some previous existing features have been taken out at the moment to allow for this reduced set of SQL queries. o prediction using the values from the last X days at the same time o the corresponding sigma calculation * The idea is to create generic CDEF's that will do the same thing, but that is also available when using RRD-files (similar to TREND, but with another scope) This will get posted as a separate patch. * Overall performance should be much better and the patch as a whole simpler. * The patch also includes modifications to the configuration infrastructure, to make libdbi support optional. -- Martin Sperl git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1650 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 9b485a6..02b72a7 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -77,7 +77,7 @@ Wim Heirman --units=si option Wolfgang Schrimm xport function Wrolf Courtney (HP-UX) hendrik visage -Martin Sperl (CDEF prediction functions) +Martin Sperl (CDEF prediction functions, libdbi) Philippe Simonet (Windows Binaries) Alexander Lucke (lucke with dns-net.de) of DNS:NET Internet Services (www.dns-net.de) http://rrdtool.org diff --git a/configure.ac b/configure.ac index f08b4e9..224f013 100644 --- a/configure.ac +++ b/configure.ac @@ -468,6 +468,25 @@ AC_LANG_POP(C) CONFIGURE_PART(Find 3rd-Party Libraries) +AC_ARG_ENABLE(libdbi,[ --disable-libdbi do not build in support for libdbi],[have_libdbi=no],[ + XXX=$LIBS + LIBS="$LIBS -ldbi -ldl" + AC_MSG_CHECKING(for libdbi) + AC_LINK_IFELSE( + [AC_LANG_PROGRAM([[#include ]], + [[dbi_initialize(NULL)]] + ) + ],[AC_DEFINE(HAVE_LIBDBI,[1],[have got libdbi installed]) + AC_MSG_RESULT([yes]) + have_libdbi=yes + ],[LIBS=$XXX + AC_MSG_RESULT([no]) + have_libdbi=no + exit 1 + ] + ) +]) +AM_CONDITIONAL(BUILD_LIBDBI,[test $have_libdbi != no]) AM_CONDITIONAL(BUILD_RRDCGI,[test $enable_rrdcgi != no]) @@ -926,6 +945,7 @@ echo " Build Python Bindings: $enable_python" echo " Build rrdcgi: $enable_rrdcgi" echo " Build librrd MT: $enable_pthread" echo " Link with libintl: $enable_libintl" +echo " With libDBI: $have_libdbi" echo echo " Libraries: $ALL_LIBS" echo diff --git a/src/Makefile.am b/src/Makefile.am index 9c14263..8913e4a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -58,6 +58,10 @@ noinst_HEADERS = \ fnv.h rrd_graph.h \ rrd_is_thread_safe.h +if BUILD_LIBDBI +RRD_C_FILES += rrd_fetch_libdbi.c +endif + if BUILD_GETOPT noinst_HEADERS += rrd_getopt.h UPD_C_FILES += rrd_getopt.c rrd_getopt1.c diff --git a/src/rrd_fetch.c b/src/rrd_fetch.c index d821dfa..83b0cf6 100644 --- a/src/rrd_fetch.c +++ b/src/rrd_fetch.c @@ -235,6 +235,15 @@ int rrd_fetch_fn( *start, *end, *step); #endif +#ifdef HAVE_LIBDBI + /* handle libdbi datasources */ + if (strncmp("sql",filename,3)==0) { + if (filename[3]==filename[4]) { + return rrd_fetch_fn_libdbi(filename,cf_idx,start,end,step,ds_cnt,ds_namv,data); + } + } +#endif + rrd_init(&rrd); rrd_file = rrd_open(filename, &rrd, RRD_READONLY); if (rrd_file == NULL) diff --git a/src/rrd_tool.h b/src/rrd_tool.h index 43781da..f58cd78 100644 --- a/src/rrd_tool.h +++ b/src/rrd_tool.h @@ -92,6 +92,16 @@ extern "C" { char ***ds_namv, rrd_value_t **data); + +#ifdef HAVE_LIBDBI +int rrd_fetch_fn_libdbi(char *filename, enum cf_en cf_idx, + time_t *start,time_t *end, + unsigned long *step, + unsigned long *ds_cnt, + char ***ds_namv, + rrd_value_t **data); +#endif + #define RRD_READONLY (1<<0) #define RRD_READWRITE (1<<1) #define RRD_CREAT (1<<2)