From a8b5b7a72294a6e079b842eb75094f7e6c12a723 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 14 Jun 2019 16:58:43 +0200 Subject: [PATCH] dnsdist: Deduplicate frontends entries with carbon and prometheus --- pdns/dnsdist-carbon.cc | 16 ++++++++++++++++ pdns/dnsdist-web.cc | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/pdns/dnsdist-carbon.cc b/pdns/dnsdist-carbon.cc index 14b72e048..b0b2997c2 100644 --- a/pdns/dnsdist-carbon.cc +++ b/pdns/dnsdist-carbon.cc @@ -104,12 +104,20 @@ try str<tcpAvgQueriesPerConnection.load() << " " << now << "\r\n"; str<tcpAvgConnectionDuration.load() << " " << now << "\r\n"; } + + std::map frontendDuplicates; for(const auto& front : g_frontends) { if (front->udpFD == -1 && front->tcpFD == -1) continue; string frontName = front->local.toString() + ":" + std::to_string(front->local.getPort()) + (front->udpFD >= 0 ? "_udp" : "_tcp"); boost::replace_all(frontName, ".", "_"); + auto dupPair = frontendDuplicates.insert({frontName, 1}); + if (dupPair.second == false) { + frontName = frontName + "_" + std::to_string(dupPair.first->second); + ++dupPair.first->second; + } + const string base = namespace_name + "." + hostname + "." + instance_name + ".frontends." + frontName + "."; str<queries.load() << " " << now << "\r\n"; str<tcpDiedReadingQuery.load() << " " << now << "\r\n"; @@ -121,6 +129,7 @@ try str<tcpAvgQueriesPerConnection.load() << " " << now << "\r\n"; str<tcpAvgConnectionDuration.load() << " " << now << "\r\n"; } + auto localPools = g_pools.getLocal(); for (const auto& entry : *localPools) { string poolName = entry.first; @@ -148,6 +157,7 @@ try #ifdef HAVE_DNS_OVER_HTTPS { + std::map dohFrontendDuplicates; const string base = "dnsdist." + hostname + ".main.doh."; for(const auto& doh : g_dohlocals) { string name = doh->d_local.toStringWithPort(); @@ -156,6 +166,12 @@ try boost::replace_all(name, "[", "_"); boost::replace_all(name, "]", "_"); + auto dupPair = dohFrontendDuplicates.insert({name, 1}); + if (dupPair.second == false) { + name = name + "_" + std::to_string(dupPair.first->second); + ++dupPair.first->second; + } + vector&>> v{ {"http-connects", doh->d_httpconnects}, {"http1-queries", doh->d_http1queries}, diff --git a/pdns/dnsdist-web.cc b/pdns/dnsdist-web.cc index b9faa5583..f0ff9602c 100644 --- a/pdns/dnsdist-web.cc +++ b/pdns/dnsdist-web.cc @@ -523,12 +523,19 @@ static void connectionThread(int sock, ComboAddress remote) output << statesbase << "tcpavgconnduration" << label << " " << state->tcpAvgConnectionDuration << "\n"; } + std::map frontendDuplicates; for (const auto& front : g_frontends) { if (front->udpFD == -1 && front->tcpFD == -1) continue; string frontName = front->local.toString() + ":" + std::to_string(front->local.getPort()); string proto = (front->udpFD >= 0 ? "udp" : "tcp"); + string fullName = frontName + "_" + proto; + auto dupPair = frontendDuplicates.insert({fullName, 1}); + if (dupPair.second == false) { + frontName = frontName + "_" + std::to_string(dupPair.first->second); + ++dupPair.first->second; + } output << "dnsdist_frontend_queries{frontend=\"" << frontName << "\",proto=\"" << proto << "\"} " << front->queries.load() << "\n"; -- 2.40.0