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

#include <TelnetStats.hpp>

Inheritance diagram for TelnetStats:
Collaboration diagram for TelnetStats:

Public Member Functions

 TelnetStats (const std::shared_ptr< prometheus::Registry > &reg, uint16_t portNumber, const std::string &prependName="")
 
void consumeStats (const TelnetSessionStats &stat, bool sessionClosed)
 
void consumeStats (const TelnetServerStats &stat)
 

Private Attributes

prometheus::Family< prometheus::Info > * _infoFamily
 Information metric family.
 
prometheus::Gauge * _activeConnection
 Number of active connections.
 
prometheus::Counter * _refusedConnection
 Number of refused connections.
 
prometheus::Counter * _totalConnection
 Number of total received connections.
 
prometheus::Counter * _totalUploadBytes
 Total uploaded bytes.
 
prometheus::Counter * _totalDownloadBytes
 Total downloaded bytes.
 
prometheus::Summary * _sessionDuration
 Value of the duration of sessions.
 
prometheus::Gauge * _maxSessionDuration
 Maximum duration of sessions.
 
prometheus::Gauge * _minSessionDuration
 Minimum duration of sessions.
 

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

Prometheus statistics for Telnet server

Definition at line 33 of file TelnetStats.hpp.

Constructor & Destructor Documentation

◆ TelnetStats()

TelnetStats::TelnetStats ( const std::shared_ptr< prometheus::Registry > & reg,
uint16_t portNumber,
const std::string & prependName = "" )

Construct a new Telnet statistics

Parameters
[in]regPrometheus registry
[in]portNumberTelnet server port
[in]prependNamePrefix for Prometheus stats

Definition at line 11 of file TelnetStats.cpp.

14{
15 if (!reg)
16 {
17 throw std::invalid_argument("Can't init Telnet statistics. Registry is null");
18 }
19
20 const auto name = prependName.empty() ? "telnet_" : prependName + "_telnet_";
21
22 // Stats from base class
23 initBaseStats(reg, name);
24
25 // Basic information
27 &prometheus::BuildInfo().Name(name.substr(0, name.size() - 1)).Help("Telnet server information").Register(*reg);
28
29 _infoFamily->Add({{"server_port", std::to_string(portNumber)}});
30 _infoFamily->Add({{"init_time", date::format("%FT%TZ", date::floor<std::chrono::nanoseconds>(
31 std::chrono::high_resolution_clock::now()))}});
32 _infoFamily->Add({{"performance_unit", "nanoseconds"}});
33
34 // Connection stats
35 _activeConnection = &prometheus::BuildGauge()
36 .Name(name + "active_connections")
37 .Help("Number of active connections")
38 .Register(*reg)
39 .Add({});
40 _refusedConnection = &prometheus::BuildCounter()
41 .Name(name + "refused_connections")
42 .Help("Number of refused connections")
43 .Register(*reg)
44 .Add({});
45 _totalConnection = &prometheus::BuildCounter()
46 .Name(name + "received_connections")
47 .Help("Number of received connections")
48 .Register(*reg)
49 .Add({});
50
51 // Bandwidth stats
53 &prometheus::BuildCounter().Name(name + "uploaded_bytes").Help("Total uploaded bytes").Register(*reg).Add({});
54 _totalDownloadBytes = &prometheus::BuildCounter()
55 .Name(name + "downloaded_bytes")
56 .Help("Total downloaded bytes")
57 .Register(*reg)
58 .Add({});
59
60 // Session durations
61 _sessionDuration = &prometheus::BuildSummary()
62 .Name(name + "session_duration")
63 .Help("Duration of sessions")
64 .Register(*reg)
65 .Add({}, QUANTILE_DEFAULTS);
66 _maxSessionDuration = &prometheus::BuildGauge()
67 .Name(name + "maximum_session_duration")
68 .Help("Maximum duration of sessions")
69 .Register(*reg)
70 .Add({});
71 _minSessionDuration = &prometheus::BuildGauge()
72 .Name(name + "minimum_session_duration")
73 .Help("Minimum duration of sessions")
74 .Register(*reg)
75 .Add({});
76
77 // Set defaults
78 _minSessionDuration->Set(std::numeric_limits<int>::max());
79}
#define QUANTILE_DEFAULTS
void initBaseStats(const std::shared_ptr< prometheus::Registry > &reg, const std::string &name)
prometheus::Counter * _totalDownloadBytes
Total downloaded bytes.
prometheus::Family< prometheus::Info > * _infoFamily
Information metric family.
prometheus::Counter * _totalConnection
Number of total received connections.
prometheus::Counter * _refusedConnection
Number of refused connections.
prometheus::Gauge * _maxSessionDuration
Maximum duration of sessions.
prometheus::Gauge * _activeConnection
Number of active connections.
prometheus::Counter * _totalUploadBytes
Total uploaded bytes.
prometheus::Gauge * _minSessionDuration
Minimum duration of sessions.
prometheus::Summary * _sessionDuration
Value of the duration of sessions.
Here is the call graph for this function:

