You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -37,7 +60,7 @@ The main C++ Prometheus library - [jupp0r/prometheus-cpp](https://github.com/jup
37
60
| Build system | Bazel (primary) + CMake | CMake or **just copy files**|
38
61
| Minimum boilerplate |~20 lines to create one counter |**2 lines** to create a counter and expose it (with global registry, see below) |
39
62
| Value types |`double` only |`uint64_t` (default), `double`, `int64_t`, or any arithmetic type |
40
-
| Metric types | counter, gauge, histogram, summary|`counter`, `gauge`, `histogram`, `summary`, `info`, **`benchmark`** or you can make your own custom metric class (see `add_custom_metric_class.cpp` for a complete working example of a new user-defined metric `min_max_t`) |
63
+
| Metric types |`counter`, `gauge`, `histogram`, `summary`, `info`|[`counter`](examples/test_counter.cpp), [`gauge`](examples/test_gauge.cpp), [`histogram`](examples/test_histogram.cpp), [`summary`](examples/test_summary.cpp), `info`, **[`benchmark`](examples/test_benchmark.cpp)**- or [make your own](examples/add_custom_metric_class.cpp)|
41
64
| C++ standard | C++11 | C++11 |
42
65
| Thread-safe | Yes | Yes |
43
66
@@ -62,12 +85,12 @@ will work.
62
85
-**Low entry barrier** - a working counter with HTTP export is 2 lines of code (with global registry, see below)
63
86
-**Gradual complexity** - start simple, add families/labels/registries/custom types when needed
64
87
-**Multiple value types** - `uint64_t` (fast integer), `double` (Prometheus-compatible), `int64_t`, or custom
-**Simplest way with global_registry** - add metrics anywhere in your code without passing registry references
68
91
-**prometheus-cpp compatible** - supports the same Builder/Family/Registry API style
69
-
-**Extensible** - each metric type is self-contained in one header; **you can add your own metric by following the same pattern** (see `add_custom_metric_class.cpp` example)
70
-
-**Detailed examples** - see the examples folder for usage patterns
92
+
-**Extensible** - each metric type is self-contained in one header; **you can [add your own](examples/add_custom_metric_class.cpp) metric by following the same pattern**
93
+
-**Detailed examples** - see the [examples](examples) folder for usage patterns
71
94
72
95
---
73
96
@@ -149,7 +172,7 @@ int main() {
149
172
150
173
### 1. HTTP pull (recommended for long-running services)
151
174
152
-
The application runs an HTTP server. Prometheus scrapes it periodically.
175
+
The application runs an HTTP server. Prometheus scrapes it periodically ([example](examples/provide_via_http_pull_simple.cpp)).
153
176
154
177
```cpp
155
178
#include<prometheus/prometheus.h>
@@ -160,7 +183,7 @@ prometheus::http_server_t server (registry, "127.0.0.1:9100");
160
183
// → http://localhost:9100/metrics
161
184
```
162
185
163
-
**Multiple endpoints** for different metric domains:
186
+
**Multiple endpoints** for different metric domains ([example](examples/provide_via_http_pull_advanced.cpp)):
The examples use `prometheus-cpp-lite` (header-only target) and define
759
-
`global_registry` in each `.cpp` file. To use the pre-defined global
760
-
objects instead, link against `prometheus-cpp-lite-full`.
786
+
787
+
| Example | Description |
788
+
|---------|-------------|
789
+
| **Quick start** | |
790
+
| [`quick_start.cpp`](examples/quick_start.cpp) | All metric types + HTTP server in one file. The code from the README "All metric types at a glance" section. |
791
+
| **Export modes** | |
792
+
| [`provide_via_http_pull_simple.cpp`](examples/provide_via_http_pull_simple.cpp) | Shortest HTTP pull server — 3 lines of setup, `curl http://localhost:9100/metrics`. |
793
+
| [`provide_via_http_pull_advanced.cpp`](examples/provide_via_http_pull_advanced.cpp) | Single-registry and multi-path (multiple registries at different URLs) HTTP pull examples. |
794
+
| [`provide_via_http_push_simple.cpp`](examples/provide_via_http_push_simple.cpp) | Shortest periodic push to Pushgateway — 3 lines of setup. |
| [`provide_via_textfile.cpp`](examples/provide_via_textfile.cpp) | Periodic save to `.prom` file for node_exporter textfile collector. |
797
+
| **Metric types — all API levels** | |
798
+
| [`test_counter.cpp`](examples/test_counter.cpp) | Counter (`uint64_t`) — every way to create: global/explicit registry, untyped/typed family, all legacy APIs. |
799
+
| [`test_gauge.cpp`](examples/test_gauge.cpp) | Gauge (`int64_t`) — same full set of API variants. |
800
+
| [`test_histogram.cpp`](examples/test_histogram.cpp) | Histogram (`double`) — buckets, custom boundaries, same full set of API variants. |
801
+
| [`test_summary.cpp`](examples/test_summary.cpp) | Summary (`double`) — quantiles, custom quantile definitions, same full set of API variants. |
802
+
| [`test_benchmark.cpp`](examples/test_benchmark.cpp) | Benchmark (`double`) — profile method execution time, same full set of API variants. |
| [`use_metrics_in_class_simple.cpp`](examples/use_metrics_in_class_simple.cpp) | Simplest way to add metrics to a class — declare as members, increment in methods, expose via `http_server.start()`. |
807
+
| [`use_benchmark_in_class_simple.cpp`](examples/use_benchmark_in_class_simple.cpp) | Profile method execution time with `benchmark_metric_t` — `start()`/`stop()` around code phases. |
808
+
| [`use_metrics_in_class_advanced.cpp`](examples/use_metrics_in_class_advanced.cpp) | Dynamic per-instance metrics with labels — connection pool where each connection creates metrics at runtime via `make_metric<>()` without storing families. |
| [`add_custom_metric_class.cpp`](examples/add_custom_metric_class.cpp) | How to create your own metric type (`min_max_t` — tracks min/max of observed values). Demonstrates owning/reference forms, all family wrappers, and the Builder API. |
0 commit comments