Prometheus metrics for the daemon's state between requests (#194)
Logs and traces show requests, scans and downloads; nothing showed what the daemon holds meanwhile. /metrics, behind sign-in, gives database connections in use and idle against the pool's maximum, commands waiting for the worker, live-update listeners, free torrent slots, episodes playing through DeadAir, the library's counts, the tokio runtime's workers, tasks and queue, and the process's memory and open files, in Prometheus's text format, written by hand rather than with a client library. Not logged or traced: Prometheus asks every 15 s. The iPX dashboard gains a Daemon row of them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
18
src/db.rs
18
src/db.rs
@@ -130,6 +130,24 @@ pub fn location() -> String {
|
||||
/// The Postgres connection option that keeps notices from being sent at all; see `connect`.
|
||||
const QUIET: &str = "options=-c%20client_min_messages%3Dwarning";
|
||||
|
||||
impl Db {
|
||||
/// The connection pool as it stands, for /metrics (#194): connections open, those of them
|
||||
/// idle, and the most it will open.
|
||||
pub fn pool(&self) -> (u32, usize, u32) {
|
||||
use sea_orm::DbBackend;
|
||||
match self.orm.get_database_backend() {
|
||||
DbBackend::Postgres => {
|
||||
let p = self.orm.get_postgres_connection_pool();
|
||||
(p.size(), p.num_idle(), p.options().get_max_connections())
|
||||
}
|
||||
_ => {
|
||||
let p = self.orm.get_sqlite_connection_pool();
|
||||
(p.size(), p.num_idle(), p.options().get_max_connections())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A URL fit for a log or an error: the password taken out.
|
||||
fn redact(url: &str) -> String {
|
||||
match (url.find("://"), url.rfind('@')) {
|
||||
|
||||
Reference in New Issue
Block a user