From 5a3a92b4a93527f6a0b0eecc16fac690b63e6f9d Mon Sep 17 00:00:00 2001 From: Dmitry Razumov Date: Wed, 2 Oct 2024 14:56:37 +0200 Subject: [PATCH] Added prometheus format to user stats (#2193) (#2201) * Added prometheus format to user stats * use "name" instead "sensor" for counter name * remove timestamp --------- Co-authored-by: Dmitry Razumov --- .../core/libs/user_stats/user_stats_actor.cpp | 23 +++++++++++++++++++ .../core/libs/user_stats/user_stats_actor.h | 1 + 2 files changed, 24 insertions(+) diff --git a/cloud/storage/core/libs/user_stats/user_stats_actor.cpp b/cloud/storage/core/libs/user_stats/user_stats_actor.cpp index c535b6a3db7..80b99163698 100644 --- a/cloud/storage/core/libs/user_stats/user_stats_actor.cpp +++ b/cloud/storage/core/libs/user_stats/user_stats_actor.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -54,6 +55,11 @@ void TUserStatsActor::RegisterPages(const NActors::TActorContext& ctx) [this] (IOutputStream& out) { return OutputSpackPage(out); })); + mon->Register(new TMonPageWrapper( + Path + "/user_stats/prometheus", + [this] (IOutputStream& out) { + return OutputPrometheusPage(out); + })); } } @@ -108,6 +114,23 @@ void TUserStatsActor::OutputSpackPage(IOutputStream& out) const encoder->OnStreamEnd(); } +void TUserStatsActor::OutputPrometheusPage(IOutputStream& out) const +{ + out << NMonitoring::HTTPOKPROMETHEUS; + + auto encoder = NMonitoring::EncoderPrometheus(&out, "name"); + + encoder->OnStreamBegin(); + { + TReadGuard g{Lock}; + + for (auto&& provider : Providers) { + provider->Append(TInstant::Zero(), encoder.Get()); + } + } + encoder->OnStreamEnd(); +} + //////////////////////////////////////////////////////////////////////////////// void TUserStatsActor::HandleHttpInfo( diff --git a/cloud/storage/core/libs/user_stats/user_stats_actor.h b/cloud/storage/core/libs/user_stats/user_stats_actor.h index fffd47411b6..e6f0fc3c9fc 100644 --- a/cloud/storage/core/libs/user_stats/user_stats_actor.h +++ b/cloud/storage/core/libs/user_stats/user_stats_actor.h @@ -38,6 +38,7 @@ class TUserStatsActor final void OutputJsonPage(IOutputStream& out) const; void OutputSpackPage(IOutputStream& out) const; + void OutputPrometheusPage(IOutputStream& out) const; private: STFUNC(StateWork);