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 +59,7 @@ The main C++ Prometheus library - [jupp0r/prometheus-cpp](https://github.com/jup
37
59
| Build system | Bazel (primary) + CMake | CMake or **just copy files**|
38
60
| Minimum boilerplate |~20 lines to create one counter |**2 lines** to create a counter and expose it (with global registry, see below) |
39
61
| 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`) |
62
+
| 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
63
| C++ standard | C++11 | C++11 |
42
64
| Thread-safe | Yes | Yes |
43
65
@@ -62,12 +84,12 @@ will work.
62
84
-**Low entry barrier** - a working counter with HTTP export is 2 lines of code (with global registry, see below)
63
85
-**Gradual complexity** - start simple, add families/labels/registries/custom types when needed
64
86
-**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
90
-**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
91
+
-**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**
92
+
-**Detailed examples** - see the [examples](examples) folder for usage patterns
71
93
72
94
---
73
95
@@ -149,7 +171,7 @@ int main() {
149
171
150
172
### 1. HTTP pull (recommended for long-running services)
151
173
152
-
The application runs an HTTP server. Prometheus scrapes it periodically.
174
+
The application runs an HTTP server. Prometheus scrapes it periodically ([example](examples/provide_via_http_pull_simple.cpp)).
153
175
154
176
```cpp
155
177
#include<prometheus/prometheus.h>
@@ -160,7 +182,7 @@ prometheus::http_server_t server (registry, "127.0.0.1:9100");
160
182
// → http://localhost:9100/metrics
161
183
```
162
184
163
-
**Multiple endpoints** for different metric domains:
185
+
**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`.
785
+
786
+
| Example | Description |
787
+
|---------|-------------|
788
+
| **Quick start** | |
789
+
| [`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. |
790
+
| **Export modes** | |
791
+
| [`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`. |
792
+
| [`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. |
793
+
| [`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. |
796
+
| **Metric types — all API levels** | |
797
+
| [`test_counter.cpp`](examples/test_counter.cpp) | Counter (`uint64_t`) — every way to create: global/explicit registry, untyped/typed family, all legacy APIs. |
798
+
| [`test_gauge.cpp`](examples/test_gauge.cpp) | Gauge (`int64_t`) — same full set of API variants. |
799
+
| [`test_histogram.cpp`](examples/test_histogram.cpp) | Histogram (`double`) — buckets, custom boundaries, same full set of API variants. |
800
+
| [`test_summary.cpp`](examples/test_summary.cpp) | Summary (`double`) — quantiles, custom quantile definitions, same full set of API variants. |
801
+
| [`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()`. |
806
+
| [`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. |
807
+
| [`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