This commit is contained in:
2025-10-12 19:32:47 +02:00
parent fb91d8346f
commit 9c836e0862
3 changed files with 78 additions and 39 deletions

View File

@@ -312,7 +312,7 @@ impl Collector for BackupCollector {
// Try to get borgbackup metrics first, fall back to restic if not available
let borgbackup_result = self.get_borgbackup_metrics().await;
let (backup_info, overall_status) = match borgbackup_result {
let (backup_info, overall_status) = match &borgbackup_result {
Ok(borg_metrics) => {
// Parse borgbackup timestamp to DateTime
let last_success = chrono::DateTime::from_timestamp(borg_metrics.timestamp, 0);
@@ -329,6 +329,7 @@ impl Collector for BackupCollector {
last_success,
last_failure: None, // borgbackup metrics don't include failure info
size_gb: borg_metrics.repository.total_repository_size_bytes as f32 / (1024.0 * 1024.0 * 1024.0),
latest_archive_size_gb: Some(borg_metrics.repository.latest_archive_size_bytes as f32 / (1024.0 * 1024.0 * 1024.0)),
snapshot_count: borg_metrics.repository.total_archives as u32,
};
@@ -356,12 +357,14 @@ impl Collector for BackupCollector {
last_success: stats.last_success,
last_failure,
size_gb: stats.total_size as f32 / (1024.0 * 1024.0 * 1024.0),
latest_archive_size_gb: None, // Restic doesn't provide this easily
snapshot_count: stats.snapshot_count,
},
Err(_) => BackupInfo {
last_success: None,
last_failure,
size_gb: 0.0,
latest_archive_size_gb: None,
snapshot_count: 0,
},
};
@@ -380,12 +383,26 @@ impl Collector for BackupCollector {
last_message: None,
});
let backup_metrics = json!({
// Add disk information if available from borgbackup metrics
let mut backup_json = json!({
"overall_status": overall_status,
"backup": backup_info,
"service": service_data,
"timestamp": Utc::now()
});
// If we got borgbackup metrics, include disk information
if let Ok(borg_metrics) = &borgbackup_result {
backup_json["disk"] = json!({
"device": borg_metrics.backup_disk.device,
"health": borg_metrics.backup_disk.health,
"total_gb": borg_metrics.backup_disk.total_bytes as f32 / (1024.0 * 1024.0 * 1024.0),
"used_gb": borg_metrics.backup_disk.used_bytes as f32 / (1024.0 * 1024.0 * 1024.0),
"usage_percent": borg_metrics.backup_disk.usage_percent
});
}
let backup_metrics = backup_json;
Ok(CollectorOutput {
agent_type: AgentType::Backup,
@@ -419,6 +436,7 @@ struct BackupInfo {
last_success: Option<DateTime<Utc>>,
last_failure: Option<DateTime<Utc>>,
size_gb: f32,
latest_archive_size_gb: Option<f32>,
snapshot_count: u32,
}