Skip to content

Expose All Metrics in tokio::runtime::RuntimeMetrics? #61

@AlJohri

Description

@AlJohri

I've made the mistake a few times now of thinking a metric doesn't exist and finding it is in tokio::runtime::RuntimeMetrics rather than this crate.

Some examples of this are:

  • active_tasks_count
  • num_blocking_threads
  • num_idle_blocking_threads
  • blocking_queue_depth
  • io_driver_fd_registered_count
  • io_driver_fd_deregistered_count

Is there a way to expose all of the available tokio metrics here and keep them in sync?

Currently we use tokio-metrics for most metrics and then manually get the missing ones from the runtime handle:

struct AdditionalTokioRuntimeMetrics {
    active_tasks_count: usize,
    num_blocking_threads: usize,
    num_idle_blocking_threads: usize,
    blocking_queue_depth: usize,
}

// NOTE: some metrics are not available from `tokio_metrics::RuntimeMetrics` so instead we
// get it from `tokio::runtime::RuntimeMetrics`
fn get_additional_tokio_metrics(
    runtime: tokio::runtime::RuntimeMetrics,
) -> AdditionalTokioRuntimeMetrics {
    AdditionalTokioRuntimeMetrics {
        active_tasks_count: runtime.active_tasks_count(),
        num_blocking_threads: runtime.num_blocking_threads(),
        num_idle_blocking_threads: runtime.num_idle_blocking_threads(),
        blocking_queue_depth: runtime.blocking_queue_depth(),
    }
}

Hoping to remove this snippet of code and rely exclusively on tokio-metrics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions