Repcale dots in prometheus metric names with underscores

This commit is contained in:
VDimir 2019-12-21 17:47:44 +00:00
parent ea56001fc0
commit 0e9daded94
2 changed files with 14 additions and 3 deletions

View File

@ -1,5 +1,7 @@
#include "PrometheusMetricsWriter.h"
#include <algorithm>
#include <IO/WriteHelpers.h>
namespace
@ -20,6 +22,11 @@ void writeOutLine(DB::WriteBuffer & wb, T && val, TArgs &&... args)
writeOutLine(wb, std::forward<TArgs>(args)...);
}
void replaceInvalidChars(std::string & metric_name)
{
std::replace(metric_name.begin(), metric_name.end(), '.', '_');
}
}
@ -47,6 +54,7 @@ void PrometheusMetricsWriter::write(WriteBuffer & wb) const
std::string metric_name{ProfileEvents::getName(static_cast<ProfileEvents::Event>(i))};
std::string metric_doc{ProfileEvents::getDocumentation(static_cast<ProfileEvents::Event>(i))};
replaceInvalidChars(metric_name);
std::string key{profile_events_prefix + metric_name};
writeOutLine(wb, "# HELP", key, metric_doc);
@ -64,6 +72,7 @@ void PrometheusMetricsWriter::write(WriteBuffer & wb) const
std::string metric_name{CurrentMetrics::getName(static_cast<CurrentMetrics::Metric>(i))};
std::string metric_doc{CurrentMetrics::getDocumentation(static_cast<CurrentMetrics::Metric>(i))};
replaceInvalidChars(metric_name);
std::string key{current_metrics_prefix + metric_name};
writeOutLine(wb, "# HELP", key, metric_doc);
@ -78,6 +87,8 @@ void PrometheusMetricsWriter::write(WriteBuffer & wb) const
for (const auto & name_value : async_metrics_values)
{
std::string key{asynchronous_metrics_prefix + name_value.first};
replaceInvalidChars(key);
auto value = name_value.second;
// TODO: add HELP section? asynchronous_metrics contains only key and value

View File

@ -28,9 +28,9 @@ private:
const bool send_metrics;
const bool send_asynchronous_metrics;
static inline constexpr auto profile_events_prefix = "ClickHouseProfileEvents";
static inline constexpr auto current_metrics_prefix = "ClickHouseMetrics";
static inline constexpr auto asynchronous_metrics_prefix = "ClickHouseAsyncMetrics";
static inline constexpr auto profile_events_prefix = "ClickHouseProfileEvents_";
static inline constexpr auto current_metrics_prefix = "ClickHouseMetrics_";
static inline constexpr auto asynchronous_metrics_prefix = "ClickHouseAsyncMetrics_";
};
}