Standardize connection descriptions and focus on connections for gitea/vaultwarden

This commit is contained in:
Christoffer Martinsson 2025-10-13 19:35:31 +02:00
parent 07886ec317
commit 322997932e

View File

@ -475,12 +475,10 @@ impl ServiceCollector {
} }
} }
if connections == 0 { if connections > 0 {
None Some(format!("{} connections", connections))
} else if connections == 1 {
Some("1 SSH connection".to_string())
} else { } else {
Some(format!("{} SSH connections", connections)) None
} }
} }
@ -502,7 +500,7 @@ impl ServiceCollector {
let connection_count = stdout.lines().count().saturating_sub(1); // Subtract header line let connection_count = stdout.lines().count().saturating_sub(1); // Subtract header line
if connection_count > 0 { if connection_count > 0 {
Some(format!("{} active connections", connection_count)) Some(format!("{} connections", connection_count))
} else { } else {
None None
} }
@ -548,7 +546,7 @@ impl ServiceCollector {
if let Some(line) = stdout.lines().next() { if let Some(line) = stdout.lines().next() {
if let Ok(count) = line.trim().parse::<i32>() { if let Ok(count) = line.trim().parse::<i32>() {
if count > 0 { if count > 0 {
return Some(format!("{} active connections", count)); return Some(format!("{} connections", count));
} }
} }
} }
@ -571,7 +569,7 @@ impl ServiceCollector {
let connection_count = stdout.lines().count().saturating_sub(1); // Subtract header line let connection_count = stdout.lines().count().saturating_sub(1); // Subtract header line
if connection_count > 0 { if connection_count > 0 {
return Some(format!("{} active connections", connection_count)); return Some(format!("{} connections", connection_count));
} }
} }
@ -846,7 +844,7 @@ impl ServiceCollector {
if line.starts_with("connected_clients:") { if line.starts_with("connected_clients:") {
if let Some(count) = line.split(':').nth(1) { if let Some(count) = line.split(':').nth(1) {
if let Ok(client_count) = count.trim().parse::<i32>() { if let Ok(client_count) = count.trim().parse::<i32>() {
return Some(format!("{} connected clients", client_count)); return Some(format!("{} connections", client_count));
} }
} }
} }
@ -867,8 +865,6 @@ impl ServiceCollector {
let connection_count = stdout.lines().count().saturating_sub(1); let connection_count = stdout.lines().count().saturating_sub(1);
if connection_count > 0 { if connection_count > 0 {
return Some(format!("{} connections", connection_count)); return Some(format!("{} connections", connection_count));
} else {
return Some("No connections".to_string());
} }
} }
@ -894,23 +890,9 @@ impl ServiceCollector {
} }
} }
// Fallback: check data directory sizes - try multiple paths // Fallback: check HTTP connections on port 3000
let paths = [ let output = Command::new("/run/current-system/sw/bin/ss")
"/var/lib/gitea/data/gitea.db", .args(["-tn", "state", "established", "dport", "= :3000"])
"/var/lib/gitea/gitea.db",
"/var/lib/gitea/data.db"
];
for path in &paths {
if let Ok(metadata) = tokio::fs::metadata(path).await {
let size_mb = metadata.len() as f32 / (1024.0 * 1024.0);
return Some(format!("DB: {:.1} MB", size_mb));
}
}
// Last resort: check total gitea directory size
let output = Command::new("sudo")
.args(["/run/current-system/sw/bin/du", "-sh", "/var/lib/gitea"])
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.stderr(Stdio::piped()) .stderr(Stdio::piped())
.output() .output()
@ -919,8 +901,9 @@ impl ServiceCollector {
if output.status.success() { if output.status.success() {
let stdout = String::from_utf8_lossy(&output.stdout); let stdout = String::from_utf8_lossy(&output.stdout);
if let Some(size) = stdout.split_whitespace().next() { let connection_count = stdout.lines().count().saturating_sub(1);
return Some(format!("Data: {}", size)); if connection_count > 0 {
return Some(format!("{} connections", connection_count));
} }
} }
@ -965,24 +948,9 @@ impl ServiceCollector {
} }
async fn get_vaultwarden_info(&self) -> Option<String> { async fn get_vaultwarden_info(&self) -> Option<String> {
// Check database for basic stats (SQLite) - try common locations // Check HTTP connections - vaultwarden typically runs on port 8000 or behind nginx
let db_paths = [ let output = Command::new("/run/current-system/sw/bin/ss")
"/var/lib/vaultwarden/db.sqlite3", .args(["-tn", "state", "established", "dport", "= :8000"])
"/var/lib/vaultwarden/data/db.sqlite3",
"/var/lib/bitwarden_rs/db.sqlite3",
"/var/lib/vaultwarden/data.sqlite3"
];
for path in &db_paths {
if let Ok(metadata) = tokio::fs::metadata(path).await {
let size_mb = metadata.len() as f32 / (1024.0 * 1024.0);
return Some(format!("DB: {:.1} MB", size_mb));
}
}
// Fallback: check directory size
let output = Command::new("sudo")
.args(["/run/current-system/sw/bin/du", "-sh", "/var/lib/vaultwarden"])
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.stderr(Stdio::piped()) .stderr(Stdio::piped())
.output() .output()
@ -991,8 +959,9 @@ impl ServiceCollector {
if output.status.success() { if output.status.success() {
let stdout = String::from_utf8_lossy(&output.stdout); let stdout = String::from_utf8_lossy(&output.stdout);
if let Some(size) = stdout.split_whitespace().next() { let connection_count = stdout.lines().count().saturating_sub(1);
return Some(format!("Data: {}", size)); if connection_count > 0 {
return Some(format!("{} connections", connection_count));
} }
} }
@ -1035,9 +1004,7 @@ impl ServiceCollector {
let stdout = String::from_utf8_lossy(&output.stdout); let stdout = String::from_utf8_lossy(&output.stdout);
let connection_count = stdout.lines().count().saturating_sub(1); let connection_count = stdout.lines().count().saturating_sub(1);
if connection_count > 0 { if connection_count > 0 {
return Some(format!("{} MQTT connections", connection_count)); return Some(format!("{} connections", connection_count));
} else {
return Some("No active connections".to_string());
} }
} }
@ -1059,8 +1026,6 @@ impl ServiceCollector {
let connection_count = stdout.lines().count().saturating_sub(1); let connection_count = stdout.lines().count().saturating_sub(1);
if connection_count > 0 { if connection_count > 0 {
return Some(format!("{} connections", connection_count)); return Some(format!("{} connections", connection_count));
} else {
return Some("No connections".to_string());
} }
} }