-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcheck_global_objects.cpp
More file actions
45 lines (39 loc) · 1.66 KB
/
check_global_objects.cpp
File metadata and controls
45 lines (39 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* prometheus-cpp-lite — header-only C++ library for exposing Prometheus metrics
* https://github.com/biaks/prometheus-cpp-lite
*
* Copyright (c) 2026 Yan Kryukov ianiskr@gmail.com
* Licensed under the MIT License
*
* =============================================================================
* check_global_objects.cpp — Global objects usage example
*
* Demonstrates using pre-defined global objects from prometheus-cpp-lite-full:
* global_registry, file_saver, http_server, http_pusher.
* All metric types are created with the global registry and exposed via
* all three export modes simultaneously (HTTP pull, HTTP push, file).
*
*/
#include <prometheus/prometheus.h>
using namespace prometheus;
int main () {
counter_metric_t requests ("http_requests_total", "Total requests");
gauge_metric_t active ("active_connections", "Open connections");
histogram_metric_t latency ("request_duration_seconds", "Request latency");
summary_metric_t response ("response_time_seconds", "Response time");
benchmark_metric_t uptime ("uptime_seconds", "Process uptime");
file_saver. start(std::chrono::seconds(5), "./metrics.txt");
http_server.start("127.0.0.1:9091");
http_pusher.start(std::chrono::seconds(5), "http://localhost:9091/metrics/job/test");
uptime.start();
for (int i = 0; i < 60; ++i) {
std::this_thread::sleep_for(std::chrono::seconds(1));
requests++;
active.Set (10 + std::rand() % 50);
latency.Observe (0.001 * (std::rand() % 1000));
response.Observe (0.001 * (std::rand() % 500));
if (i % 10 == 0)
std::cout << global_registry.serialize() << std::endl;
}
uptime.stop();
}