From: Gibheer Date: Tue, 11 Sep 2018 18:39:39 +0000 (+0200) Subject: add more variables to carbon keys X-Git-Tag: auth-4.2.0-alpha1~49^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0d4aa0b2eb04793bc570d5e02f47cc120b9de7d;p=thirdparty%2Fpdns.git add more variables to carbon keys 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. --- diff --git a/docs/settings.rst b/docs/settings.rst index 8f8d2d88b6..7a158ef71c 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -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`` diff --git a/pdns/auth-carbon.cc b/pdns/auth-carbon.cc index 3913763009..dd9ffaf34b 100644 --- a/pdns/auth-carbon.cc +++ b/pdns/auth-carbon.cc @@ -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 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."< 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."<