From 952d3fcbe0582cfeb95500da58cf8e038a864e52 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Sun, 6 Apr 2014 14:19:01 +0200 Subject: [PATCH] implement carbon/graphite stats for powerdns auth too, clean up some whitespace here and there --- pdns/Makefile.am | 2 +- pdns/auth-carbon.cc | 80 ++++++++++++++++++++++++++++++++++++++++++ pdns/common_startup.cc | 11 +++--- pdns/common_startup.hh | 4 +-- pdns/dynhandler.cc | 1 - pdns/receiver.cc | 1 - pdns/sstuff.hh | 5 +++ pdns/statbag.cc | 3 -- pdns/statbag.hh | 3 +- 9 files changed, 96 insertions(+), 14 deletions(-) create mode 100644 pdns/auth-carbon.cc diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 251417fa7c..5acc3b6f29 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -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 index 0000000000..8af852ff11 --- /dev/null +++ b/pdns/auth-carbon.cc @@ -0,0 +1,80 @@ +#include "statbag.hh" +#include "logger.hh" +#include "iputils.hh" +#include "sstuff.hh" +#include "arguments.hh" +#include "common_startup.hh" +#include + +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 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."< 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) diff --git a/pdns/common_startup.hh b/pdns/common_startup.hh index aeae738ad4..d08d303378 100644 --- a/pdns/common_startup.hh +++ b/pdns/common_startup.hh @@ -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; diff --git a/pdns/dynhandler.cc b/pdns/dynhandler.cc index 3510a7c259..bedf7f65a0 100644 --- a/pdns/dynhandler.cc +++ b/pdns/dynhandler.cc @@ -53,7 +53,6 @@ string DLQuitHandler(const vector&parts, Utility::pid_t ppid) L<