@@ -39,35 +39,34 @@ using namespace prometheus;
3939// curl http://localhost:9100/metrics
4040// =============================================================================
4141
42- void example_simple () {
43- std::cout << " \n === Example 1: Simple mode — single registry at /metrics ===\n " ;
44- std::cout << " Listening on http://localhost:9100/metrics for 10 seconds...\n\n " ;
42+ void example_simple () {
43+ std::cout << " \n === Example 1: Simple mode — single registry at /metrics ===\n " ;
44+ std::cout << " Listening on http://localhost:9100/metrics for 10 seconds...\n\n " ;
4545
4646 // 1. Create a shared registry.
47- std::shared_ptr< registry_t > registry = std::make_shared<registry_t >();
47+ auto registry = std::make_shared<registry_t >();
4848
4949 // 2. Create metrics inside it.
5050 counter_metric_t requests (registry, " http_requests_total" , " Total HTTP requests" );
5151 gauge_metric_t active (registry, " active_connections" , " Currently open connections" );
5252
5353 // 3. Start the HTTP server — metrics are now available at http://localhost:9100/metrics
54- http_server_t server ({{127 ,0 ,0 ,1 }, 9100 }, registry);
54+ http_server_t server ({{127 ,0 ,0 ,1 }, 9100 }, registry, " /metrics " , log_e::info );
5555
5656 // Simulate application work.
5757 for (int i = 0 ; i < 10 ; ++i) {
5858 std::this_thread::sleep_for (std::chrono::seconds (1 ));
5959
60- int rnd = std::rand () % 10 ;
61- requests += rnd;
62- active.Set (5 + std::rand () % 20 );
60+ requests += std::rand () % 10 ;
61+ active = 5 + std::rand () % 20 ;
6362
6463 std::cout << " [simple] tick " << (i + 1 ) << " /10"
65- << " requests=" << requests.Get ()
66- << " active=" << active.Get () << std::endl;
64+ << " requests=" << requests.Get ()
65+ << " active=" << active.Get () << std::endl;
6766 }
6867
6968 // Server stops automatically when it goes out of scope.
70- std::cout << " Stopped.\n " ;
69+ std::cout << " Stopped.\n " ;
7170}
7271
7372// =============================================================================
@@ -80,55 +79,55 @@ void example_simple() {
8079// curl http://localhost:9200/metrics/sys
8180// =============================================================================
8281
83- void example_multipath () {
84- std::cout << " \n === Example 2: Multi-path mode — multiple registries at different paths ===\n "
85- << " Listening on http://localhost:9200 for 10 seconds...\n "
86- << " /metrics/app — application metrics\n "
87- << " /metrics/sys — system metrics\n\n " ;
82+ void example_multipath () {
83+ std::cout << " \n === Example 2: Multi-path mode — multiple registries at different paths ===\n "
84+ << " Listening on http://localhost:9200 for 10 seconds...\n "
85+ << " /metrics/app — application metrics\n "
86+ << " /metrics/sys — system metrics\n\n " ;
8887
8988 // 1. Create separate registries for different metric domains.
90- std::shared_ptr< registry_t > app_registry = std::make_shared<registry_t >();
91- std::shared_ptr< registry_t > sys_registry = std::make_shared<registry_t >();
89+ auto app_registry = std::make_shared<registry_t >();
90+ auto sys_registry = std::make_shared<registry_t >();
9291
9392 // 2. Populate each registry with its own metrics.
94- counter_metric_t orders_total (app_registry, " orders_total" , " Total orders processed" );
95- gauge_metric_t queue_size (app_registry, " queue_size" , " Current queue depth" );
93+ counter_metric_t orders_total (app_registry, " orders_total" , " Total orders processed" );
94+ gauge_metric_t queue_size (app_registry, " queue_size" , " Current queue depth" );
9695
9796 gauge_metric_t cpu_usage (sys_registry, " cpu_usage_percent" , " CPU usage percentage" );
9897 gauge_metric_t memory_used_mb (sys_registry, " memory_used_mb" , " Memory usage in MB" );
9998
10099 // 3. Create the server and register each registry under its own path.
101100 http_server_t server;
102- server.add_endpoint (app_registry, " /metrics/app" );
103- server.add_endpoint (sys_registry, " /metrics/sys" );
104- server.start ({{127 ,0 ,0 ,1 }, 9200 });
101+ server.add_endpoint (app_registry, " /metrics/app" );
102+ server.add_endpoint (sys_registry, " /metrics/sys" );
103+ server.start ({{127 ,0 ,0 ,1 }, 9200 }, log_e::info );
105104
106105 // Simulate application work.
107106 for (int i = 0 ; i < 10 ; ++i) {
108107 std::this_thread::sleep_for (std::chrono::seconds (1 ));
109108
110- orders_total += 1 + std::rand () % 5 ;
111- queue_size. Set ( std::rand () % 50 ) ;
109+ orders_total += 1 + std::rand () % 5 ;
110+ queue_size = std::rand () % 50 ;
112111
113- cpu_usage. Set ( 10 + std::rand () % 80 ) ;
114- memory_used_mb. Set ( 200 + std::rand () % 300 ) ;
112+ cpu_usage = 10 + std::rand () % 80 ;
113+ memory_used_mb = 200 + std::rand () % 300 ;
115114
116115 std::cout << " [multi] tick " << (i + 1 ) << " /10"
117- << " orders=" << orders_total.Get ()
118- << " queue=" << queue_size.Get ()
119- << " cpu=" << cpu_usage.Get () << " %"
120- << " mem=" << memory_used_mb.Get () << " MB" << std::endl;
116+ << " orders=" << orders_total.Get ()
117+ << " queue=" << queue_size.Get ()
118+ << " cpu=" << cpu_usage.Get () << " %"
119+ << " mem=" << memory_used_mb.Get () << " MB" << std::endl;
121120 }
122121
123122 // Server stops automatically when it goes out of scope.
124- std::cout << " Stopped.\n " ;
123+ std::cout << " Stopped.\n " ;
125124}
126125
127126// =============================================================================
128127// main
129128// =============================================================================
130129
131- int main () {
130+ int main () {
132131 std::cout << " === HTTP Pull endpoint examples ===\n " ;
133132 std::cout << " Use curl or a browser to fetch metrics while the examples run.\n " ;
134133
0 commit comments