From 0affb140bebb6f5914fbe150921e07ca3377e47b Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 3 Aug 2017 16:29:56 +0200 Subject: [PATCH] dnsdist: Don't use square brackets for IPv6 in Carbon metrics --- pdns/dnsdist-carbon.cc | 4 ++-- pdns/iputils.hh | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pdns/dnsdist-carbon.cc b/pdns/dnsdist-carbon.cc index 63e780d82..caae0bb94 100644 --- a/pdns/dnsdist-carbon.cc +++ b/pdns/dnsdist-carbon.cc @@ -84,7 +84,7 @@ try } const auto states = g_dstates.getCopy(); for(const auto& state : states) { - string serverName = state->getName(); + 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 + "."; str<queries.load() << " " << now << "\r\n"; @@ -97,7 +97,7 @@ try if (front->udpFD == -1 && front->tcpFD == -1) continue; - string frontName = front->local.toStringWithPort() + (front->udpFD >= 0 ? "_udp" : "_tcp"); + 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 + "."; str<queries.load() << " " << now << "\r\n"; diff --git a/pdns/iputils.hh b/pdns/iputils.hh index 30849cd6b..bf6ba4c9f 100644 --- a/pdns/iputils.hh +++ b/pdns/iputils.hh @@ -276,6 +276,12 @@ union ComboAddress { } void truncate(unsigned int bits) noexcept; + + uint16_t getPort() const + { + return ntohs(sin4.sin_port); + } + }; /** This exception is thrown by the Netmask class and by extension by the NetmaskGroup class */ -- 2.50.1