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
Copy file name to clipboardExpand all lines: README.md
+46Lines changed: 46 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -153,6 +153,8 @@ More information about where cargo looks for configuration files can be found
153
153
Missing this configuration file during compilation will cause tokio-metrics to not work, and alternating
154
154
between building with and without this configuration file included will cause full rebuilds of your project.
155
155
156
+
### Collecting Runtime Metrics directly
157
+
156
158
The `rt` feature of `tokio-metrics` is on by default; simply check that you do
157
159
not set `default-features = false` when declaring it as a dependency; e.g.:
158
160
```toml
@@ -181,6 +183,50 @@ tokio::spawn(do_work());
181
183
tokio::spawn(do_work());
182
184
```
183
185
186
+
### Collecting Runtime Metrics via metrics.rs
187
+
188
+
If you also enable the `metrics-rs-integration` feature, you can use [metrics.rs] exporters to export metrics outside of your process. `metrics.rs` supports a variety of exporters, including [Prometheus].
189
+
190
+
The exported metrics by default will be exported with their name, preceded by `tokio_`. For example, `tokio_workers_count` for the [`workers_count`] metric. This can be customized by using the `with_metrics_tranformer` function.
191
+
192
+
If you want to use [Prometheus], you could have this `Cargo.toml`:
193
+
194
+
```toml
195
+
[dependencies]
196
+
tokio-metrics = { version = "0.4.1", features = ["metrics-rs-integration"] }
197
+
metrics = "0.24"
198
+
# You don't actually need to use the Prometheus exporter with uds-listener enabled,
199
+
# it's just here as an example.
200
+
metrics-exporter-prometheus = { version = "0.16", features = ["uds-listener"] }
201
+
```
202
+
203
+
Then, you can launch a metrics exporter:
204
+
```rust
205
+
// This makes metrics visible via a local Unix socket with name prometheus.sock
206
+
// You probably want to do it differently.
207
+
//
208
+
// If you use this exporter, you can access the metrics for debugging
209
+
// by running `curl --unix-socket prometheus.sock localhost`.
0 commit comments