Skip to content
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,18 @@ jobs:
run: cargo hack check --each-feature --no-dev-deps --all

test-versions:
name: test-version (${{ matrix.name }})
needs: check
runs-on: ubuntu-latest
strategy:
matrix:
include:
- rustflags: "--cfg tokio_unstable -Dwarnings"
name: "tokio-unstable"
- rustflags: "-Dwarnings"
name: "stable"
env:
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
RUSTFLAGS: ${{ matrix.rustflags }}
steps:
- uses: actions/checkout@master
- uses: actions-rs/toolchain@v1
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ rt = ["tokio"]
tokio-stream = "0.1.11"
futures-util = "0.3.19"
pin-project-lite = "0.2.7"
tokio = { version = "1.41.0", features = ["rt", "time", "net"], optional = true }
tokio = { version = "1.45.1", features = ["rt", "time", "net"], optional = true }
metrics = { version = "0.24", optional = true }

[dev-dependencies]
Expand All @@ -36,7 +36,7 @@ futures = "0.3.21"
num_cpus = "1.13.1"
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.79"
tokio = { version = "1.41.0", features = ["full", "rt", "time", "macros", "test-util"] }
tokio = { version = "1.45.1", features = ["full", "rt", "time", "macros", "test-util"] }
metrics-util = { version = "0.19", features = ["debugging"] }
metrics = { version = "0.24" }
metrics-exporter-prometheus = { version = "0.16", features = ["uds-listener"] }
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ loop {

## Getting Started With Runtime Metrics

This unstable functionality requires `tokio_unstable`, and the `rt` crate
Not all runtime metrics are stable. Using unstable metrics requires `tokio_unstable`, and the `rt` crate
feature. To enable `tokio_unstable`, the `--cfg` `tokio_unstable` must be passed
to `rustc` when compiling. You can do this by setting the `RUSTFLAGS`
environment variable before compiling your application; e.g.:
Expand All @@ -170,6 +170,17 @@ More information about where cargo looks for configuration files can be found
Missing this configuration file during compilation will cause tokio-metrics to not work, and alternating
between building with and without this configuration file included will cause full rebuilds of your project.

### Stable Runtime Metrics

- **[`workers_count`]**
- **[`total_park_count`]**
- **[`max_park_count`]**
- **[`min_park_count`]**
- **[`total_busy_duration`]**
- **[`max_busy_duration`]**
- **[`min_busy_duration`]**
- **[`global_queue_depth`]**

### Collecting Runtime Metrics directly

The `rt` feature of `tokio-metrics` is on by default; simply check that you do
Expand Down
6 changes: 3 additions & 3 deletions examples/axum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ async fn main() {

let intervals = root_intervals.zip(create_user_intervals);
for (root_route, (create_user_route, create_user_insert)) in intervals {
println!("root_route = {:#?}", root_route);
println!("create_user_route = {:#?}", create_user_route);
println!("create_user_insert = {:#?}", create_user_insert);
println!("root_route = {root_route:#?}");
println!("create_user_route = {create_user_route:#?}");
println!("create_user_insert = {create_user_insert:#?}");
tokio::time::sleep(metrics_frequency).await;
}
});
Expand Down
2 changes: 1 addition & 1 deletion examples/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
tokio::spawn(async move {
for interval in runtime_monitor.intervals() {
// pretty-print the metric interval
println!("{:?}", interval);
println!("{interval:?}");
// wait 500ms
tokio::time::sleep(Duration::from_millis(500)).await;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
tokio::spawn(async move {
for deltas in metrics_monitor.intervals() {
// pretty-print the metric deltas
println!("{:?}", deltas);
println!("{deltas:?}");
// wait 500ms
tokio::time::sleep(Duration::from_millis(500)).await;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
tokio::spawn(async move {
for deltas in metrics_monitor.intervals() {
// pretty-print the metric deltas
println!("{:?}", deltas);
println!("{deltas:?}");
// wait 500ms
tokio::time::sleep(Duration::from_millis(500)).await;
}
Expand Down
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
//! ```

#![cfg_attr(
all(tokio_unstable, feature = "rt"),
feature = "rt",
doc = r##"
### Monitoring runtime metrics (unstable)
### Monitoring runtime metrics
[Monitor][RuntimeMonitor] key [metrics][RuntimeMetrics] of a tokio runtime.
**This functionality requires `tokio_unstable` and the crate feature `rt`.**
**This functionality requires crate feature `rt` and some metrics require `tokio_unstable`.**

In the below example, a [`RuntimeMonitor`] is [constructed][RuntimeMonitor::new] and
three tasks are spawned and awaited; meanwhile, a fourth task prints [metrics][RuntimeMetrics]
Expand Down Expand Up @@ -104,7 +104,7 @@ async fn do_work() {
}
```

### Monitoring and publishing runtime metrics (unstable)
### Monitoring and publishing runtime metrics

If the `metrics-rs-integration` feature is additionally enabled, this crate allows
publishing runtime metrics externally via [metrics-rs](metrics) exporters.
Expand Down Expand Up @@ -156,8 +156,8 @@ async fn main() {
macro_rules! cfg_rt {
($($item:item)*) => {
$(
#[cfg(all(tokio_unstable, feature = "rt"))]
#[cfg_attr(docsrs, doc(cfg(all(tokio_unstable, feature = "rt"))))]
#[cfg(feature = "rt")]
#[cfg_attr(docsrs, doc(cfg(feature = "rt")))]
$item
)*
};
Expand All @@ -172,10 +172,10 @@ cfg_rt! {
};
}

#[cfg(all(tokio_unstable, feature = "rt", feature = "metrics-rs-integration"))]
#[cfg(all(feature = "rt", feature = "metrics-rs-integration"))]
#[cfg_attr(
docsrs,
doc(cfg(all(tokio_unstable, feature = "rt", feature = "metrics-rs-integration")))
doc(cfg(all(feature = "rt", feature = "metrics-rs-integration")))
)]
pub use runtime::metrics_rs_integration::{RuntimeMetricsReporter, RuntimeMetricsReporterBuilder};

Expand Down
Loading
Loading