Add TaskMonitor interval metrics w/ admin command.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2026-03-02 02:10:55 +00:00
parent bf8ae48ec2
commit 9e75453303
6 changed files with 90 additions and 12 deletions

View File

@@ -22,6 +22,7 @@ use tuwunel_core::{
Event,
pdu::{PduEvent, PduId, RawPduId},
},
tokio_metrics::TaskMonitor,
trace, utils,
utils::{
stream::{IterStream, ReadyExt},
@@ -790,6 +791,37 @@ pub(super) async fn runtime_interval(&self) -> Result {
.await
}
#[admin_command]
pub(super) async fn task_metrics(&self) -> Result {
let out = self
.services
.server
.metrics
.task_metrics()
.map(TaskMonitor::cumulative)
.map_or_else(
|| "Task metrics are not available.".to_owned(),
|metrics| format!("```rs\n{metrics:#?}\n```"),
);
self.write_str(&out).await
}
#[admin_command]
pub(super) async fn task_interval(&self) -> Result {
let out = self
.services
.server
.metrics
.task_interval()
.map_or_else(
|| "Task metrics are not available.".to_owned(),
|metrics| format!("```rs\n{metrics:#?}\n```"),
);
self.write_str(&out).await
}
#[admin_command]
pub(super) async fn time(&self) -> Result {
let now = SystemTime::now();

View File

@@ -197,6 +197,13 @@ pub(super) enum DebugCommand {
/// invocation.
RuntimeInterval,
/// - Print detailed tokio task metrics accumulated in total.
TaskMetrics,
/// - Print detailed tokio task metrics accumulated since last command
/// invocation.
TaskInterval,
/// - Print the current time
Time,