Repo-Init
 
Loading...
Searching...
No Matches
BaseServerStats.cpp
Go to the documentation of this file.
2
3#include <prometheus/counter.h>
4#include <prometheus/summary.h>
5
6void BaseServerStats::initBaseStats(const std::shared_ptr<prometheus::Registry> &reg, const std::string &name)
7{
8 // Command stats
9 _succeededCommand = &prometheus::BuildCounter()
10 .Name(name + "succeeded_commands")
11 .Help("Number of succeeded commands")
12 .Register(*reg)
13 .Add({});
14 _failedCommand = &prometheus::BuildCounter()
15 .Name(name + "failed_commands")
16 .Help("Number of failed commands")
17 .Register(*reg)
18 .Add({});
19 _totalCommand = &prometheus::BuildCounter()
20 .Name(name + "received_commands")
21 .Help("Number of received commands")
22 .Register(*reg)
23 .Add({});
24
25 // Performance stats
26 _processingTime = &prometheus::BuildSummary()
27 .Name(name + "processing_time")
28 .Help("Command processing performance")
29 .Register(*reg)
30 .Add({}, QUANTILE_DEFAULTS);
31 _maxProcessingTime = &prometheus::BuildGauge()
32 .Name(name + "maximum_processing_time")
33 .Help("Maximum value of the command processing performance")
34 .Register(*reg)
35 .Add({});
36 _minProcessingTime = &prometheus::BuildGauge()
37 .Name(name + "minimum_processing_time")
38 .Help("Minimum value of the command processing performance")
39 .Register(*reg)
40 .Add({});
41
42 // Set defaults
43 _minProcessingTime->Set(std::numeric_limits<int>::max());
44}
45
46void BaseServerStats::consumeBaseStats(uint64_t succeeded, uint64_t failed, double processingTime)
47{
48 // Command stats
49 _succeededCommand->Increment(static_cast<double>(succeeded));
50 _failedCommand->Increment(static_cast<double>(failed));
51 _totalCommand->Increment(static_cast<double>(succeeded + failed));
52
53 // Performance stats
54 if (processingTime > 0)
55 {
56 _processingTime->Observe(processingTime);
57 _maxProcessingTime->Set(std::max(_maxProcessingTime->Value(), processingTime));
58 _minProcessingTime->Set(std::min(_minProcessingTime->Value(), processingTime));
59 }
60}
#define QUANTILE_DEFAULTS
prometheus::Counter * _succeededCommand
Number of succeeded commands.
prometheus::Gauge * _minProcessingTime
Minimum value of the command processing performance.
void consumeBaseStats(uint64_t succeeded, uint64_t failed, double processingTime)
prometheus::Counter * _failedCommand
Number of failed commands.
prometheus::Gauge * _maxProcessingTime
Maximum value of the command processing performance.
prometheus::Counter * _totalCommand
Number of total received commands.
prometheus::Summary * _processingTime
Value of the command processing performance.
void initBaseStats(const std::shared_ptr< prometheus::Registry > &reg, const std::string &name)