From 4c1c085d076705261d30ec8177b1fbb59c76fd6d Mon Sep 17 00:00:00 2001 From: Markus Schmidl Date: Sat, 25 May 2024 19:20:39 +0200 Subject: [PATCH] add name label for prometheus --- include/prometheus.h | 3 ++- src/main.cpp | 5 ++++- src/prometheus.cpp | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/prometheus.h b/include/prometheus.h index 44a73b3..1d76cc2 100644 --- a/include/prometheus.h +++ b/include/prometheus.h @@ -11,9 +11,10 @@ class PrometheusExporter { private: std::shared_ptr registry_; std::unique_ptr exposer_; + const std::string prometheus_name_; public: - PrometheusExporter(const std::string& host) noexcept; + PrometheusExporter(const std::string& prometheus_host, const std::string& prometheus_name) noexcept; ~PrometheusExporter() noexcept = default; auto burst_received_count() noexcept -> prometheus::Family&; diff --git a/src/main.cpp b/src/main.cpp index 88236b3..19432c2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,7 @@ auto main(int argc, char** argv) -> int { std::optional input_file, output_file; std::optional uplink_scrambling_code; std::optional prometheus_address; + std::optional prometheus_name; std::shared_ptr prometheus_exporter; @@ -42,6 +43,7 @@ auto main(int argc, char** argv) -> int { ("iq", "Receive IQ instead of bitstream", cxxopts::value()->default_value("false")) ("uplink", " enable uplink parsing with predefined scrambilng code", cxxopts::value>(uplink_scrambling_code)) ("prometheus-address", " on which ip and port the webserver for prometheus should listen. example: 127.0.0.1:9010", cxxopts::value>(prometheus_address)) + ("prometheus-name", " the name which is included in the prometheus metrics", cxxopts::value>(prometheus_name)) ; // clang-format on @@ -61,7 +63,8 @@ auto main(int argc, char** argv) -> int { iq_or_bit_stream = result["iq"].as(); if (prometheus_address) { - prometheus_exporter = std::make_shared(*prometheus_address); + prometheus_exporter = std::make_shared( + *prometheus_address, prometheus_name.value_or("Unnamed Tetra Decoder")); } } catch (std::exception& e) { std::cout << "error parsing options: " << e.what() << std::endl; diff --git a/src/prometheus.cpp b/src/prometheus.cpp index 3638f18..7c62e77 100644 --- a/src/prometheus.cpp +++ b/src/prometheus.cpp @@ -1,6 +1,7 @@ #include "prometheus.h" -PrometheusExporter::PrometheusExporter(const std::string& prometheus_host) noexcept { +PrometheusExporter::PrometheusExporter(const std::string& prometheus_host, const std::string& prometheus_name) noexcept + : prometheus_name_(std::move(prometheus_name)) { exposer_ = std::make_unique(prometheus_host); registry_ = std::make_shared(); @@ -11,6 +12,7 @@ auto PrometheusExporter::burst_received_count() noexcept -> prometheus::Family

prometheus::Fami return prometheus::BuildCounter() .Name("burst_decode_error_count") .Help("Incrementing counter of the decoding errors on received bursts") + .Labels({{"name", prometheus_name_}}) .Register(*registry_); }