Skip to main content

Crate oxtel_tokio

Crate oxtel_tokio 

Source
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());
MetricTypeWhat it is
oxtel.tokio.worker.countgauge, {thread}Worker threads.
oxtel.tokio.task.countgauge, {task}Tasks spawned and not yet finished.
oxtel.tokio.global_queue.lengthgauge, {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.utilizationgauge, 1The 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:

MetricTypeWhat it is
oxtel.tokio.blocking.thread.countgauge, {thread}Blocking threads, by oxtel.tokio.thread.state: busy or idle.
oxtel.tokio.blocking.queue.lengthgauge, {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 record records.

Functions§

describe_metrics
Gives the current metrics recorder the descriptions of the runtime metrics. Sampler::new does this.
record
Records the runtime’s metrics every ten seconds, on a thread of its own, until the returned Recording is dropped.