Repo-Init
 
Loading...
Searching...
No Matches
ZeroMQStats Class Reference

#include <ZeroMQStats.hpp>

Inheritance diagram for ZeroMQStats:
Collaboration diagram for ZeroMQStats:

Public Member Functions

 ZeroMQStats (const std::shared_ptr< prometheus::Registry > &reg, const std::string &prependName="")
 
void consumeStats (const std::vector< zmq::message_t > &recvMsgs, const std::vector< zmq::message_t > &sendMsgs, const ZeroMQServerStats &serverStats)
 

Private Attributes

prometheus::Family< prometheus::Info > * _infoFamily
 Information metric family.
 
prometheus::Counter * _succeededCommandParts
 Number of received succeeded message parts.
 
prometheus::Counter * _failedCommandParts
 Number of received failed message parts.
 
prometheus::Counter * _totalCommandParts
 Number of received total message parts.
 
prometheus::Counter * _totalUploadBytes
 Total uploaded bytes.
 
prometheus::Counter * _totalDownloadBytes
 Total downloaded bytes.
 

Additional Inherited Members

- Private Member Functions inherited from BaseServerStats
void initBaseStats (const std::shared_ptr< prometheus::Registry > &reg, const std::string &name)
 
void consumeBaseStats (uint64_t succeeded, uint64_t failed, double processingTime)
 

Detailed Description

Represents the statistics of a ZeroMQ server.

Definition at line 22 of file ZeroMQStats.hpp.

Constructor & Destructor Documentation

◆ ZeroMQStats()

ZeroMQStats::ZeroMQStats ( const std::shared_ptr< prometheus::Registry > & reg,
const std::string & prependName = "" )
explicit

Construct a new ZeroMQStats object.

Parameters
[in]regPrometheus registry.
[in]prependNamePrefix for Prometheus stats.

Definition at line 9 of file ZeroMQStats.cpp.

11{
12 if (!reg)
13 {
14 throw std::invalid_argument("Can't init ZeroMQ statistics. Registry is null");
15 }
16
17 const auto name = prependName.empty() ? "zeromq_" : prependName + "_zeromq_";
18
19 // Init stats from base class
20 initBaseStats(reg, name);
21
22 // Basic information
24 &prometheus::BuildInfo().Name(name.substr(0, name.size() - 1)).Help("ZeroMQ server information").Register(*reg);
25
26 _infoFamily->Add({{"init_time", date::format("%FT%TZ", date::floor<std::chrono::nanoseconds>(
27 std::chrono::high_resolution_clock::now()))}});
28 _infoFamily->Add({{"performance_unit", "nanoseconds"}});
29
30 // Command stats
31 _succeededCommandParts = &prometheus::BuildCounter()
32 .Name(name + "succeeded_command_parts")
33 .Help("Number of received succeeded message parts")
34 .Register(*reg)
35 .Add({});
36 _failedCommandParts = &prometheus::BuildCounter()
37 .Name(name + "failed_command_parts")
38 .Help("Number of received failed message parts")
39 .Register(*reg)
40 .Add({});
41 _totalCommandParts = &prometheus::BuildCounter()
42 .Name(name + "total_command_parts")
43 .Help("Number of received total message parts")
44 .Register(*reg)
45 .Add({});
46
47 // Bandwidth stats
49 &prometheus::BuildCounter().Name(name + "uploaded_bytes").Help("Total uploaded bytes").Register(*reg).Add({});
50 _totalDownloadBytes = &prometheus::BuildCounter()
51 .Name(name + "downloaded_bytes")
52 .Help("Total downloaded bytes")
53 .Register(*reg)
54 .Add({});
55}
void initBaseStats(const std::shared_ptr< prometheus::Registry > &reg, const std::string &name)
prometheus::Counter * _failedCommandParts
Number of received failed message parts.
prometheus::Counter * _totalDownloadBytes
Total downloaded bytes.
prometheus::Counter * _totalCommandParts
Number of received total message parts.
prometheus::Counter * _succeededCommandParts
Number of received succeeded message parts.
prometheus::Counter * _totalUploadBytes
Total uploaded bytes.
prometheus::Family< prometheus::Info > * _infoFamily
Information metric family.
Here is the call graph for this function:

Member Function Documentation

◆ consumeStats()

void ZeroMQStats::consumeStats ( const std::vector< zmq::message_t > & recvMsgs,
const std::vector< zmq::message_t > & sendMsgs,
const ZeroMQServerStats & serverStats )

Updates the statistics with messages.

Parameters
[in]recvMsgsReceived messages.
[in]sendMsgsSend messages.
[in]serverStatsZeroMQ server stats.

Definition at line 57 of file ZeroMQStats.cpp.

59{
60 consumeBaseStats(static_cast<uint64_t>(serverStats.isSuccessful), static_cast<uint64_t>(!serverStats.isSuccessful),
61 static_cast<double>((serverStats.processingTimeEnd - serverStats.processingTimeStart).count()));
62
63 for (const auto &entry : recvMsgs)
64 {
65 _totalCommandParts->Increment();
66 _totalDownloadBytes->Increment(static_cast<double>(entry.size()));
67
68 if (serverStats.isSuccessful)
69 {
70 _succeededCommandParts->Increment();
71 }
72 else
73 {
74 _failedCommandParts->Increment();
75 }
76 }
77
78 for (const auto &entry : sendMsgs)
79 {
80 _totalUploadBytes->Increment(static_cast<double>(entry.size()));
81 }
82}
void consumeBaseStats(uint64_t succeeded, uint64_t failed, double processingTime)
bool isSuccessful
Indicates if processing was successful for this connection.
std::chrono::high_resolution_clock::time_point processingTimeEnd
Processing time end.
std::chrono::high_resolution_clock::time_point processingTimeStart
Processing time start.
Here is the call graph for this function:

Member Data Documentation

◆ _failedCommandParts

prometheus::Counter* ZeroMQStats::_failedCommandParts
private

Number of received failed message parts.

Definition at line 26 of file ZeroMQStats.hpp.

◆ _infoFamily

prometheus::Family<prometheus::Info>* ZeroMQStats::_infoFamily
private

Information metric family.

Definition at line 24 of file ZeroMQStats.hpp.

◆ _succeededCommandParts

prometheus::Counter* ZeroMQStats::_succeededCommandParts
private

Number of received succeeded message parts.

Definition at line 25 of file ZeroMQStats.hpp.

◆ _totalCommandParts

prometheus::Counter* ZeroMQStats::_totalCommandParts
private

Number of received total message parts.

Definition at line 27 of file ZeroMQStats.hpp.

◆ _totalDownloadBytes

prometheus::Counter* ZeroMQStats::_totalDownloadBytes
private

Total downloaded bytes.

Definition at line 29 of file ZeroMQStats.hpp.

◆ _totalUploadBytes

prometheus::Counter* ZeroMQStats::_totalUploadBytes
private

Total uploaded bytes.

Definition at line 28 of file ZeroMQStats.hpp.


The documentation for this class was generated from the following files: