|
24 | 24 | }, |
25 | 25 | time::Instant, |
26 | 26 | }, |
| 27 | + tokio_metrics::RuntimeMonitor, |
27 | 28 | tracing::{ |
| 29 | + error, |
28 | 30 | field::{ |
29 | 31 | Field, |
30 | 32 | Visit, |
@@ -165,6 +167,84 @@ where |
165 | 167 | } |
166 | 168 | } |
167 | 169 |
|
| 170 | +pub async fn update_tokio_runtime_metrics(runtime_monitor: &RuntimeMonitor) { |
| 171 | + let Some(metrics) = runtime_monitor.intervals().next() else { |
| 172 | + error!("No tokio runtime metrics available"); |
| 173 | + return; |
| 174 | + }; |
| 175 | + |
| 176 | + // Worker metrics |
| 177 | + metrics::gauge!("tokio_workers_count").set(metrics.workers_count as f64); |
| 178 | + |
| 179 | + // Park count metrics |
| 180 | + metrics::gauge!("tokio_total_park_count").set(metrics.total_park_count as f64); |
| 181 | + metrics::gauge!("tokio_max_park_count").set(metrics.max_park_count as f64); |
| 182 | + metrics::gauge!("tokio_min_park_count").set(metrics.min_park_count as f64); |
| 183 | + |
| 184 | + // Poll duration metrics |
| 185 | + metrics::gauge!("tokio_mean_poll_duration_ns") |
| 186 | + .set(metrics.mean_poll_duration.as_nanos() as f64); |
| 187 | + metrics::gauge!("tokio_mean_poll_duration_worker_min_ns") |
| 188 | + .set(metrics.mean_poll_duration_worker_min.as_nanos() as f64); |
| 189 | + metrics::gauge!("tokio_mean_poll_duration_worker_max_ns") |
| 190 | + .set(metrics.mean_poll_duration_worker_max.as_nanos() as f64); |
| 191 | + |
| 192 | + // Noop metrics |
| 193 | + metrics::gauge!("tokio_total_noop_count").set(metrics.total_noop_count as f64); |
| 194 | + metrics::gauge!("tokio_max_noop_count").set(metrics.max_noop_count as f64); |
| 195 | + metrics::gauge!("tokio_min_noop_count").set(metrics.min_noop_count as f64); |
| 196 | + |
| 197 | + // Steal metrics |
| 198 | + metrics::gauge!("tokio_total_steal_count").set(metrics.total_steal_count as f64); |
| 199 | + metrics::gauge!("tokio_max_steal_count").set(metrics.max_steal_count as f64); |
| 200 | + metrics::gauge!("tokio_min_steal_count").set(metrics.min_steal_count as f64); |
| 201 | + metrics::gauge!("tokio_total_steal_operations").set(metrics.total_steal_operations as f64); |
| 202 | + metrics::gauge!("tokio_max_steal_operations").set(metrics.max_steal_operations as f64); |
| 203 | + metrics::gauge!("tokio_min_steal_operations").set(metrics.min_steal_operations as f64); |
| 204 | + |
| 205 | + // Schedule metrics |
| 206 | + metrics::gauge!("tokio_num_remote_schedules").set(metrics.num_remote_schedules as f64); |
| 207 | + metrics::gauge!("tokio_total_local_schedule_count") |
| 208 | + .set(metrics.total_local_schedule_count as f64); |
| 209 | + metrics::gauge!("tokio_max_local_schedule_count").set(metrics.max_local_schedule_count as f64); |
| 210 | + metrics::gauge!("tokio_min_local_schedule_count").set(metrics.min_local_schedule_count as f64); |
| 211 | + |
| 212 | + // Overflow metrics |
| 213 | + metrics::gauge!("tokio_total_overflow_count").set(metrics.total_overflow_count as f64); |
| 214 | + metrics::gauge!("tokio_max_overflow_count").set(metrics.max_overflow_count as f64); |
| 215 | + metrics::gauge!("tokio_min_overflow_count").set(metrics.min_overflow_count as f64); |
| 216 | + |
| 217 | + // Polls metrics |
| 218 | + metrics::gauge!("tokio_total_polls_count").set(metrics.total_polls_count as f64); |
| 219 | + metrics::gauge!("tokio_max_polls_count").set(metrics.max_polls_count as f64); |
| 220 | + metrics::gauge!("tokio_min_polls_count").set(metrics.min_polls_count as f64); |
| 221 | + |
| 222 | + // Busy duration metrics |
| 223 | + metrics::gauge!("tokio_total_busy_duration_ns") |
| 224 | + .set(metrics.total_busy_duration.as_nanos() as f64); |
| 225 | + metrics::gauge!("tokio_max_busy_duration_ns").set(metrics.max_busy_duration.as_nanos() as f64); |
| 226 | + metrics::gauge!("tokio_min_busy_duration_ns").set(metrics.min_busy_duration.as_nanos() as f64); |
| 227 | + |
| 228 | + // Queue depth metrics |
| 229 | + metrics::gauge!("tokio_global_queue_depth").set(metrics.global_queue_depth as f64); |
| 230 | + metrics::gauge!("tokio_total_local_queue_depth").set(metrics.total_local_queue_depth as f64); |
| 231 | + metrics::gauge!("tokio_max_local_queue_depth").set(metrics.max_local_queue_depth as f64); |
| 232 | + metrics::gauge!("tokio_min_local_queue_depth").set(metrics.min_local_queue_depth as f64); |
| 233 | + metrics::gauge!("tokio_blocking_queue_depth").set(metrics.blocking_queue_depth as f64); |
| 234 | + |
| 235 | + // Task and thread metrics |
| 236 | + metrics::gauge!("tokio_live_tasks_count").set(metrics.live_tasks_count as f64); |
| 237 | + metrics::gauge!("tokio_blocking_threads_count").set(metrics.blocking_threads_count as f64); |
| 238 | + metrics::gauge!("tokio_idle_blocking_threads_count") |
| 239 | + .set(metrics.idle_blocking_threads_count as f64); |
| 240 | + |
| 241 | + // Other metrics |
| 242 | + metrics::gauge!("tokio_elapsed_us").set(metrics.elapsed.as_micros() as f64); |
| 243 | + metrics::gauge!("tokio_budget_forced_yield_count") |
| 244 | + .set(metrics.budget_forced_yield_count as f64); |
| 245 | + metrics::gauge!("tokio_io_driver_ready_count").set(metrics.io_driver_ready_count as f64); |
| 246 | +} |
| 247 | + |
168 | 248 | pub async fn start_metrics(run_options: RunOptions, server_state: Arc<ServerState>) -> Result<()> { |
169 | 249 | tracing::info!("Starting Metrics Server..."); |
170 | 250 |
|
|
0 commit comments