]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
implement built-in statistics dumper using the 'carbon' protocol, which is also under...
authorbert hubert <bert.hubert@netherlabs.nl>
Wed, 2 Apr 2014 21:43:46 +0000 (23:43 +0200)
committerbert hubert <bert.hubert@netherlabs.nl>
Wed, 2 Apr 2014 21:43:46 +0000 (23:43 +0200)
pdns/Makefile.am
pdns/iputils.hh
pdns/pdns_recursor.cc
pdns/rec-carbon.cc [new file with mode: 0644]
pdns/syncres.hh

index 055224cdf51b03ef1d02af5fc06df8eb149acc22..251417fa7c4e2fc9419f9c58b78f2a964a21cef5 100644 (file)
@@ -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)
index decbb606dc70a469b1f9212d5bb5e00a435b579c..6b15f4b2134bc814d184397161e839f0a838a9f9 100644 (file)
@@ -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
index 52ca7506eac4a3e6f5e29530622d9ccc31aae4b3..fb8f4d4c1c928fcfe5fef53b94623e82838fa405 100644 (file)
@@ -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 (file)
index 0000000..f96ef39
--- /dev/null
@@ -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;
+}
index 428ee58f558e0dc212cc7386c36fc0a3c3a3ab25..eb48af17da76824e7003884b4d338c562c9245f0 100644 (file)
@@ -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