aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/core/log_metrics.h
blob: 91fed3a4e4c677888213770aaf0a1271b71cb5b5 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#pragma once

#include <library/cpp/monlib/dynamic_counters/counters.h>
#include <library/cpp/monlib/metrics/metric_registry.h>
#include <library/cpp/monlib/service/pages/templates.h>

namespace NActors {
class ILoggerMetrics {
public:
    virtual ~ILoggerMetrics() = default;

    virtual void IncActorMsgs() = 0;
    virtual void IncDirectMsgs() = 0;
    virtual void IncLevelRequests() = 0;
    virtual void IncIgnoredMsgs() = 0;
    virtual void IncAlertMsgs() = 0;
    virtual void IncEmergMsgs() = 0;
    virtual void IncDroppedMsgs() = 0;

    virtual void GetOutputHtml(IOutputStream&) = 0;
};

class TLoggerCounters : public ILoggerMetrics {
public:
    TLoggerCounters(TIntrusivePtr<NMonitoring::TDynamicCounters> counters)
        : DynamicCounters(counters)
    {
        ActorMsgs_ = DynamicCounters->GetCounter("ActorMsgs", true);
        DirectMsgs_ = DynamicCounters->GetCounter("DirectMsgs", true);
        LevelRequests_ = DynamicCounters->GetCounter("LevelRequests", true);
        IgnoredMsgs_ = DynamicCounters->GetCounter("IgnoredMsgs", true);
        DroppedMsgs_ = DynamicCounters->GetCounter("DroppedMsgs", true);

        AlertMsgs_ = DynamicCounters->GetCounter("AlertMsgs", true);
        EmergMsgs_ = DynamicCounters->GetCounter("EmergMsgs", true);
    }

    ~TLoggerCounters() = default;

    void IncActorMsgs() override {
        ++*ActorMsgs_;
    }
    void IncDirectMsgs() override {
        ++*DirectMsgs_;
    }
    void IncLevelRequests() override {
        ++*LevelRequests_;
    }
    void IncIgnoredMsgs() override {
        ++*IgnoredMsgs_;
    }
    void IncAlertMsgs() override {
        ++*AlertMsgs_;
    }
    void IncEmergMsgs() override {
        ++*EmergMsgs_;
    }
    void IncDroppedMsgs() override {
        DroppedMsgs_->Inc();
    };

    void GetOutputHtml(IOutputStream& str) override {
        HTML(str) {
            DIV_CLASS("row") {
                DIV_CLASS("col-md-12") {
                    TAG(TH4) {
                        str << "Counters" << Endl;
                    }
                    DynamicCounters->OutputHtml(str);
                }
            }
        }
    }

private:
    NMonitoring::TDynamicCounters::TCounterPtr ActorMsgs_;
    NMonitoring::TDynamicCounters::TCounterPtr DirectMsgs_;
    NMonitoring::TDynamicCounters::TCounterPtr LevelRequests_;
    NMonitoring::TDynamicCounters::TCounterPtr IgnoredMsgs_;
    NMonitoring::TDynamicCounters::TCounterPtr AlertMsgs_;
    NMonitoring::TDynamicCounters::TCounterPtr EmergMsgs_;
    // Dropped while the logger backend was unavailable
    NMonitoring::TDynamicCounters::TCounterPtr DroppedMsgs_;

    TIntrusivePtr<NMonitoring::TDynamicCounters> DynamicCounters;
};

class TLoggerMetrics : public ILoggerMetrics {
public:
    TLoggerMetrics(std::shared_ptr<NMonitoring::TMetricRegistry> metrics)
        : Metrics(metrics)
    {
        ActorMsgs_ = Metrics->Rate(NMonitoring::TLabels{{"sensor", "logger.actor_msgs"}});
        DirectMsgs_ = Metrics->Rate(NMonitoring::TLabels{{"sensor", "logger.direct_msgs"}});
        LevelRequests_ = Metrics->Rate(NMonitoring::TLabels{{"sensor", "logger.level_requests"}});
        IgnoredMsgs_ = Metrics->Rate(NMonitoring::TLabels{{"sensor", "logger.ignored_msgs"}});
        DroppedMsgs_ = Metrics->Rate(NMonitoring::TLabels{{"sensor", "logger.dropped_msgs"}});

        AlertMsgs_ = Metrics->Rate(NMonitoring::TLabels{{"sensor", "logger.alert_msgs"}});
        EmergMsgs_ = Metrics->Rate(NMonitoring::TLabels{{"sensor", "logger.emerg_msgs"}});
    }

    ~TLoggerMetrics() = default;

    void IncActorMsgs() override {
        ActorMsgs_->Inc();
    }
    void IncDirectMsgs() override {
        DirectMsgs_->Inc();
    }
    void IncLevelRequests() override {
        LevelRequests_->Inc();
    }
    void IncIgnoredMsgs() override {
        IgnoredMsgs_->Inc();
    }
    void IncAlertMsgs() override {
        AlertMsgs_->Inc();
    }
    void IncEmergMsgs() override {
        EmergMsgs_->Inc();
    }
    void IncDroppedMsgs() override {
        DroppedMsgs_->Inc();
    };

    void GetOutputHtml(IOutputStream& str) override {
        HTML(str) {
            DIV_CLASS("row") {
                DIV_CLASS("col-md-12") {
                    TAG(TH4) {
                        str << "Metrics" << Endl;
                    }
                    // TODO: Now, TMetricRegistry does not have the GetOutputHtml function
                }
            }
        }
    }

private:
    NMonitoring::TRate* ActorMsgs_;
    NMonitoring::TRate* DirectMsgs_;
    NMonitoring::TRate* LevelRequests_;
    NMonitoring::TRate* IgnoredMsgs_;
    NMonitoring::TRate* AlertMsgs_;
    NMonitoring::TRate* EmergMsgs_;
    // Dropped while the logger backend was unavailable
    NMonitoring::TRate* DroppedMsgs_;

    std::shared_ptr<NMonitoring::TMetricRegistry> Metrics;
};
}