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
--- /dev/null
+#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;
+}
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
::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";
}
}
-
if(!(P=NS->receive(&question))) { // receive a packet inline
continue; // packet was broken, try again
}
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)
/*
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
extern void declareStats();
extern void mainthread();
extern int isGuarded( char ** );
-
+void* carbonDumpThread(void*);
extern bool g_anyToTcp;
extern bool g_addSuperfluousNSEC3;
L<<Logger::Error<<"Scheduling exit on remote request"<<endl;
}
return ret;
-
}
static void dokill(int)
::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()
{
Utility::setNonBlocking(d_socket);
}
+ //! Set the socket to blocking
+ void setBlocking()
+ {
+ Utility::setBlocking(d_socket);
+ }
void setReuseAddr()
{
{
lock();
-
if(!d_stats.count(key))
{
unlock();
return 0;
}
-
unsigned int tmp=*d_stats[key];
d_stats[key]=0;
unlock();
-
return tmp;
}
/*
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
d_items[d_pos++ % d_size]=item;
}
-
unsigned int getSize()
{
return d_size;