]> granicus.if.org Git - pdns/commitdiff
add support for carbon-ourname to override our hostname for carbon reporting if needed
authorbert hubert <bert.hubert@netherlabs.nl>
Wed, 2 Apr 2014 21:56:34 +0000 (23:56 +0200)
committerbert hubert <bert.hubert@netherlabs.nl>
Wed, 2 Apr 2014 21:56:34 +0000 (23:56 +0200)
pdns/pdns_recursor.cc
pdns/rec-carbon.cc

index fb8f4d4c1c928fcfe5fef53b94623e82838fa405..7a35121e4ed79077359d0f844064e877933b689d 100644 (file)
@@ -2099,6 +2099,7 @@ 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-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("quiet","Suppress logging of questions and answers")="";
index f96ef3970de3f4da4ac1554999ff8540dd349ce3..48056b0c3fb4b3cdf4b95e6cf29e87b534a66e3b 100644 (file)
@@ -24,8 +24,15 @@ try
 
   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 all_t::value_type& val, all) {
-    str<<"pdns.recursor.localhost."<<val.first<<' '<<val.second<<' '<<now<<"\r\n";
+    str<<"pdns.recursor."<<hostname<<"."<<val.first<<' '<<val.second<<' '<<now<<"\r\n";
   }
   const string msg = str.str();