]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
add more variables to dnsdist carbon keys
authorGibheer <gibheer+git@zero-knowledge.org>
Tue, 11 Sep 2018 18:48:13 +0000 (20:48 +0200)
committerGibheer <gibheer+git@zero-knowledge.org>
Thu, 20 Sep 2018 09:42:45 +0000 (11:42 +0200)
dnsdist provides a couple metrics through the carbon system, which were
not variable enough to be used in larger environments.

With this commit two more variables are introduced, namespace and
instance, to make it easier to group metrics in different groups.

pdns/dnsdist-carbon.cc
pdns/dnsdist.hh

index 860657d586b0d16c20aace766898ff508d9a1c47..0e879ae6a0da4ca03ce2e76b62c5f651f100f56d 100644 (file)
@@ -54,6 +54,10 @@ try
 
     for (const auto& conf : *localCarbon) {
       const auto& server = conf.server;
+      std::string namespace_name = conf.namespace_name;
+      if(namespace_name.empty()) {
+        namespace_name="dnsdist";
+      }
       std::string hostname = conf.ourname;
       if(hostname.empty()) {
         char tmp[80];
@@ -64,6 +68,10 @@ try
         hostname=tmp;
         boost::replace_all(hostname, ".", "_");
       }
+      std::string instance_name = conf.instance_name;
+      if(instance_name.empty()) {
+        instance_name="main";
+      }
 
       try {
         Socket s(server.sin4.sin_family, SOCK_STREAM);
@@ -72,7 +80,7 @@ try
         ostringstream str;
         time_t now=time(0);
         for(const auto& e : g_stats.entries) {
-          str<<"dnsdist."<<hostname<<".main."<<e.first<<' ';
+          str<<namespace_name<<"."<<hostname<<"."<<instance_name<<"."<<e.first<<' ';
           if(const auto& val = boost::get<DNSDistStats::stat_t*>(&e.second))
             str<<(*val)->load();
           else if (const auto& dval = boost::get<double*>(&e.second))
@@ -85,7 +93,7 @@ try
         for(const auto& state : *states) {
           string serverName = state->name.empty() ? (state->remote.toString() + ":" + std::to_string(state->remote.getPort())) : state->getName();
           boost::replace_all(serverName, ".", "_");
-          const string base = "dnsdist." + hostname + ".main.servers." + serverName + ".";
+          const string base = instance_name + "." + hostname + "." + instance_name + ".servers." + serverName + ".";
           str<<base<<"queries" << ' ' << state->queries.load() << " " << now << "\r\n";
           str<<base<<"drops" << ' ' << state->reuseds.load() << " " << now << "\r\n";
           str<<base<<"latency" << ' ' << (state->availability != DownstreamState::Availability::Down ? state->latencyUsec/1000.0 : 0) << " " << now << "\r\n";
@@ -98,7 +106,7 @@ try
 
           string frontName = front->local.toString() + ":" + std::to_string(front->local.getPort()) +  (front->udpFD >= 0 ? "_udp" : "_tcp");
           boost::replace_all(frontName, ".", "_");
-          const string base = "dnsdist." + hostname + ".main.frontends." + frontName + ".";
+          const string base = namespace_name + "." + hostname + "." + instance_name + ".frontends." + frontName + ".";
           str<<base<<"queries" << ' ' << front->queries.load() << " " << now << "\r\n";
         }
         auto localPools = g_pools.getLocal();
@@ -108,7 +116,7 @@ try
           if (poolName.empty()) {
             poolName = "_default_";
           }
-          const string base = "dnsdist." + hostname + ".main.pools." + poolName + ".";
+          const string base = namespace_name + "." + hostname + "." + instance_name + ".pools." + poolName + ".";
           const std::shared_ptr<ServerPool> pool = entry.second;
           str<<base<<"servers" << " " << pool->countServers(false) << " " << now << "\r\n";
           str<<base<<"servers-up" << " " << pool->countServers(true) << " " << now << "\r\n";
index c66e1f217b5a005958be8871e3f83e2679e69841..a875b9d6b74a7dbf348253f1165230e67ea605f5 100644 (file)
@@ -874,7 +874,9 @@ void removeServerFromPool(pools_t& pools, const string& poolName, std::shared_pt
 struct CarbonConfig
 {
   ComboAddress server;
+  std::string namespace_name;
   std::string ourname;
+  std::string instance_name;
   unsigned int interval;
 };