Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
network_metric_event.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
17#pragma once
18
19#include <chrono>
20#include <map>
21#include <string>
22
24
30{
31 counter,
32 gauge,
33 histogram,
34 summary
35};
36
55{
56 std::string name;
57 double value;
58 std::string unit;
60 std::chrono::steady_clock::time_point timestamp;
61 std::map<std::string, std::string> labels;
72 const std::string& metric_name,
73 double metric_value,
75 const std::map<std::string, std::string>& metric_labels = {},
76 const std::string& metric_unit = "")
77 : name(metric_name)
78 , value(metric_value)
79 , unit(metric_unit)
80 , type(metric_type)
81 , timestamp(std::chrono::steady_clock::now())
82 , labels(metric_labels)
83 {
84 }
85
90 : value(0.0)
92 , timestamp(std::chrono::steady_clock::now())
93 {
94 }
95
100
105
110
114 network_metric_event& operator=(network_metric_event&&) noexcept = default;
115};
116
122{
123 std::string connection_id;
124 std::string event_type;
125 std::string protocol;
126 std::string remote_address;
127 std::chrono::steady_clock::time_point timestamp;
128 std::map<std::string, std::string> labels;
129
131 const std::string& conn_id,
132 const std::string& evt_type,
133 const std::string& proto = "tcp",
134 const std::string& remote = "",
135 const std::map<std::string, std::string>& lbls = {})
136 : connection_id(conn_id)
137 , event_type(evt_type)
138 , protocol(proto)
139 , remote_address(remote)
140 , timestamp(std::chrono::steady_clock::now())
141 , labels(lbls)
142 {
143 }
144
146 : timestamp(std::chrono::steady_clock::now())
147 {
148 }
149
153 network_connection_event& operator=(network_connection_event&&) noexcept = default;
154};
155
161{
162 std::string connection_id;
163 std::string direction;
164 std::size_t bytes;
165 std::size_t packets;
166 std::chrono::steady_clock::time_point timestamp;
167 std::map<std::string, std::string> labels;
168
170 const std::string& conn_id,
171 const std::string& dir,
172 std::size_t byte_count,
173 std::size_t packet_count = 1,
174 const std::map<std::string, std::string>& lbls = {})
175 : connection_id(conn_id)
176 , direction(dir)
177 , bytes(byte_count)
178 , packets(packet_count)
179 , timestamp(std::chrono::steady_clock::now())
180 , labels(lbls)
181 {
182 }
183
185 : bytes(0)
186 , packets(0)
187 , timestamp(std::chrono::steady_clock::now())
188 {
189 }
190
194 network_transfer_event& operator=(network_transfer_event&&) noexcept = default;
195};
196
202{
203 std::string connection_id;
204 double latency_ms;
205 std::string operation;
206 std::chrono::steady_clock::time_point timestamp;
207 std::map<std::string, std::string> labels;
208
210 const std::string& conn_id,
211 double latency,
212 const std::string& op = "roundtrip",
213 const std::map<std::string, std::string>& lbls = {})
214 : connection_id(conn_id)
215 , latency_ms(latency)
216 , operation(op)
217 , timestamp(std::chrono::steady_clock::now())
218 , labels(lbls)
219 {
220 }
221
223 : latency_ms(0.0)
224 , timestamp(std::chrono::steady_clock::now())
225 {
226 }
227
231 network_latency_event& operator=(network_latency_event&&) noexcept = default;
232};
233
239{
240 std::string connection_id;
241 bool is_alive;
243 std::size_t missed_heartbeats;
245 std::chrono::steady_clock::time_point timestamp;
246 std::map<std::string, std::string> labels;
247
249 const std::string& conn_id,
250 bool alive,
251 double response_time = 0.0,
252 std::size_t missed = 0,
253 double loss_rate = 0.0,
254 const std::map<std::string, std::string>& lbls = {})
255 : connection_id(conn_id)
256 , is_alive(alive)
257 , response_time_ms(response_time)
258 , missed_heartbeats(missed)
259 , packet_loss_rate(loss_rate)
260 , timestamp(std::chrono::steady_clock::now())
261 , labels(lbls)
262 {
263 }
264
266 : is_alive(false)
267 , response_time_ms(0.0)
268 , missed_heartbeats(0)
269 , packet_loss_rate(0.0)
270 , timestamp(std::chrono::steady_clock::now())
271 {
272 }
273
277 network_health_event& operator=(network_health_event&&) noexcept = default;
278};
279
280} // namespace kcenon::network::events
network_metric_type
Types of network metrics.
sliding_histogram latency
Specialized event for connection-related metrics.
network_connection_event(const std::string &conn_id, const std::string &evt_type, const std::string &proto="tcp", const std::string &remote="", const std::map< std::string, std::string > &lbls={})
network_connection_event & operator=(const network_connection_event &)=default
network_connection_event(network_connection_event &&) noexcept=default
network_connection_event(const network_connection_event &)=default
std::chrono::steady_clock::time_point timestamp
Specialized event for connection health status.
std::chrono::steady_clock::time_point timestamp
std::map< std::string, std::string > labels
network_health_event(const std::string &conn_id, bool alive, double response_time=0.0, std::size_t missed=0, double loss_rate=0.0, const std::map< std::string, std::string > &lbls={})
network_health_event(const network_health_event &)=default
network_health_event(network_health_event &&) noexcept=default
network_health_event & operator=(const network_health_event &)=default
Specialized event for latency measurements.
std::map< std::string, std::string > labels
network_latency_event(network_latency_event &&) noexcept=default
network_latency_event & operator=(const network_latency_event &)=default
network_latency_event(const network_latency_event &)=default
network_latency_event(const std::string &conn_id, double latency, const std::string &op="roundtrip", const std::map< std::string, std::string > &lbls={})
std::chrono::steady_clock::time_point timestamp
Event for publishing network metrics via EventBus.
network_metric_event & operator=(const network_metric_event &)=default
Copy assignment operator.
std::chrono::steady_clock::time_point timestamp
network_metric_event(const network_metric_event &)=default
Copy constructor (required for EventType concept)
network_metric_event(const std::string &metric_name, double metric_value, network_metric_type metric_type=network_metric_type::counter, const std::map< std::string, std::string > &metric_labels={}, const std::string &metric_unit="")
Construct a network metric event.
std::map< std::string, std::string > labels
network_metric_event(network_metric_event &&) noexcept=default
Move constructor.
Specialized event for data transfer metrics.
network_transfer_event & operator=(const network_transfer_event &)=default
network_transfer_event(const std::string &conn_id, const std::string &dir, std::size_t byte_count, std::size_t packet_count=1, const std::map< std::string, std::string > &lbls={})
network_transfer_event(const network_transfer_event &)=default
std::chrono::steady_clock::time_point timestamp
network_transfer_event(network_transfer_event &&) noexcept=default
std::map< std::string, std::string > labels