Skip to content

Commit 119dc57

Browse files
committed
expose basic tokio runtime metrics
1 parent 4fa2ce8 commit 119dc57

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

libsql-server/src/http/admin/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,34 @@ where
9393

9494
tokio::task::spawn(async move {
9595
loop {
96+
let runtime = tokio::runtime::Handle::current();
97+
let metrics = runtime.metrics();
98+
crate::metrics::TOKIO_RUNTIME_BLOCKING_QUEUE_DEPTH
99+
.set(metrics.blocking_queue_depth() as f64);
100+
crate::metrics::TOKIO_RUNTIME_INJECTION_QUEUE_DEPTH
101+
.set(metrics.injection_queue_depth() as f64);
102+
crate::metrics::TOKIO_RUNTIME_NUM_BLOCKING_THREADS
103+
.set(metrics.num_blocking_threads() as f64);
104+
crate::metrics::TOKIO_RUNTIME_NUM_IDLE_BLOCKING_THREADS
105+
.set(metrics.num_idle_blocking_threads() as f64);
106+
crate::metrics::TOKIO_RUNTIME_NUM_WORKERS.set(metrics.num_workers() as f64);
107+
108+
crate::metrics::TOKIO_RUNTIME_IO_DRIVER_FD_DEREGISTERED_COUNT
109+
.absolute(metrics.io_driver_fd_deregistered_count() as u64);
110+
crate::metrics::TOKIO_RUNTIME_IO_DRIVER_FD_REGISTERED_COUNT
111+
.absolute(metrics.io_driver_fd_registered_count() as u64);
112+
crate::metrics::TOKIO_RUNTIME_IO_DRIVER_READY_COUNT
113+
.absolute(metrics.io_driver_ready_count() as u64);
114+
crate::metrics::TOKIO_RUNTIME_REMOTE_SCHEDULE_COUNT
115+
.absolute(metrics.remote_schedule_count() as u64);
96116
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
117+
}
118+
});
97119

120+
tokio::task::spawn(async move {
121+
loop {
98122
crate::metrics::SERVER_COUNT.set(1.0);
123+
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
99124
}
100125
});
101126

libsql-server/src/metrics.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,57 @@ pub static QUERY_CANCELED: Lazy<Counter> = Lazy::new(|| {
158158
describe_counter!(NAME, "Number of canceled queries");
159159
register_counter!(NAME)
160160
});
161+
162+
pub static TOKIO_RUNTIME_BLOCKING_QUEUE_DEPTH: Lazy<Gauge> = Lazy::new(|| {
163+
const NAME: &str = "tokio_runtime_blocking_queue_depth";
164+
describe_gauge!(NAME, "tokio runtime blocking_queue_depth");
165+
register_gauge!(NAME)
166+
});
167+
168+
pub static TOKIO_RUNTIME_INJECTION_QUEUE_DEPTH: Lazy<Gauge> = Lazy::new(|| {
169+
const NAME: &str = "tokio_runtime_injection_queue_depth";
170+
describe_gauge!(NAME, "tokio runtime injection_queue_depth");
171+
register_gauge!(NAME)
172+
});
173+
174+
pub static TOKIO_RUNTIME_NUM_BLOCKING_THREADS: Lazy<Gauge> = Lazy::new(|| {
175+
const NAME: &str = "tokio_runtime_num_blocking_threads";
176+
describe_gauge!(NAME, "tokio runtime num_blocking_threads");
177+
register_gauge!(NAME)
178+
});
179+
180+
pub static TOKIO_RUNTIME_NUM_IDLE_BLOCKING_THREADS: Lazy<Gauge> = Lazy::new(|| {
181+
const NAME: &str = "tokio_runtime_num_idle_blocking_threads";
182+
describe_gauge!(NAME, "tokio runtime num_idle_blocking_threads");
183+
register_gauge!(NAME)
184+
});
185+
186+
pub static TOKIO_RUNTIME_NUM_WORKERS: Lazy<Gauge> = Lazy::new(|| {
187+
const NAME: &str = "tokio_runtime_num_workers";
188+
describe_gauge!(NAME, "tokio runtime num_workers");
189+
register_gauge!(NAME)
190+
});
191+
192+
pub static TOKIO_RUNTIME_IO_DRIVER_FD_DEREGISTERED_COUNT: Lazy<Counter> = Lazy::new(|| {
193+
const NAME: &str = "tokio_runtime_io_driver_fd_deregistered_count";
194+
describe_counter!(NAME, "tokio runtime io_driver_fd_deregistered_count");
195+
register_counter!(NAME)
196+
});
197+
198+
pub static TOKIO_RUNTIME_IO_DRIVER_FD_REGISTERED_COUNT: Lazy<Counter> = Lazy::new(|| {
199+
const NAME: &str = "tokio_runtime_io_driver_fd_registered_count";
200+
describe_counter!(NAME, "tokio runtime io_driver_fd_registered_count");
201+
register_counter!(NAME)
202+
});
203+
204+
pub static TOKIO_RUNTIME_IO_DRIVER_READY_COUNT: Lazy<Counter> = Lazy::new(|| {
205+
const NAME: &str = "tokio_runtime_io_driver_ready_count";
206+
describe_counter!(NAME, "tokio runtime io_driver_ready_count");
207+
register_counter!(NAME)
208+
});
209+
210+
pub static TOKIO_RUNTIME_REMOTE_SCHEDULE_COUNT: Lazy<Counter> = Lazy::new(|| {
211+
const NAME: &str = "tokio_runtime_remote_schedule_count";
212+
describe_gauge!(NAME, "tokio runtime remote_schedule_count");
213+
register_counter!(NAME)
214+
});

0 commit comments

Comments
 (0)