percentile_base.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #pragma once
  2. #include <library/cpp/monlib/dynamic_counters/counters.h>
  3. #include <util/string/printf.h>
  4. namespace NMonitoring {
  5. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  6. // Percentile tracker for monitoring
  7. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  8. struct TPercentileBase : public TThrRefBase {
  9. using TPercentile = std::pair<float, NMonitoring::TDynamicCounters::TCounterPtr>;
  10. using TPercentiles = TVector<TPercentile>;
  11. TPercentiles Percentiles;
  12. void Initialize(const TIntrusivePtr<NMonitoring::TDynamicCounters> &counters, const TVector<float> &thresholds,
  13. TCountableBase::EVisibility visibility = TCountableBase::EVisibility::Public) {
  14. Percentiles.reserve(thresholds.size());
  15. for (size_t i = 0; i < thresholds.size(); ++i) {
  16. Percentiles.emplace_back(thresholds[i],
  17. counters->GetNamedCounter("percentile", Sprintf("%.1f", thresholds[i] * 100.f), false, visibility));
  18. }
  19. }
  20. void Initialize(const TIntrusivePtr<NMonitoring::TDynamicCounters> &counters, TString group, TString subgroup,
  21. TString name, const TVector<float> &thresholds,
  22. TCountableBase::EVisibility visibility = TCountableBase::EVisibility::Public) {
  23. auto subCounters = counters->GetSubgroup(group, subgroup)->GetSubgroup("sensor", name);
  24. Initialize(subCounters, thresholds, visibility);
  25. }
  26. };
  27. } // NMonitoring