]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
implement carbon/graphite stats for powerdns auth too, clean up some whitespace here...
authorbert hubert <bert.hubert@netherlabs.nl>
Sun, 6 Apr 2014 12:19:01 +0000 (14:19 +0200)
committerbert hubert <bert.hubert@netherlabs.nl>
Sun, 6 Apr 2014 12:19:01 +0000 (14:19 +0200)
pdns/Makefile.am
pdns/auth-carbon.cc [new file with mode: 0644]
pdns/common_startup.cc
pdns/common_startup.hh
pdns/dynhandler.cc
pdns/receiver.cc
pdns/sstuff.hh
pdns/statbag.cc
pdns/statbag.hh

index 251417fa7c4e2fc9419f9c58b78f2a964a21cef5..5acc3b6f29c84a010990a33507829aefaae43128 100644 (file)
@@ -63,7 +63,7 @@ dnsseckeeper.hh dnssecinfra.hh base32.hh dns.cc dnssecsigner.cc polarrsakeyinfra
 sha.hh md5.hh signingpipe.cc signingpipe.hh dnslabeltext.cc lua-pdns.cc lua-auth.cc lua-auth.hh serialtweaker.cc \
 ednssubnet.cc ednssubnet.hh cachecleaner.hh json.cc json.hh \
 version.hh version.cc rfc2136handler.cc responsestats.cc responsestats.hh \
-comment.hh
+comment.hh auth-carbon.cc
 
 
 pdns_server_LDFLAGS=@moduleobjects@ @modulelibs@ @DYNLINKFLAGS@ @LIBDL@ @THREADFLAGS@  $(BOOST_SERIALIZATION_LDFLAGS) -rdynamic
diff --git a/pdns/auth-carbon.cc b/pdns/auth-carbon.cc
new file mode 100644 (file)
index 0000000..8af852f
--- /dev/null
@@ -0,0 +1,80 @@
+#include "statbag.hh"
+#include "logger.hh"
+#include "iputils.hh"
+#include "sstuff.hh"
+#include "arguments.hh"
+#include "common_startup.hh"
+#include <boost/foreach.hpp>
+
+using namespace std;
+
+void* carbonDumpThread(void*)
+try
+{
+  extern StatBag S;
+
+  for(int numloops=0;;++numloops) {
+    if(arg()["carbon-server"].empty()) {
+      sleep(1);
+      continue;
+    }
+    if(numloops)
+      sleep(arg().asNum("carbon-interval"));
+
+    try {
+      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
+      
+      vector<string> entries = S.getEntries();
+      
+      ostringstream str;
+      time_t now=time(0);
+      string hostname=arg()["carbon-ourname"];
+      if(hostname.empty()) {
+       char tmp[80];
+       memset(tmp, 0, sizeof(tmp));
+       gethostname(tmp, sizeof(tmp));
+       hostname=tmp;
+      }
+      BOOST_FOREACH(const string& entry, entries) {
+       str<<"pdns."<<hostname<<".auth."<<entry<<' '<<S.read(entry)<<' '<<now<<"\r\n";
+      }
+      const string msg = str.str();
+      
+      int ret = waitForRWData(s.getHandle(), false, 1 , 0); 
+      if(ret <= 0 ) {
+       L<<Logger::Warning<<"Unable to write data to carbon server on "<<remote.toStringWithPort();
+       L<<": "<< (ret<0 ? strerror(errno) : "Timeout")<<endl;
+       continue;
+      }
+      s.setBlocking();
+      ret=writen2(s.getHandle(), msg.c_str(), msg.size());
+      if(ret < 0)
+       L<<Logger::Warning<<"Error writing carbon data to "<<remote.toStringWithPort()<<": "<<strerror(errno)<<endl;
+      if(ret==0)
+       L<<Logger::Warning<<"EOF writing carbon data to "<<remote.toStringWithPort();
+    }
+    catch(exception& e) {
+      L<<Logger::Warning<<"Problem sending carbon data: "<<e.what()<<endl;
+    }
+  }
+  return 0;
+}
+catch(exception& e)
+{
+  L<<Logger::Error<<"Carbon thread died: "<<e.what()<<endl;
+  return 0;
+}
+catch(PDNSException& e)
+{
+  L<<Logger::Error<<"Carbon thread died, PDNSException: "<<e.reason<<endl;
+  return 0;
+}
+catch(...)
+{
+  L<<Logger::Error<<"Carbon thread died"<<endl;
+  return 0;
+}
index a9a8c8100606d3dd22315d9a353e67599883ac32..aadc6d568e1de5852e636e9105ca2aa5e3df3478 100644 (file)
@@ -26,7 +26,6 @@ bool g_anyToTcp;
 bool g_addSuperfluousNSEC3;
 typedef Distributor<DNSPacket,DNSPacket,PacketHandler> DNSDistributor;
 
-
 ArgvMap theArg;
 StatBag S;  //!< Statistics are gathered across PDNS via the StatBag class S
 PacketCache PC; //!< This is the main PacketCache, shared across all threads
@@ -122,7 +121,11 @@ void declareArguments()
   ::arg().setSwitch("out-of-zone-additional-processing","Do out of zone additional processing")="yes";
   ::arg().setSwitch("do-ipv6-additional-processing", "Do AAAA additional processing")="yes";
   ::arg().setSwitch("query-logging","Hint backends that queries should be logged")="no";
-  
+
+  ::arg().set("carbon-ourname", "If set, overrides our reported hostname for carbon stats")="";
+  ::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("cache-ttl","Seconds to store packets in the PacketCache")="20";
   ::arg().set("recursive-cache-ttl","Seconds to store packets for recursive queries in the PacketCache")="10";
   ::arg().set("negquery-cache-ttl","Seconds to store negative query results in the QueryCache")="60";
@@ -273,7 +276,6 @@ void *qthread(void *number)
       }
     }
 
-
     if(!(P=NS->receive(&question))) { // receive a packet         inline
       continue;                    // packet was broken, try again
     }
@@ -391,7 +393,8 @@ void mainthread()
 
   if(TN)
     TN->go(); // tcp nameserver launch
-    
+
+  pthread_create(&qtid,0,carbonDumpThread, 0); // runs even w/o carbon, might change @ runtime    
   //  fork(); (this worked :-))
   unsigned int max_rthreads= ::arg().asNum("receiver-threads");
   for(unsigned int n=0; n < max_rthreads; ++n)
index aeae738ad4b9242f1a601adc9c968cf86321c1dc..d08d303378841206de58c243748bfee1c6c58cec 100644 (file)
@@ -1,6 +1,6 @@
 /*
     PowerDNS Versatile Database Driven Nameserver
-    Copyright (C) 2002  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
@@ -49,7 +49,7 @@ extern void declareArguments();
 extern void declareStats();
 extern void mainthread();
 extern int isGuarded( char ** );
-
+void* carbonDumpThread(void*);
 extern bool g_anyToTcp;
 extern bool g_addSuperfluousNSEC3;
 
index 3510a7c2594a6c183a80623ec822bc7fb16009bf..bedf7f65a04dfb9d319ed992e5ef3de55824edd7 100644 (file)
@@ -53,7 +53,6 @@ string DLQuitHandler(const vector<string>&parts, Utility::pid_t ppid)
     L<<Logger::Error<<"Scheduling exit on remote request"<<endl;
   }
   return ret;
-
 }
 
 static void dokill(int)
index ea06db21fcd131ab3f264a6cc804d6e8b522b3cd..2ec3333aff619fab5a92a9ebde18bce53ba7ad74 100644 (file)
@@ -350,7 +350,6 @@ static void UNIX_declareArguments()
   ::arg().set("chroot","If set, chroot to this directory for more security")="";
   ::arg().set("logging-facility","Log under a specific facility")="";
   ::arg().set("daemon","Operate as a daemon")="no";
-
 }
 
 static void loadModules()
index 81171f5c17f8760d8a3fb73594dd06889393647a..5a00362335e23b597de546b48a026364e3d1f3cd 100644 (file)
@@ -83,6 +83,11 @@ public:
   {
     Utility::setNonBlocking(d_socket);
   }
+  //! Set the socket to blocking
+  void setBlocking()
+  {
+    Utility::setBlocking(d_socket);
+  }
 
   void setReuseAddr()
   {
index 40a98d3f228f6d3020506eaa6ccc4642c6e9b692..58eed06d22a7e3dee97598d9555c64de7e5c4807 100644 (file)
@@ -128,19 +128,16 @@ unsigned int StatBag::readZero(const string &key)
 {
   lock();
 
-
   if(!d_stats.count(key))
     {
       unlock();
       return 0;
     }
-
   
   unsigned int tmp=*d_stats[key];
   d_stats[key]=0;
 
   unlock();
-
   return tmp;
 }
 
index 4baabbd8e011a505d3605f5ed920be3bdf5e79b1..b45e7df1e32a7e0dc8f7f12800b342b15617179a 100644 (file)
@@ -1,6 +1,6 @@
 /*
     PowerDNS Versatile Database Driven Nameserver
-    Copyright (C) 2002  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
@@ -39,7 +39,6 @@ public:
     d_items[d_pos++ % d_size]=item;
   }
 
-
   unsigned int getSize()
   {
     return d_size;