Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AlJohri opened this issue Jun 23, 2024 · 2 comments
Open

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

AlJohri opened this issue Jun 23, 2024 · 2 comments

Comments

@AlJohri
Copy link

AlJohri commented Jun 23, 2024

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.

@AlJohri
Copy link
Author

AlJohri commented Jun 24, 2024

@mox692
Copy link
Member

mox692 commented Jun 24, 2024

I don't see any harm in adding these metrics as well.

Note that some of these metrics are not stabilized yet, so the they could be changed or removed. (See also tokio-rs/tokio#6546.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants