Fix storage display format and clean up warnings
All checks were successful
Build and Release / build-and-release (push) Successful in 1m9s
All checks were successful
Build and Release / build-and-release (push) Successful in 1m9s
Update storage display to match CLAUDE.md specification: - Show drive temp/wear on main line: nvme0n1 T: 25°C W: 4% - Display individual filesystems as sub-items: /: 55% 250.5GB/456.4GB - Remove Total usage line in favor of filesystem breakdown Clean up code warnings: - Remove unused heartbeat methods and fields - Remove unused backup widget fields and methods - Add allow attributes for legacy methods
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard-agent"
|
||||
version = "0.1.137"
|
||||
version = "0.1.138"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -262,47 +262,11 @@ impl Agent {
|
||||
agent_data.system.memory.swap_used_gb = value;
|
||||
}
|
||||
}
|
||||
// Tmpfs metrics
|
||||
else if metric.name.starts_with("memory_tmp_") {
|
||||
// For now, create a single /tmp tmpfs entry
|
||||
if metric.name == "memory_tmp_usage_percent" {
|
||||
// Tmpfs metrics - handle multiple auto-discovered tmpfs mounts
|
||||
else if metric.name.starts_with("memory_tmpfs_") {
|
||||
if let Some((mount_point, metric_type)) = self.parse_tmpfs_metric_name(&metric.name) {
|
||||
if let Some(value) = metric.value.as_f32() {
|
||||
if let Some(tmpfs) = agent_data.system.memory.tmpfs.get_mut(0) {
|
||||
tmpfs.usage_percent = value;
|
||||
} else {
|
||||
agent_data.system.memory.tmpfs.push(TmpfsData {
|
||||
mount: "/tmp".to_string(),
|
||||
usage_percent: value,
|
||||
used_gb: 0.0,
|
||||
total_gb: 0.0,
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if metric.name == "memory_tmp_used_gb" {
|
||||
if let Some(value) = metric.value.as_f32() {
|
||||
if let Some(tmpfs) = agent_data.system.memory.tmpfs.get_mut(0) {
|
||||
tmpfs.used_gb = value;
|
||||
} else {
|
||||
agent_data.system.memory.tmpfs.push(TmpfsData {
|
||||
mount: "/tmp".to_string(),
|
||||
usage_percent: 0.0,
|
||||
used_gb: value,
|
||||
total_gb: 0.0,
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if metric.name == "memory_tmp_total_gb" {
|
||||
if let Some(value) = metric.value.as_f32() {
|
||||
if let Some(tmpfs) = agent_data.system.memory.tmpfs.get_mut(0) {
|
||||
tmpfs.total_gb = value;
|
||||
} else {
|
||||
agent_data.system.memory.tmpfs.push(TmpfsData {
|
||||
mount: "/tmp".to_string(),
|
||||
usage_percent: 0.0,
|
||||
used_gb: 0.0,
|
||||
total_gb: value,
|
||||
});
|
||||
}
|
||||
self.update_tmpfs_data(&mut agent_data.system.memory.tmpfs, &mount_point, &metric_type, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -394,6 +358,63 @@ impl Agent {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Parse tmpfs metric name to extract mount point and metric type
|
||||
/// Example: "memory_tmpfs_tmp_usage_percent" -> ("/tmp", "usage_percent")
|
||||
fn parse_tmpfs_metric_name(&self, metric_name: &str) -> Option<(String, String)> {
|
||||
if !metric_name.starts_with("memory_tmpfs_") {
|
||||
return None;
|
||||
}
|
||||
|
||||
let remainder = &metric_name[13..]; // Remove "memory_tmpfs_" prefix
|
||||
|
||||
// Find the last underscore to separate metric type from mount point
|
||||
if let Some(last_underscore) = remainder.rfind('_') {
|
||||
let mount_safe = &remainder[..last_underscore];
|
||||
let metric_type = &remainder[last_underscore + 1..];
|
||||
|
||||
// Convert safe mount name back to actual mount point
|
||||
let mount_point = if mount_safe.is_empty() {
|
||||
"/"
|
||||
} else {
|
||||
&format!("/{}", mount_safe.replace('_', "/"))
|
||||
};
|
||||
|
||||
Some((mount_point.to_string(), metric_type.to_string()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Update tmpfs data in the tmpfs vector
|
||||
fn update_tmpfs_data(&self, tmpfs_vec: &mut Vec<TmpfsData>, mount_point: &str, metric_type: &str, value: f32) {
|
||||
// Find existing tmpfs entry
|
||||
let existing_index = tmpfs_vec.iter()
|
||||
.position(|tmpfs| tmpfs.mount == mount_point);
|
||||
|
||||
let tmpfs_index = if let Some(index) = existing_index {
|
||||
index
|
||||
} else {
|
||||
// Create new entry
|
||||
tmpfs_vec.push(TmpfsData {
|
||||
mount: mount_point.to_string(),
|
||||
usage_percent: 0.0,
|
||||
used_gb: 0.0,
|
||||
total_gb: 0.0,
|
||||
});
|
||||
tmpfs_vec.len() - 1
|
||||
};
|
||||
|
||||
// Update the tmpfs entry
|
||||
if let Some(tmpfs) = tmpfs_vec.get_mut(tmpfs_index) {
|
||||
match metric_type {
|
||||
"usage_percent" => tmpfs.usage_percent = value,
|
||||
"used_gb" => tmpfs.used_gb = value,
|
||||
"total_gb" => tmpfs.total_gb = value,
|
||||
_ => {} // Unknown metric type, ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Extract drive name from metric like "disk_nvme0n1_temperature"
|
||||
fn extract_drive_name(&self, metric_name: &str) -> Option<String> {
|
||||
if metric_name.starts_with("disk_") {
|
||||
@@ -529,31 +550,6 @@ impl Agent {
|
||||
}
|
||||
|
||||
/// Create heartbeat metric for host connectivity detection
|
||||
fn get_heartbeat_metric(&self) -> Metric {
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
let timestamp = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs();
|
||||
|
||||
Metric::new(
|
||||
"agent_heartbeat".to_string(),
|
||||
MetricValue::Integer(timestamp as i64),
|
||||
Status::Ok,
|
||||
)
|
||||
}
|
||||
|
||||
/// Send standalone heartbeat for connectivity detection
|
||||
async fn send_heartbeat(&mut self) -> Result<()> {
|
||||
// Create minimal agent data with just heartbeat
|
||||
let agent_data = AgentData::new(self.hostname.clone(), self.get_agent_version());
|
||||
// Heartbeat timestamp is already set in AgentData::new()
|
||||
|
||||
self.zmq_handler.publish_agent_data(&agent_data).await?;
|
||||
debug!("Sent standalone heartbeat for connectivity detection");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_commands(&mut self) -> Result<()> {
|
||||
// Try to receive commands (non-blocking)
|
||||
|
||||
Reference in New Issue
Block a user