Expand description
Metrics for a tokio runtime: its workers, its tasks, the tasks waiting to run, and how busy it is. Part of oxtel.
One line records them every ten seconds, for as long as the value it returns is kept:
let _runtime_metrics = oxtel_tokio::record(&tokio::runtime::Handle::current());| Metric | Type | What it is |
|---|---|---|
oxtel.tokio.worker.count | gauge, {thread} | Worker threads. |
oxtel.tokio.task.count | gauge, {task} | Tasks spawned and not yet finished. |
oxtel.tokio.global_queue.length | gauge, {task} | Tasks waiting in the global queue, where tasks spawned from outside the runtime go. A queue that keeps growing means the workers can’t keep up. |
oxtel.tokio.utilization | gauge, 1 | The share of the workers’ time spent running tasks since the last recording, from 0 to 1. Near 1, the runtime is saturated. |
Built with --cfg tokio_unstable, as tokio’s own unstable metrics
need, it also records the blocking pool, where spawn_blocking work
runs:
| Metric | Type | What it is |
|---|---|---|
oxtel.tokio.blocking.thread.count | gauge, {thread} | Blocking threads, by oxtel.tokio.thread.state: busy or idle. |
oxtel.tokio.blocking.queue.length | gauge, {task} | Blocking work waiting for a thread. |
The OpenTelemetry conventions don’t define tokio metrics, so these are
named under oxtel., shaped like the conventions’ own runtime metrics
(dotnet.thread_pool.* and nodejs.eventloop.utilization). They’re
recorded through metrics, so they go wherever the program’s recorder
sends them: with oxtel::init(), to OTLP or Prometheus.
The recording happens on a thread of its own, so it goes on when the
runtime is too busy to run anything else, which is when it matters.
Sampler records on demand instead, such as just before serving a
scrape, and names runtimes apart when a program has several.
Structs§
- Recording
- A runtime’s metrics being recorded. Dropping it stops the recording.
- Sampler
- Records one runtime’s metrics when asked. It remembers the last time it recorded, to say how busy the runtime has been since.
Constants§
- DEFAULT_
INTERVAL - How often
recordrecords.
Functions§
- describe_
metrics - Gives the current
metricsrecorder the descriptions of the runtime metrics.Sampler::newdoes this. - record
- Records the runtime’s metrics every ten seconds, on
a thread of its own, until the returned
Recordingis dropped.