Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
network_metrics_example.cpp File Reference

Demonstrates network metrics collection and reporting. More...

#include <kcenon/network/metrics/metrics.h>
#include <cstdlib>
#include <iostream>
#include <string>
Include dependency graph for network_metrics_example.cpp:

Go to the source code of this file.

Functions

int main ()
 

Detailed Description

Demonstrates network metrics collection and reporting.

Definition in file network_metrics_example.cpp.

Function Documentation

◆ main()

int main ( )

Definition at line 33 of file network_metrics_example.cpp.

34{
35 std::cout << "=== Network Metrics Example ===" << std::endl;
36
37 // 1. Histogram for latency tracking
38 std::cout << "\n1. Histogram (latency tracking):" << std::endl;
39 metrics::histogram latency_hist;
40
41 // Simulate latency measurements
42 double latencies[] = {1.2, 2.5, 1.8, 3.1, 2.0, 1.5, 4.2, 2.8, 1.9, 2.3};
43 for (double lat : latencies)
44 {
45 latency_hist.record(lat);
46 }
47
48 auto snapshot = latency_hist.get_snapshot();
49 std::cout << " Recorded 10 latency measurements" << std::endl;
50 std::cout << " Snapshot retrieved" << std::endl;
51
52 // 2. Metric reporter (static convenience methods)
53 std::cout << "\n2. Metric reporter:" << std::endl;
55 std::cout << " Reported: connection accepted" << std::endl;
56
58 std::cout << " Reported: 1024 bytes sent" << std::endl;
59
61 std::cout << " Reported: 2.5ms latency" << std::endl;
62
64 std::cout << " Reported: connection failed (timeout)" << std::endl;
65
66 // 3. Standard metric names
67 std::cout << "\n3. Standard metric names:" << std::endl;
68 std::cout << " Active connections: " << metrics::metric_names::CONNECTIONS_ACTIVE << std::endl;
69 std::cout << " Bytes sent: " << metrics::metric_names::BYTES_SENT << std::endl;
70 std::cout << " Latency: " << metrics::metric_names::LATENCY_MS << std::endl;
71
72 std::cout << "\nDone." << std::endl;
73 return 0;
74}
Thread-safe histogram for capturing value distributions.
Definition histogram.h:106
void record(double value)
Record a value observation.
static void report_latency(double ms)
Report network latency.
static void report_connection_failed(const std::string &reason)
Report a failed connection attempt.
static void report_connection_accepted()
Report a new connection accepted.
static void report_bytes_sent(size_t bytes)
Report bytes sent.
constexpr const char * CONNECTIONS_ACTIVE

References kcenon::network::metrics::metric_names::BYTES_SENT, kcenon::network::metrics::metric_names::CONNECTIONS_ACTIVE, kcenon::network::metrics::metric_names::LATENCY_MS, kcenon::network::metrics::histogram::record(), kcenon::network::metrics::metric_reporter::report_bytes_sent(), kcenon::network::metrics::metric_reporter::report_connection_accepted(), kcenon::network::metrics::metric_reporter::report_connection_failed(), and kcenon::network::metrics::metric_reporter::report_latency().

Here is the call graph for this function: