Repo-Init
 
Loading...
Searching...
No Matches
Status.cpp
Go to the documentation of this file.
1#include "metrics/Status.hpp"
2
3#include <format>
4
5#include <prometheus/counter.h>
6#include <prometheus/gauge.h>
7
8StatusTracker::StatusTracker(const std::shared_ptr<prometheus::Registry> &reg, const std::string &name,
9 uint64_t metricID)
10{
11 // Register values
12 _activeCtr = &prometheus::BuildGauge()
13 .Name(std::format("{}{}{}", name, "_active_event_ctr_", metricID))
14 .Help("Currently active number of events of " + name)
15 .Register(*reg)
16 .Add({});
17 _totalCtr = &prometheus::BuildCounter()
18 .Name(std::format("{}{}{}", name, "_total_event_ctr_", metricID))
19 .Help("Total occurrences of " + name)
20 .Register(*reg)
21 .Add({});
22 _successCtr = &prometheus::BuildCounter()
23 .Name(std::format("{}{}{}", name, "_success_event_ctr_", metricID))
24 .Help("Successful events of " + name)
25 .Register(*reg)
26 .Add({});
27 _failedCtr = &prometheus::BuildCounter()
28 .Name(std::format("{}{}{}", name, "_fail_event_ctr_", metricID))
29 .Help("Failed events of " + name)
30 .Register(*reg)
31 .Add({});
32}
33
35
37
39{
40 _successCtr->Increment();
41 _totalCtr->Increment();
42 if (_activeCtr->Value() > 0)
43 {
44 _activeCtr->Decrement();
45 }
46}
47
49{
50 _failedCtr->Increment();
51 _totalCtr->Increment();
52 if (_activeCtr->Value() > 0)
53 {
54 _activeCtr->Decrement();
55 }
56}
void incrementActive()
Definition Status.cpp:34
prometheus::Gauge * _activeCtr
Active number of events.
Definition Status.hpp:11
void incrementSuccess()
Definition Status.cpp:38
void incrementFail()
Definition Status.cpp:48
StatusTracker(const std::shared_ptr< prometheus::Registry > &reg, const std::string &name, uint64_t metricID=0)
Definition Status.cpp:8
prometheus::Counter * _failedCtr
Number of fail.
Definition Status.hpp:14
void decrementActive()
Definition Status.cpp:36
prometheus::Counter * _successCtr
Number of success.
Definition Status.hpp:13
prometheus::Counter * _totalCtr
Total number of counters.
Definition Status.hpp:12