]> git.ipfire.org Git - thirdparty/pdns.git/blobdiff - pdns/rec-carbon.cc
rec: ensure correct service user on debian
[thirdparty/pdns.git] / pdns / rec-carbon.cc
index 5cf085ba9e816b2767a5d5a13863e7bf703cbcd4..5f2b92fa08e42db31a8d5f65c2488bb9bf65556c 100644 (file)
@@ -14,17 +14,24 @@ void doCarbonDump(void*)
 try
 {
   string hostname;
+  string instance_name;
+  string namespace_name;
   vector<string> carbonServers;
 
   {
     Lock l(&g_carbon_config_lock);
     stringtok(carbonServers, arg()["carbon-server"], ", ");
+    namespace_name=arg()["carbon-namespace"];
     hostname=arg()["carbon-ourname"];
+    instance_name=arg()["carbon-instance"];
   }
 
   if(carbonServers.empty())
     return;
 
+  if(namespace_name.empty()) {
+    namespace_name="pdns";
+  }
   if(hostname.empty()) {
     char tmp[80];
     memset(tmp, 0, sizeof(tmp));
@@ -35,6 +42,9 @@ try
     hostname=tmp;
     boost::replace_all(hostname, ".", "_");    
   }
+  if(instance_name.empty()) {
+    instance_name="recursor";
+  }
 
   registerAllStats();
   string msg;
@@ -47,33 +57,33 @@ try
  
     if(msg.empty()) {
       typedef map<string,string> all_t;
-      all_t all=getAllStatsMap();
+      all_t all=getAllStatsMap(StatComponent::Carbon);
       
       ostringstream str;
       time_t now=time(0);
       
       for(const all_t::value_type& val :  all) {
-        str<<"pdns."<<hostname<<".recursor."<<val.first<<' '<<val.second<<' '<<now<<"\r\n";
+        str<<namespace_name<<'.'<<hostname<<'.'<<instance_name<<'.'<<val.first<<' '<<val.second<<' '<<now<<"\r\n";
       }
       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;
+      g_log<<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()<<endl;
+      g_log<<Logger::Warning<<"Timeout connecting/writing carbon data to "<<remote.toStringWithPort()<<endl;
   }
  }
 catch(PDNSException& e)
 {
-  L<<Logger::Error<<"Error in carbon thread: "<<e.reason<<endl;
+  g_log<<Logger::Error<<"Error in carbon thread: "<<e.reason<<endl;
 }
 catch(std::exception& e)
 {
-  L<<Logger::Error<<"Error in carbon thread: "<<e.what()<<endl;
+  g_log<<Logger::Error<<"Error in carbon thread: "<<e.what()<<endl;
 }
 catch(...)
 {
-  L<<Logger::Error<<"Unknown error in carbon thread"<<endl;
+  g_log<<Logger::Error<<"Unknown error in carbon thread"<<endl;
 }