Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
network_metrics_example.cpp
Go to the documentation of this file.
1/*****************************************************************************
2BSD 3-Clause License
3
4Copyright (c) 2024, 🍀☀🌕🌥 🌊
5All rights reserved.
6*****************************************************************************/
7
26
27#include <cstdlib>
28#include <iostream>
29#include <string>
30
31using namespace kcenon::network;
32
33int main()
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.
Unified metrics header for network_system.
constexpr const char * CONNECTIONS_ACTIVE
Main namespace for all Network System components.