4#include <prometheus/counter.h>
5#include <prometheus/gauge.h>
6#include <prometheus/info.h>
7#include <prometheus/summary.h>
12 const std::string &prependName)
17 throw std::invalid_argument(
"Can't init Telnet statistics. Registry is null");
20 const auto name = prependName.empty() ?
"telnet_" : prependName +
"_telnet_";
27 &prometheus::BuildInfo().Name(name.substr(0, name.size() - 1)).Help(
"Telnet server information").Register(*reg);
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"}});
36 .Name(name +
"active_connections")
37 .Help(
"Number of active connections")
41 .Name(name +
"refused_connections")
42 .Help(
"Number of refused connections")
46 .Name(name +
"received_connections")
47 .Help(
"Number of received connections")
53 &prometheus::BuildCounter().Name(name +
"uploaded_bytes").Help(
"Total uploaded bytes").Register(*reg).Add({});
55 .Name(name +
"downloaded_bytes")
56 .Help(
"Total downloaded bytes")
62 .Name(name +
"session_duration")
63 .Help(
"Duration of sessions")
67 .Name(name +
"maximum_session_duration")
68 .Help(
"Maximum duration of sessions")
72 .Name(name +
"minimum_session_duration")
73 .Help(
"Minimum duration of sessions")
91 const auto sessionTime =
static_cast<double>(
94 if (sessionTime < _minSessionDuration->Value())
void consumeBaseStats(uint64_t succeeded, uint64_t failed, double processingTime)
void initBaseStats(const std::shared_ptr< prometheus::Registry > ®, const std::string &name)
void consumeStats(const TelnetSessionStats &stat, bool sessionClosed)
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.
TelnetStats(const std::shared_ptr< prometheus::Registry > ®, uint16_t portNumber, const std::string &prependName="")
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.
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.