Fix service descriptions with better fallbacks and correct paths
This commit is contained in:
parent
6da23019e5
commit
a33b019d83
@ -556,7 +556,8 @@ impl ServiceCollector {
|
||||
}
|
||||
|
||||
async fn get_mysql_connections(&self) -> Option<String> {
|
||||
let output = Command::new("mysql")
|
||||
// Try mysql command first
|
||||
let output = Command::new("/run/current-system/sw/bin/mysql")
|
||||
.args(["-e", "SHOW PROCESSLIST;"])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
@ -564,18 +565,33 @@ impl ServiceCollector {
|
||||
.await
|
||||
.ok()?;
|
||||
|
||||
if !output.status.success() {
|
||||
return None;
|
||||
if output.status.success() {
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let connection_count = stdout.lines().count().saturating_sub(1); // Subtract header line
|
||||
|
||||
if connection_count > 0 {
|
||||
return Some(format!("{} active connections", connection_count));
|
||||
}
|
||||
}
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let connection_count = stdout.lines().count().saturating_sub(1); // Subtract header line
|
||||
|
||||
if connection_count > 0 {
|
||||
Some(format!("{} active connections", connection_count))
|
||||
} else {
|
||||
None
|
||||
// Fallback: check MySQL connections on port 3306
|
||||
let output = Command::new("/run/current-system/sw/bin/ss")
|
||||
.args(["-tn", "state", "established", "dport", "= :3306"])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.output()
|
||||
.await
|
||||
.ok()?;
|
||||
|
||||
if output.status.success() {
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let connection_count = stdout.lines().count().saturating_sub(1);
|
||||
if connection_count > 0 {
|
||||
return Some(format!("{} connections", connection_count));
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn is_running_as_root(&self) -> bool {
|
||||
@ -814,7 +830,8 @@ impl ServiceCollector {
|
||||
}
|
||||
|
||||
async fn get_redis_info(&self) -> Option<String> {
|
||||
let output = Command::new("redis-cli")
|
||||
// Try redis-cli first
|
||||
let output = Command::new("/run/current-system/sw/bin/redis-cli")
|
||||
.args(["info", "clients"])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
@ -822,27 +839,45 @@ impl ServiceCollector {
|
||||
.await
|
||||
.ok()?;
|
||||
|
||||
if !output.status.success() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
for line in stdout.lines() {
|
||||
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));
|
||||
if output.status.success() {
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
for line in stdout.lines() {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: check for redis connections on port 6379
|
||||
let output = Command::new("/run/current-system/sw/bin/ss")
|
||||
.args(["-tn", "state", "established", "dport", "= :6379"])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.output()
|
||||
.await
|
||||
.ok()?;
|
||||
|
||||
if output.status.success() {
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
async fn get_gitea_info(&self) -> Option<String> {
|
||||
// Try to get gitea stats from API (if accessible)
|
||||
let output = Command::new("curl")
|
||||
.args(["-s", "-f", "http://localhost:3000/api/v1/repos/search?limit=1"])
|
||||
let output = Command::new("/run/current-system/sw/bin/curl")
|
||||
.args(["-s", "-f", "-m", "2", "http://localhost:3000/api/v1/repos/search?limit=1"])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.output()
|
||||
@ -858,10 +893,34 @@ impl ServiceCollector {
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: check data directory
|
||||
if let Ok(metadata) = tokio::fs::metadata("/var/lib/gitea/data/gitea.db").await {
|
||||
let size_mb = metadata.len() as f32 / (1024.0 * 1024.0);
|
||||
return Some(format!("DB: {:.1} MB", size_mb));
|
||||
// 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"])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.output()
|
||||
.await
|
||||
.ok()?;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
@ -905,10 +964,35 @@ impl ServiceCollector {
|
||||
}
|
||||
|
||||
async fn get_vaultwarden_info(&self) -> Option<String> {
|
||||
// Check database for basic stats (SQLite)
|
||||
if let Ok(metadata) = tokio::fs::metadata("/var/lib/bitwarden_rs/db.sqlite3").await {
|
||||
let size_mb = metadata.len() as f32 / (1024.0 * 1024.0);
|
||||
return Some(format!("DB: {:.1} MB", size_mb));
|
||||
// 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"])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.output()
|
||||
.await
|
||||
.ok()?;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user