From: Otto Moerbeek Date: Wed, 31 Aug 2022 06:43:38 +0000 (+0200) Subject: Prometheus stats plus tweaks in rec_control X-Git-Tag: rec-4.9.0-alpha0~16^2~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0dc0e4daffb9137be2eca4cc6fdaa92e4cc283f4;p=thirdparty%2Fpdns.git Prometheus stats plus tweaks in rec_control --- diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 8722a5551c..942a2b9dfe 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -941,14 +941,14 @@ static ProxyMappingStats_t* pleaseGetProxyMappingStats() static RemoteLoggerStats_t* pleaseGetRemoteLoggerStats() { - auto ret = new RemoteLoggerStats_t; + auto ret = make_unique(); if (t_protobufServers) { for (const auto& s : *t_protobufServers) { ret->emplace(std::make_pair(s->address(), s->getStats())); } } - return ret; + return ret.release(); } static string doGetProxyMappingStats() @@ -964,52 +964,52 @@ static string doGetProxyMappingStats() static RemoteLoggerStats_t* pleaseGetOutgoingRemoteLoggerStats() { - auto ret = new RemoteLoggerStats_t; + auto ret = make_unique(); if (t_outgoingProtobufServers) { for (const auto& s : *t_outgoingProtobufServers) { ret->emplace(std::make_pair(s->address(), s->getStats())); } } - return ret; + return ret.release(); } #ifdef HAVE_FSTRM static RemoteLoggerStats_t* pleaseGetFramestreamLoggerStats() { - auto ret = new RemoteLoggerStats_t; + auto ret = make_unique(); if (t_frameStreamServersInfo.servers) { for (const auto& s : *t_frameStreamServersInfo.servers) { ret->emplace(std::make_pair(s->address(), s->getStats())); } } - return ret; + return ret.release(); } #endif -static void remoteLoggerStats(const string& name, const RemoteLoggerStats_t& stats, ostringstream& os) +static void remoteLoggerStats(const string& type, const RemoteLoggerStats_t& stats, ostringstream& os) { - if (stats.size() > 0) { - std::string filler(name.size(), ' '); - os << name << "\tQueued\tPipe-\tToo-\tOther-\tAddress" << endl; - os << filler << "\t\tFull\tLarge\terror" << endl; - for (const auto& [key, entry]: stats) { - os << filler<< '\t' << entry.d_queued << '\t' << entry.d_pipeFull << '\t' << entry.d_tooLarge << '\t' << entry.d_otherError << '\t' << key << endl; - } + if (stats.empty()) { + return; + } + for (const auto& [key, entry]: stats) { + os << entry.d_queued << '\t' << entry.d_pipeFull << '\t' << entry.d_tooLarge << '\t' << entry.d_otherError << '\t' << key << '\t' << type << endl; } } static string getRemoteLoggerStats() { ostringstream os; + os << "Queued\tPipe-\tToo-\tOther-\tAddress\tType" << endl; + os << "\tFull\tLarge\terror" << endl; auto stats = broadcastAccFunction(pleaseGetRemoteLoggerStats); - remoteLoggerStats("Protobuf ", stats, os); + remoteLoggerStats("protobuf", stats, os); stats = broadcastAccFunction(pleaseGetOutgoingRemoteLoggerStats); - remoteLoggerStats("OutProtobuf", stats, os); + remoteLoggerStats("outgoingProtobuf", stats, os); #ifdef HAVE_FSTRM stats = broadcastAccFunction(pleaseGetFramestreamLoggerStats); - remoteLoggerStats("Framestream", stats, os); + remoteLoggerStats("dnstapFrameStream", stats, os); #endif return os.str(); } @@ -1259,6 +1259,36 @@ static StatsMap toProxyMappingStatsMap(const string& name) return entries; } +static StatsMap toRemoteLoggerStatsMap(const string& name) +{ + const auto pbasename = getPrometheusName(name); + StatsMap entries; + + auto stats1 = broadcastAccFunction(pleaseGetRemoteLoggerStats); + auto stats2 = broadcastAccFunction(pleaseGetOutgoingRemoteLoggerStats); + auto stats3 = broadcastAccFunction(pleaseGetFramestreamLoggerStats); + uint64_t count = 0; + for (const auto& [stats, type] : { make_pair(stats1, "protobuf") , make_pair(stats2, "outgoingProtobuf"), make_pair(stats3, "dnstapFrameStream") } ) { + for (const auto& [key, entry] : stats) { + auto keyname = pbasename + "{address=\"" + key + "\",type=\"" + type + "\",count=\""; + auto sname1 = name + "-q-" + std::to_string(count); + auto pname1 = keyname + "queued\"}"; + entries.emplace(sname1, StatsMapEntry{pname1, std::to_string(entry.d_queued)}); + auto sname2 = name + "-p-" + std::to_string(count); + auto pname2 = keyname + "pipeFull\"}"; + entries.emplace(sname2, StatsMapEntry{pname2, std::to_string(entry.d_pipeFull)}); + auto sname3 = name + "-t-" + std::to_string(count); + auto pname3 = keyname + "tooLarge\"}"; + entries.emplace(sname3, StatsMapEntry{pname3, std::to_string(entry.d_tooLarge)}); + auto sname4 = name + "-o-" + std::to_string(count); + auto pname4 = keyname + "otherError\"}"; + entries.emplace(sname4, StatsMapEntry{pname4, std::to_string(entry.d_otherError)}); + ++count; + } + } + return entries; +} + static void registerAllStats1() { addGetStat("questions", &g_stats.qcounter); @@ -1533,6 +1563,9 @@ static void registerAllStats1() addGetStat("auth-rcode-answers", []() { return toAuthRCodeStatsMap("auth-rcode-answers", g_stats.authRCode); }); + addGetStat("remote-logger", []() { + return toRemoteLoggerStatsMap("remote-logger"); + }); } void registerAllStats() diff --git a/pdns/recursordist/docs/manpages/rec_control.1.rst b/pdns/recursordist/docs/manpages/rec_control.1.rst index b3a07e7a87..1e701b4887 100644 --- a/pdns/recursordist/docs/manpages/rec_control.1.rst +++ b/pdns/recursordist/docs/manpages/rec_control.1.rst @@ -167,6 +167,9 @@ get-proxymapping-stats get-qtypelist Retrieves QType statistics. Queries from cache aren't being counted yet. +get-remotelogger-stats + Retrieves the remote logger statistics, per type and address. + hash-password [*WORK-FACTOR*] Asks for a password then returns the hashed and salted version, to use as a webserver password or API key. This command does diff --git a/pdns/ws-recursor.cc b/pdns/ws-recursor.cc index 74f61f4c07..d1f7604136 100644 --- a/pdns/ws-recursor.cc +++ b/pdns/ws-recursor.cc @@ -1159,6 +1159,11 @@ const std::map MetricDefinitionStorage::d_metrics {"auth-formerr-answers", MetricDefinition(PrometheusMetricType::multicounter, "Count of RCodes returned by authoritative servers")}, + + // For multicounters, state the first + {"remote-logger-o-0", + MetricDefinition(PrometheusMetricType::multicounter, + "Number of remote logging events")}, }; #define CHECK_PROMETHEUS_METRICS 0