From: bert hubert Date: Wed, 2 Apr 2014 21:43:46 +0000 (+0200) Subject: implement built-in statistics dumper using the 'carbon' protocol, which is also under... X-Git-Tag: rec-3.6.0-rc1~96 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2c78bd5712aeda8f4505a9907d4296870da0fe0b;p=thirdparty%2Fpdns.git implement built-in statistics dumper using the 'carbon' protocol, which is also understood by metronome --- diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 055224cdf5..251417fa7c 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -293,7 +293,7 @@ dns_random.cc \ lua-pdns.cc lua-pdns.hh lua-recursor.cc lua-recursor.hh randomhelper.cc \ recpacketcache.cc recpacketcache.hh dns.cc nsecrecords.cc base32.cc cachecleaner.hh \ ws-recursor.cc ws-recursor.hh ws-api.cc ws-api.hh webserver.cc webserver.hh \ -json.cc json.hh version.hh version.cc responsestats.cc +json.cc json.hh version.hh version.cc responsestats.cc rec-carbon.cc pdns_recursor_LDFLAGS= $(LUA_LIBS) pdns_recursor_LDADD= $(POLARSSL_LIBS) $(YAHTTP_LIBS) diff --git a/pdns/iputils.hh b/pdns/iputils.hh index decbb606dc..6b15f4b213 100644 --- a/pdns/iputils.hh +++ b/pdns/iputils.hh @@ -1,6 +1,6 @@ /* PowerDNS Versatile Database Driven Nameserver - Copyright (C) 2002 - 2011 PowerDNS.COM BV + Copyright (C) 2002 - 2014 PowerDNS.COM BV This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 52ca7506ea..fb8f4d4c1c 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -1993,6 +1993,8 @@ try bool listenOnTCP(true); + time_t last_carbon=0; + time_t carbonInterval=::arg().asNum("carbon-interval"); counter=0; // used to periodically execute certain tasks for(;;) { while(MT->schedule(&g_now)); // MTasker letting the mthreads do their thing @@ -2020,6 +2022,12 @@ try } Utility::gettimeofday(&g_now, 0); + + if(!t_id && (g_now.tv_sec - last_carbon >= carbonInterval)) { + MT->makeThread(doCarbonDump, 0); + last_carbon = g_now.tv_sec; + } + t_fdm->run(&g_now); // 'run' updates g_now for us @@ -2091,6 +2099,8 @@ int main(int argc, char **argv) ::arg().set("experimental-webserver-port", "Port of webserver to listen on") = "8082"; ::arg().set("experimental-webserver-password", "Password required for accessing the webserver") = ""; ::arg().set("experimental-api-config-dir", "Directory where REST API stores config and zones") = ""; + ::arg().set("carbon-server", "If set, send metrics in carbon (graphite) format to this server")=""; + ::arg().set("carbon-interval", "Number of seconds between carbon (graphite) updates")="30"; ::arg().set("quiet","Suppress logging of questions and answers")=""; ::arg().set("logging-facility","Facility to log messages as. 0 corresponds to local0")=""; ::arg().set("config-dir","Location of configuration directory (recursor.conf)")=SYSCONFDIR; diff --git a/pdns/rec-carbon.cc b/pdns/rec-carbon.cc new file mode 100644 index 0000000000..f96ef3970d --- /dev/null +++ b/pdns/rec-carbon.cc @@ -0,0 +1,45 @@ +#include "mtasker.hh" +#include "syncres.hh" +#include "rec_channel.hh" +#include "iputils.hh" +#include "logger.hh" +#include "arguments.hh" +#include + +void doCarbonDump(void*) +try +{ + if(arg()["carbon-server"].empty()) + return; + + RecursorControlParser rcp; // inits if needed + ComboAddress remote(arg()["carbon-server"], 2003); + Socket s(remote.sin4.sin_family, SOCK_STREAM); + + s.setNonBlocking(); + s.connect(remote); // we do the connect so the attempt happens while we gather stats + + typedef map all_t; + all_t all=getAllStatsMap(); + + ostringstream str; + time_t now=time(0); + BOOST_FOREACH(const all_t::value_type& val, all) { + str<<"pdns.recursor.localhost."<