]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
add more variables to carbon keys
authorGibheer <gibheer+git@zero-knowledge.org>
Tue, 11 Sep 2018 18:39:39 +0000 (20:39 +0200)
committerGibheer <gibheer+git@zero-knowledge.org>
Thu, 20 Sep 2018 09:42:45 +0000 (11:42 +0200)
The carbon key had the option to overwrite the hostname with a custom
one. But it was not possible to change either the instance or namespace,
which makes it harder to use in environments where multiple powerdns
instances are used for different purposes.

With this commit it is now possible to change the namespace and instance
part of the carbon key string. This makes it possible to differentiate
at more points or even group them easier together with other metrics,
for example the database used by pdns.

docs/settings.rst
pdns/auth-carbon.cc
pdns/common_startup.cc
pdns/rec-carbon.cc
pdns/recursordist/docs/settings.rst

index 8f8d2d88b6bb3197ef34e5f3fb2b15c745d49be2..7a158ef71c8a71bf24e3d47ab036f0b53e240538 100644 (file)
@@ -177,6 +177,18 @@ Also AXFR a zone from a master with a lower serial.
 
 Seconds to store packets in the :ref:`packet-cache`.
 
+.. _setting-carbon-namespace:
+
+``carbon-namespace``
+--------------------
+
+-  String
+-  Default: pdns
+
+Set the namespace or first string of the metric key. Be careful not to include
+any dots in this setting, unless you know what you are doing.
+See :ref:`metricscarbon`
+
 .. _setting-carbon-ourname:
 
 ``carbon-ourname``
@@ -189,6 +201,18 @@ If sending carbon updates, if set, this will override our hostname. Be
 careful not to include any dots in this setting, unless you know what
 you are doing. See :ref:`metricscarbon`
 
+.. _setting-carbon-instance:
+
+``carbon-instance``
+-------------------
+
+-  String
+-  Default: auth
+
+Set the instance or third string of the metric key. Be careful not to include
+any dots in this setting, unless you know what you are doing.
+See :ref:`metricscarbon`
+
 .. _setting-carbon-server:
 
 ``carbon-server``
index 39137630091c1a1accb7b1c2c4dd16889942813e..dd9ffaf34bf8c16a97fa133ab400ef8f4002bc36 100644 (file)
@@ -36,6 +36,10 @@ try
 {
   extern StatBag S;
 
+  string namespace_name=arg()["carbon-namespace"];
+  if(namespace_name.empty()) {
+    namespace_name="pdns";
+  }
   string hostname=arg()["carbon-ourname"];
   if(hostname.empty()) {
     char tmp[80];
@@ -46,6 +50,10 @@ try
     hostname=tmp;
     boost::replace_all(hostname, ".", "_");
   }
+  string instance_name=arg()["carbon-instancename"];
+  if(instance_name.empty()) {
+    instance_name="auth";
+  }
 
   vector<string> carbonServers;
   stringtok(carbonServers, arg()["carbon-server"], ", ");
@@ -61,7 +69,7 @@ try
     ostringstream str;
     time_t now=time(0);
     for(const string& entry : entries) {
-      str<<"pdns."<<hostname<<".auth."<<entry<<' '<<S.read(entry)<<' '<<now<<"\r\n";
+      str<<namespace_name<<'.'<<hostname<<'.'<<instance_name<<'.'<<entry<<' '<<S.read(entry)<<' '<<now<<"\r\n";
     }
     msg = str.str();
 
index 2a05f069010e1b684e1bd9a2e59c563509b773dd..0f7dab59ccf2d30951fbb98e02e4f1a50a20e071 100644 (file)
@@ -154,7 +154,9 @@ void declareArguments()
   ::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-namespace", "If set overwrites the first part of the carbon string)=");
   ::arg().set("carbon-ourname", "If set, overrides our reported hostname for carbon stats")="";
+  ::arg().set("carbon-instancename", "If set overwrites the the instance name default)=");
   ::arg().set("carbon-server", "If set, send metrics in carbon (graphite) format to this server IP address")="";
   ::arg().set("carbon-interval", "Number of seconds between carbon (graphite) updates")="30";
 
index 69e75a8898d64ba66ec53dbefcd7be6cb75b57ae..b8f4e258c6355c6130e1412a0397d036aa03f2df 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;
@@ -53,7 +63,7 @@ try
       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();
     }
index 276365c257bc99fad00d874ece7219f986ed7905..4e82c2ed93f090274228f00cbc2a94b2fe5a2042 100644 (file)
@@ -136,6 +136,14 @@ DNSSEC is not supported. Example:
 If sending carbon updates, this is the interval between them in seconds.
 See :doc:`metrics`.
 
+.. _setting-carbon-namespace:
+
+``carbon-namespace``
+--------------------
+-  String
+
+Change the namespace or first string of the metric key. The default is pdns.
+
 .. _setting-carbon-ourname:
 
 ``carbon-ourname``
@@ -146,6 +154,14 @@ If sending carbon updates, if set, this will override our hostname.
 Be careful not to include any dots in this setting, unless you know what you are doing.
 See :ref:`metricscarbon`.
 
+.. _setting-carbon-instance:
+
+``carbon-instance``
+--------------------
+-  String
+
+Change the instance or third string of the metric key. The default is recursor.
+
 .. _setting-carbon-server:
 
 ``carbon-server``