Skip to content

Commit

Permalink
Added prometheus format to user stats (#2193) (#2201)
Browse files Browse the repository at this point in the history
* Added prometheus format to user stats

* use "name" instead "sensor" for counter name

* remove timestamp

---------

Co-authored-by: Dmitry Razumov <[email protected]>
  • Loading branch information
dvrazumov and Dmitry Razumov authored Oct 2, 2024
1 parent 6f585d5 commit 5a3a92b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cloud/storage/core/libs/user_stats/user_stats_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <library/cpp/monlib/dynamic_counters/encode.h>
#include <library/cpp/monlib/service/pages/templates.h>
#include <library/cpp/monlib/encode/json/json.h>
#include <library/cpp/monlib/encode/prometheus/prometheus.h>
#include <library/cpp/monlib/encode/spack/spack_v1.h>
#include <library/cpp/monlib/encode/text/text.h>

Expand Down Expand Up @@ -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);
}));
}
}

Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions cloud/storage/core/libs/user_stats/user_stats_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5a3a92b

Please sign in to comment.