aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/monlib/dynamic_counters/percentile/percentile_base.h
blob: d3c825c43d82b7fbeb495def5d133d983d01e7b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once

#include <library/cpp/monlib/dynamic_counters/counters.h>

#include <util/string/printf.h>

namespace NMonitoring {

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Percentile tracker for monitoring
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

struct TPercentileBase : public TThrRefBase {
    using TPercentile = std::pair<float, NMonitoring::TDynamicCounters::TCounterPtr>;
    using TPercentiles = TVector<TPercentile>;

    TPercentiles Percentiles;

    void Initialize(const TIntrusivePtr<NMonitoring::TDynamicCounters> &counters, const TVector<float> &thresholds,
            TCountableBase::EVisibility visibility = TCountableBase::EVisibility::Public) {
        Percentiles.reserve(thresholds.size());
        for (size_t i = 0; i < thresholds.size(); ++i) {
            Percentiles.emplace_back(thresholds[i],
                counters->GetNamedCounter("percentile", Sprintf("%.1f", thresholds[i] * 100.f), false, visibility));
        }
    }

    void Initialize(const TIntrusivePtr<NMonitoring::TDynamicCounters> &counters, TString group, TString subgroup,
            TString name, const TVector<float> &thresholds,
            TCountableBase::EVisibility visibility = TCountableBase::EVisibility::Public) {
        auto subCounters = counters->GetSubgroup(group, subgroup)->GetSubgroup("sensor", name);
        Initialize(subCounters, thresholds, visibility);
    }
};

} // NMonitoring