Member Function Documentation

◆ consumeStats() [1/2]

void TelnetStats::consumeStats ( const TelnetServerStats & stat)

Updates statistics with server values

Parameters
[in]statStatistics values from server

Definition at line 105 of file TelnetStats.cpp.

106{
107 // Connection stats
108 _activeConnection->Set(static_cast<double>(stat.activeConnectionCtr));
109 _refusedConnection->Increment(static_cast<double>(stat.refusedConnectionCtr));
110 _totalConnection->Increment(static_cast<double>(stat.acceptedConnectionCtr));
111
112 // Performance stats if there is an active connection
113 if (stat.activeConnectionCtr > 0)
114 {
115 consumeBaseStats(0, 0, static_cast<double>((stat.processingTimeEnd - stat.processingTimeStart).count()));
116 }
117}
void consumeBaseStats(uint64_t succeeded, uint64_t failed, double processingTime)
std::chrono::high_resolution_clock::time_point processingTimeStart
Processing time start.
uint64_t activeConnectionCtr
Number of active connections.
std::chrono::high_resolution_clock::time_point processingTimeEnd
Processing time end.
uint64_t refusedConnectionCtr
Number of refused connections.
uint64_t acceptedConnectionCtr
Number of accepted connections.
Here is the call graph for this function:

◆ consumeStats() [2/2]

void TelnetStats::consumeStats ( const TelnetSessionStats & stat,
bool sessionClosed )

Updates statistics with session values

Parameters
[in]statStatistics values from session
[in]sessionClosedTrue if the provided session is closed

Definition at line 81 of file TelnetStats.cpp.

82{
84
85 _totalUploadBytes->Increment(static_cast<double>(stat.uploadBytes));
86 _totalDownloadBytes->Increment(static_cast<double>(stat.downloadBytes));
87
88 if (sessionClosed)
89 {
90 // Session durations
91 const auto sessionTime = static_cast<double>(
92 std::chrono::duration_cast<std::chrono::seconds>(stat.disconnectTime - stat.connectTime).count());
93 _sessionDuration->Observe(sessionTime);
94 if (sessionTime < _minSessionDuration->Value())
95 {
96 _minSessionDuration->Set(sessionTime);
97 }
98 if (sessionTime > _maxSessionDuration->Value())
99 {
100 _maxSessionDuration->Set(sessionTime);
101 }
102 }
103}
std::chrono::high_resolution_clock::time_point disconnectTime
Connection end time.
uint64_t failCmdCtr
Failed commands.
uint64_t successCmdCtr
Successful commands.
size_t downloadBytes
Downloaded bytes.
std::chrono::high_resolution_clock::time_point connectTime
Connection start time.
size_t uploadBytes
Uploaded bytes.
Here is the call graph for this function:

Member Data Documentation

◆ _activeConnection

prometheus::Gauge* TelnetStats::_activeConnection
private

Number of active connections.

Definition at line 36 of file TelnetStats.hpp.

◆ _infoFamily

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

Information metric family.

Definition at line 35 of file TelnetStats.hpp.

◆ _maxSessionDuration

prometheus::Gauge* TelnetStats::_maxSessionDuration
private

Maximum duration of sessions.

Definition at line 42 of file TelnetStats.hpp.

◆ _minSessionDuration

prometheus::Gauge* TelnetStats::_minSessionDuration
private

Minimum duration of sessions.

Definition at line 43 of file TelnetStats.hpp.

◆ _refusedConnection

prometheus::Counter* TelnetStats::_refusedConnection
private

Number of refused connections.

Definition at line 37 of file TelnetStats.hpp.

◆ _sessionDuration

prometheus::Summary* TelnetStats::_sessionDuration
private

Value of the duration of sessions.

Definition at line 41 of file TelnetStats.hpp.

◆ _totalConnection

prometheus::Counter* TelnetStats::_totalConnection
private

Number of total received connections.

Definition at line 38 of file TelnetStats.hpp.

◆ _totalDownloadBytes

prometheus::Counter* TelnetStats::_totalDownloadBytes
private

Total downloaded bytes.

Definition at line 40 of file TelnetStats.hpp.

◆ _totalUploadBytes

prometheus::Counter* TelnetStats::_totalUploadBytes
private

Total uploaded bytes.

Definition at line 39 of file TelnetStats.hpp.


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