mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-26 18:37:35 +00:00
feat: Add Prometheus metrics endpoint
This commit is contained in:
1 parent
ea96858c4a
commit
f14c401f39
25 files changed
+652
-46
No files matched your search
@@ -5,12 +5,18 @@ use rocksdb::perf::get_memory_usage_stats;
|
||||
|
||||
use crate::or_else;
|
||||
|
||||
pub struct MemoryUsage {
|
||||
pub mem_table_total: u64,
|
||||
pub mem_table_unflushed: u64,
|
||||
pub mem_table_readers_total: u64,
|
||||
pub row_cache: u64,
|
||||
pub col_caches: Vec<(String, u64)>,
|
||||
}
|
||||
|
||||
impl super::Engine {
|
||||
pub fn memory_usage(&self) -> Result<String> {
|
||||
let mut res = String::new();
|
||||
let stats =
|
||||
get_memory_usage_stats(Some(&[&self.db]), Some(&[&*self.ctx.row_cache.lock()]))
|
||||
.or_else(or_else)?;
|
||||
let stats = self.memory_usage_stats()?;
|
||||
let mibs = |input| f64::from(u32::try_from(input / 1024).unwrap_or(0)) / 1024.0;
|
||||
writeln!(
|
||||
res,
|
||||
@@ -19,13 +25,35 @@ impl super::Engine {
|
||||
mibs(stats.mem_table_total),
|
||||
mibs(stats.mem_table_unflushed),
|
||||
mibs(stats.mem_table_readers_total),
|
||||
mibs(u64::try_from(self.ctx.row_cache.lock().get_usage())?),
|
||||
mibs(stats.row_cache),
|
||||
)?;
|
||||
|
||||
for (name, cache) in &*self.ctx.col_cache.lock() {
|
||||
writeln!(res, "{name} cache: {:.2} MiB", mibs(u64::try_from(cache.get_usage())?))?;
|
||||
for (name, usage) in stats.col_caches {
|
||||
writeln!(res, "{name} cache: {:.2} MiB", mibs(usage))?;
|
||||
}
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
pub fn memory_usage_stats(&self) -> Result<MemoryUsage> {
|
||||
let stats =
|
||||
get_memory_usage_stats(Some(&[&self.db]), Some(&[&*self.ctx.row_cache.lock()]))
|
||||
.or_else(or_else)?;
|
||||
|
||||
let col_caches = self
|
||||
.ctx
|
||||
.col_cache
|
||||
.lock()
|
||||
.iter()
|
||||
.map(|(name, cache)| Ok((name.clone(), u64::try_from(cache.get_usage())?)))
|
||||
.collect::<Result<_>>()?;
|
||||
|
||||
Ok(MemoryUsage {
|
||||
mem_table_total: stats.mem_table_total,
|
||||
mem_table_unflushed: stats.mem_table_unflushed,
|
||||
mem_table_readers_total: stats.mem_table_readers_total,
|
||||
row_cache: u64::try_from(self.ctx.row_cache.lock().get_usage())?,
|
||||
col_caches,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user