From c0b76e5569640e71ac22c258342bd770bc4e9c19 Mon Sep 17 00:00:00 2001 From: Otto Date: Tue, 29 Jun 2021 10:29:54 +0200 Subject: [PATCH] For Prometheus output, ad HELP and TYPE --- pdns/rec_channel_rec.cc | 6 +++--- pdns/recursordist/rec_metrics.hh | 6 +++++- pdns/ws-recursor.cc | 23 ++++++++++++++++++++--- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 5ed2f9ece5..0c6b223eaf 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -1375,13 +1375,13 @@ static void registerAllStats1() addGetStat(name, &(SyncRes::s_ecsResponsesBySubnetSize6.at(idx))); } - addGetStat("cumulativeAnswers-usec-", []() { + addGetStat("cumul-answers", []() { return toStatsMap(g_stats.cumulativeAnswers.getName(), g_stats.cumulativeAnswers); }); - addGetStat("cumulativeAuth4Answers-usec-", []() { + addGetStat("cumul-auth4answers", []() { return toStatsMap(g_stats.cumulativeAuth4Answers.getName(), g_stats.cumulativeAuth4Answers); }); - addGetStat("cumulativeAuth6Answers-usec-", []() { + addGetStat("cumul-auth6answers", []() { return toStatsMap(g_stats.cumulativeAuth6Answers.getName(), g_stats.cumulativeAuth6Answers); }); } diff --git a/pdns/recursordist/rec_metrics.hh b/pdns/recursordist/rec_metrics.hh index 39b15deeb6..59921825a2 100644 --- a/pdns/recursordist/rec_metrics.hh +++ b/pdns/recursordist/rec_metrics.hh @@ -33,7 +33,8 @@ enum class PrometheusMetricType : int { counter = 1, - gauge = 2 + gauge = 2, + histogram = 3 }; // Keeps additional information about metrics @@ -79,6 +80,9 @@ public: case PrometheusMetricType::gauge: return "gauge"; break; + case PrometheusMetricType::histogram: + return "histogram"; + break; default: return ""; break; diff --git a/pdns/ws-recursor.cc b/pdns/ws-recursor.cc index a65e60795d..71566be971 100644 --- a/pdns/ws-recursor.cc +++ b/pdns/ws-recursor.cc @@ -446,7 +446,6 @@ static void prometheusMetrics(HttpRequest *req, HttpResponse *resp) { for (const auto& tup : varmap) { std::string metricName = tup.first; std::string prometheusMetricName = tup.second.d_prometheusName; - MetricDefinition metricDetails; if (s_metricDefinitions.getMetricDetails(metricName, metricDetails)) { @@ -456,7 +455,13 @@ static void prometheusMetrics(HttpRequest *req, HttpResponse *resp) { if (prometheusTypeName.empty()) { continue; } - + if (metricDetails.prometheusType == PrometheusMetricType::histogram) { + // name is XXX_count, strip the _count part + prometheusMetricName = prometheusMetricName.substr(0, prometheusMetricName.length() - 6); + output << "# HELP " << prometheusMetricName << " " << metricDetails.description << "\n"; + output << "# TYPE " << prometheusMetricName << " " << prometheusTypeName << "\n"; + continue; + } // for these we have the help and types encoded in the sources: output << "# HELP " << prometheusMetricName << " " << metricDetails.description << "\n"; output << "# TYPE " << prometheusMetricName << " " << prometheusTypeName << "\n"; @@ -1029,9 +1034,21 @@ const std::map MetricDefinitionStorage::metrics = MetricDefinition(PrometheusMetricType::counter, "Number of outgoing DoT queries since starting")}, + // For cumulative histogram, state the xxx_count name where xxx matches the name in rec_channel_rec + { "cumul-answers-count", + MetricDefinition(PrometheusMetricType::histogram, + "histogram of our answer times")}, + // For cumulative histogram, state the xxx_count name where xxx matches the name in rec_channel_rec + { "cumul-auth4answers-count", + MetricDefinition(PrometheusMetricType::histogram, + "histogram of authoritative answer times over IPv4")}, + // For cumulative histogram, state the xxx_count name where xxx matches the name in rec_channel_rec + { "cumul-auth6answers-count", + MetricDefinition(PrometheusMetricType::histogram, + "histogram of authoritative answer times over IPV6")}, }; -#define CHECK_PROMETHEUS_METRICS 0 +#define CHECK_PROMETHEUS_METRICS 1 #if CHECK_PROMETHEUS_METRICS static void validatePrometheusMetrics() -- 2.47.2