aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/providers/common/metrics/service_counters.cpp
blob: 09f0de4a3737c7f079ff0026b23c3836435d3b49 (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
37
38
39
40
41
42
43
44
45
46
47
48
#include "service_counters.h"

namespace NYql {
namespace NCommon {

TServiceCounters::TServiceCounters(
    const ::NMonitoring::TDynamicCounterPtr& rootCounters,
    const ::NMonitoring::TDynamicCounterPtr& publicCounters,
    const TString& subsystemName)
    : RootCounters(rootCounters)
    , PublicCounters(publicCounters)
    , Counters(subsystemName ? RootCounters->GetSubgroup("subsystem", subsystemName) : RootCounters)
{
}

TServiceCounters::TServiceCounters(
    const ::NMonitoring::TDynamicCounterPtr& baseCounters,
    const TString& subsystemName)
    : RootCounters(baseCounters->GetSubgroup("counters", "yq"))
    , PublicCounters(baseCounters->GetSubgroup("counters", "yq_public"))
    , Counters(subsystemName ? RootCounters->GetSubgroup("subsystem", subsystemName) : RootCounters)
{
}

TServiceCounters::TServiceCounters(
    const TServiceCounters& serviceCounters,
    const TString& subsystemName)
    : RootCounters(serviceCounters.RootCounters)
    , PublicCounters(serviceCounters.PublicCounters)
    , Counters(subsystemName ? RootCounters->GetSubgroup("subsystem", subsystemName) : serviceCounters.Counters)
    , UptimeRootCounter(serviceCounters.UptimeRootCounter)
    , UptimePublicCounter(serviceCounters.UptimePublicCounter)
{
}

void TServiceCounters::InitUptimeCounter() {
    UptimePublicCounter = PublicCounters->GetNamedCounter("name", "query.uptime_seconds", false);
    UptimeRootCounter = RootCounters->GetNamedCounter("sensor", "UptimeSeconds", false);
}

void TServiceCounters::SetUptimePublicAndServiceCounter(i64 val) const {
    Y_ABORT_UNLESS(UptimePublicCounter && UptimeRootCounter);
    UptimePublicCounter->Set(val);
    UptimeRootCounter->Set(val);
}

} // namespace NCommon
} // namespace NYql