Testing
This commit is contained in:
@@ -97,6 +97,8 @@ pub struct BackupMetrics {
|
||||
pub overall_status: BackupStatus,
|
||||
pub backup: BackupInfo,
|
||||
pub service: BackupServiceInfo,
|
||||
#[serde(default)]
|
||||
pub disk: Option<BackupDiskInfo>,
|
||||
pub timestamp: DateTime<Utc>,
|
||||
}
|
||||
|
||||
@@ -105,6 +107,8 @@ pub struct BackupInfo {
|
||||
pub last_success: Option<DateTime<Utc>>,
|
||||
pub last_failure: Option<DateTime<Utc>>,
|
||||
pub size_gb: f32,
|
||||
#[serde(default)]
|
||||
pub latest_archive_size_gb: Option<f32>,
|
||||
pub snapshot_count: u32,
|
||||
}
|
||||
|
||||
@@ -115,6 +119,15 @@ pub struct BackupServiceInfo {
|
||||
pub last_message: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct BackupDiskInfo {
|
||||
pub device: String,
|
||||
pub health: String,
|
||||
pub total_gb: f32,
|
||||
pub used_gb: f32,
|
||||
pub usage_percent: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub enum BackupStatus {
|
||||
Healthy,
|
||||
|
||||
@@ -35,60 +35,68 @@ fn render_metrics(frame: &mut Frame, _host: &HostDisplayData, metrics: &BackupMe
|
||||
let mut data = WidgetData::new(
|
||||
"Backups",
|
||||
Some(WidgetStatus::new(widget_status)),
|
||||
vec!["Aspect".to_string(), "Details".to_string()]
|
||||
vec!["Backup".to_string(), "Status".to_string(), "Details".to_string()]
|
||||
);
|
||||
|
||||
let repo_status = repo_status_level(metrics);
|
||||
// Latest backup
|
||||
let (latest_status, latest_time) = if let Some(last_success) = metrics.backup.last_success.as_ref() {
|
||||
let hours_ago = chrono::Utc::now().signed_duration_since(*last_success).num_hours();
|
||||
let time_str = if hours_ago < 24 {
|
||||
format!("{}h ago", hours_ago)
|
||||
} else {
|
||||
format!("{}d ago", hours_ago / 24)
|
||||
};
|
||||
(StatusLevel::Ok, time_str)
|
||||
} else {
|
||||
(StatusLevel::Warning, "Never".to_string())
|
||||
};
|
||||
|
||||
data.add_row(
|
||||
Some(WidgetStatus::new(repo_status)),
|
||||
Some(WidgetStatus::new(latest_status)),
|
||||
vec![],
|
||||
vec![
|
||||
"Latest".to_string(),
|
||||
latest_time,
|
||||
format!("{:.1} GiB", metrics.backup.latest_archive_size_gb.unwrap_or(metrics.backup.size_gb)),
|
||||
],
|
||||
);
|
||||
|
||||
// Repository total
|
||||
data.add_row(
|
||||
Some(WidgetStatus::new(StatusLevel::Ok)),
|
||||
vec![],
|
||||
vec![
|
||||
"Repo".to_string(),
|
||||
format!(
|
||||
"Snapshots: {} • Size: {:.1} GiB",
|
||||
metrics.backup.snapshot_count, metrics.backup.size_gb
|
||||
),
|
||||
format!("{} archives", metrics.backup.snapshot_count),
|
||||
format!("{:.1} GiB total", metrics.backup.size_gb),
|
||||
],
|
||||
);
|
||||
|
||||
let service_status = service_status_level(metrics);
|
||||
data.add_row(
|
||||
Some(WidgetStatus::new(service_status)),
|
||||
vec![],
|
||||
vec![
|
||||
"Service".to_string(),
|
||||
format!(
|
||||
"Enabled: {} • Pending jobs: {}",
|
||||
metrics.service.enabled, metrics.service.pending_jobs
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
if let Some(last_failure) = metrics.backup.last_failure.as_ref() {
|
||||
// Disk usage
|
||||
if let Some(disk) = &metrics.disk {
|
||||
let disk_status = match disk.health.as_str() {
|
||||
"ok" => StatusLevel::Ok,
|
||||
"failed" => StatusLevel::Error,
|
||||
_ => StatusLevel::Warning,
|
||||
};
|
||||
|
||||
data.add_row(
|
||||
Some(WidgetStatus::new(StatusLevel::Error)),
|
||||
Some(WidgetStatus::new(disk_status)),
|
||||
vec![],
|
||||
vec![
|
||||
"Last failure".to_string(),
|
||||
format_timestamp(Some(last_failure)),
|
||||
"Disk usage".to_string(),
|
||||
disk.health.clone(),
|
||||
format!("{:.0} GB, {:.0}% used", disk.total_gb, disk.usage_percent),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(message) = metrics.service.last_message.as_ref() {
|
||||
let status_level = match metrics.overall_status {
|
||||
BackupStatus::Failed => StatusLevel::Error,
|
||||
BackupStatus::Warning => StatusLevel::Warning,
|
||||
BackupStatus::Unknown => StatusLevel::Unknown,
|
||||
BackupStatus::Healthy => StatusLevel::Ok,
|
||||
};
|
||||
|
||||
} else {
|
||||
data.add_row(
|
||||
Some(WidgetStatus::new(status_level)),
|
||||
Some(WidgetStatus::new(StatusLevel::Unknown)),
|
||||
vec![],
|
||||
vec![
|
||||
"Last message".to_string(),
|
||||
message.clone(),
|
||||
"Disk usage".to_string(),
|
||||
"Unknown".to_string(),
|
||||
"—".to_string(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user