Permalink
Browse files

implement built-in statistics dumper using the 'carbon' protocol, whi…

…ch is also understood by metronome
  • Loading branch information...
1 parent d4eba26 commit 2c78bd5712aeda8f4505a9907d4296870da0fe0b @ahupowerdns ahupowerdns committed Apr 2, 2014
Showing with 58 additions and 3 deletions.
  1. +1 −1 pdns/Makefile.am
  2. +1 −1 pdns/iputils.hh
  3. +10 −0 pdns/pdns_recursor.cc
  4. +45 −0 pdns/rec-carbon.cc
  5. +1 −1 pdns/syncres.hh
View
@@ -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)
View
@@ -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
View
@@ -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;
View
@@ -0,0 +1,45 @@
+#include "mtasker.hh"
+#include "syncres.hh"
+#include "rec_channel.hh"
+#include "iputils.hh"
+#include "logger.hh"
+#include "arguments.hh"
+#include <boost/foreach.hpp>
+
+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<string,string> 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."<<val.first<<' '<<val.second<<' '<<now<<"\r\n";
+ }
+ const string msg = str.str();
+
+ int ret=asendtcp(msg, &s); // this will actually do the right thing waiting on the connect
+ if(ret < 0)
+ L<<Logger::Warning<<"Error writing carbon data to "<<remote.toStringWithPort()<<": "<<strerror(errno)<<endl;
+ if(ret==0)
+ L<<Logger::Warning<<"Timeout connecting/writing carbon data to "<<remote.toStringWithPort();
+ }
+catch(PDNSException& e)
+{
+ L<<Logger::Error<<"Error in carbon thread: "<<e.reason<<endl;
+}
+catch(std::exception& e)
+{
+ L<<Logger::Error<<"Error in carbon thread: "<<e.what()<<endl;
+}
View
@@ -637,5 +637,5 @@ uint64_t* pleaseGetPacketCacheHits();
uint64_t* pleaseGetPacketCacheSize();
uint64_t* pleaseWipeCache(const std::string& canon);
uint64_t* pleaseWipeAndCountNegCache(const std::string& canon);
-
+void doCarbonDump(void*);
#endif

0 comments on commit 2c78bd5

Please sign in to comment.