Standardize connection descriptions and focus on connections for gitea/vaultwarden
This commit is contained in:
parent
07886ec317
commit
322997932e
@ -475,12 +475,10 @@ impl ServiceCollector {
|
||||
}
|
||||
}
|
||||
|
||||
if connections == 0 {
|
||||
None
|
||||
} else if connections == 1 {
|
||||
Some("1 SSH connection".to_string())
|
||||
if connections > 0 {
|
||||
Some(format!("{} connections", connections))
|
||||
} 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
|
||||
|
||||
if connection_count > 0 {
|
||||
Some(format!("{} active connections", connection_count))
|
||||
Some(format!("{} connections", connection_count))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -548,7 +546,7 @@ impl ServiceCollector {
|
||||
if let Some(line) = stdout.lines().next() {
|
||||
if let Ok(count) = line.trim().parse::<i32>() {
|
||||
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
|
||||
|
||||
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 let Some(count) = line.split(':').nth(1) {
|
||||
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);
|
||||
if connection_count > 0 {
|
||||
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
|
||||
let paths = [
|
||||
"/var/lib/gitea/data/gitea.db",
|
||||
"/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"])
|
||||
// Fallback: check HTTP connections on port 3000
|
||||
let output = Command::new("/run/current-system/sw/bin/ss")
|
||||
.args(["-tn", "state", "established", "dport", "= :3000"])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.output()
|
||||
@ -919,8 +901,9 @@ impl ServiceCollector {
|
||||
|
||||
if output.status.success() {
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
if let Some(size) = stdout.split_whitespace().next() {
|
||||
return Some(format!("Data: {}", size));
|
||||
let connection_count = stdout.lines().count().saturating_sub(1);
|
||||
if connection_count > 0 {
|
||||
return Some(format!("{} connections", connection_count));
|
||||
}
|
||||
}
|
||||
|
||||
@ -965,24 +948,9 @@ impl ServiceCollector {
|
||||
}
|
||||
|
||||
async fn get_vaultwarden_info(&self) -> Option<String> {
|
||||
// Check database for basic stats (SQLite) - try common locations
|
||||
let db_paths = [
|
||||
"/var/lib/vaultwarden/db.sqlite3",
|
||||
"/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"])
|
||||
// Check HTTP connections - vaultwarden typically runs on port 8000 or behind nginx
|
||||
let output = Command::new("/run/current-system/sw/bin/ss")
|
||||
.args(["-tn", "state", "established", "dport", "= :8000"])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.output()
|
||||
@ -991,8 +959,9 @@ impl ServiceCollector {
|
||||
|
||||
if output.status.success() {
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
if let Some(size) = stdout.split_whitespace().next() {
|
||||
return Some(format!("Data: {}", size));
|
||||
let connection_count = stdout.lines().count().saturating_sub(1);
|
||||
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 connection_count = stdout.lines().count().saturating_sub(1);
|
||||
if connection_count > 0 {
|
||||
return Some(format!("{} MQTT connections", connection_count));
|
||||
} else {
|
||||
return Some("No active connections".to_string());
|
||||
return Some(format!("{} connections", connection_count));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1059,8 +1026,6 @@ impl ServiceCollector {
|
||||
let connection_count = stdout.lines().count().saturating_sub(1);
|
||||
if connection_count > 0 {
|
||||
return Some(format!("{} connections", connection_count));
|
||||
} else {
|
||||
return Some("No connections".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user