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