- Implement get_top_cpu_process() and get_top_ram_process() functions in SystemCollector - Add top_cpu_process and top_ram_process fields to SystemSummary data structure - Update System widget to display top processes as description rows - Show process name and percentage usage for highest CPU and RAM consumers - Skip kernel threads and filter out processes with minimal usage (<0.1%)
190 lines
4.7 KiB
Rust
190 lines
4.7 KiB
Rust
#![allow(dead_code)]
|
|
|
|
use chrono::{DateTime, Utc};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct SmartMetrics {
|
|
pub status: String,
|
|
pub drives: Vec<DriveInfo>,
|
|
pub summary: DriveSummary,
|
|
pub issues: Vec<String>,
|
|
pub timestamp: DateTime<Utc>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct DriveInfo {
|
|
pub name: String,
|
|
pub temperature_c: f32,
|
|
pub wear_level: f32,
|
|
pub power_on_hours: u64,
|
|
pub available_spare: f32,
|
|
pub capacity_gb: Option<f32>,
|
|
pub used_gb: Option<f32>,
|
|
#[serde(default)]
|
|
pub description: Option<Vec<String>>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct DriveSummary {
|
|
pub healthy: usize,
|
|
pub warning: usize,
|
|
pub critical: usize,
|
|
pub capacity_total_gb: f32,
|
|
pub capacity_used_gb: f32,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct SystemMetrics {
|
|
pub summary: SystemSummary,
|
|
pub timestamp: u64,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct SystemSummary {
|
|
pub cpu_load_1: f32,
|
|
pub cpu_load_5: f32,
|
|
pub cpu_load_15: f32,
|
|
#[serde(default)]
|
|
pub cpu_status: Option<String>,
|
|
pub memory_used_mb: f32,
|
|
pub memory_total_mb: f32,
|
|
pub memory_usage_percent: f32,
|
|
#[serde(default)]
|
|
pub memory_status: Option<String>,
|
|
#[serde(default)]
|
|
pub cpu_temp_c: Option<f32>,
|
|
#[serde(default)]
|
|
pub cpu_temp_status: Option<String>,
|
|
#[serde(default)]
|
|
pub cpu_cstate: Option<Vec<String>>,
|
|
#[serde(default)]
|
|
pub logged_in_users: Option<Vec<String>>,
|
|
#[serde(default)]
|
|
pub top_cpu_process: Option<String>,
|
|
#[serde(default)]
|
|
pub top_ram_process: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct ServiceMetrics {
|
|
pub summary: ServiceSummary,
|
|
pub services: Vec<ServiceInfo>,
|
|
pub timestamp: DateTime<Utc>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct ServiceSummary {
|
|
pub healthy: usize,
|
|
pub degraded: usize,
|
|
pub failed: usize,
|
|
#[serde(default)]
|
|
pub services_status: Option<String>,
|
|
pub memory_used_mb: f32,
|
|
pub memory_quota_mb: f32,
|
|
#[serde(default)]
|
|
pub system_memory_used_mb: f32,
|
|
#[serde(default)]
|
|
pub system_memory_total_mb: f32,
|
|
#[serde(default)]
|
|
pub memory_status: Option<String>,
|
|
#[serde(default)]
|
|
pub disk_used_gb: f32,
|
|
#[serde(default)]
|
|
pub disk_total_gb: f32,
|
|
#[serde(default)]
|
|
pub cpu_load_1: f32,
|
|
#[serde(default)]
|
|
pub cpu_load_5: f32,
|
|
#[serde(default)]
|
|
pub cpu_load_15: f32,
|
|
#[serde(default)]
|
|
pub cpu_status: Option<String>,
|
|
#[serde(default)]
|
|
pub cpu_cstate: Option<Vec<String>>,
|
|
#[serde(default)]
|
|
pub cpu_temp_c: Option<f32>,
|
|
#[serde(default)]
|
|
pub cpu_temp_status: Option<String>,
|
|
#[serde(default)]
|
|
pub gpu_load_percent: Option<f32>,
|
|
#[serde(default)]
|
|
pub gpu_temp_c: Option<f32>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct ServiceInfo {
|
|
pub name: String,
|
|
pub status: ServiceStatus,
|
|
pub memory_used_mb: f32,
|
|
pub memory_quota_mb: f32,
|
|
pub cpu_percent: f32,
|
|
pub sandbox_limit: Option<f32>,
|
|
#[serde(default)]
|
|
pub disk_used_gb: f32,
|
|
#[serde(default)]
|
|
pub disk_quota_gb: f32,
|
|
#[serde(default)]
|
|
pub is_sandboxed: bool,
|
|
#[serde(default)]
|
|
pub is_sandbox_excluded: bool,
|
|
#[serde(default)]
|
|
pub description: Option<Vec<String>>,
|
|
#[serde(default)]
|
|
pub sub_service: Option<String>,
|
|
#[serde(default)]
|
|
pub latency_ms: Option<f32>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub enum ServiceStatus {
|
|
Running,
|
|
Degraded,
|
|
Restarting,
|
|
Stopped,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct BackupMetrics {
|
|
pub overall_status: String,
|
|
pub backup: BackupInfo,
|
|
pub service: BackupServiceInfo,
|
|
#[serde(default)]
|
|
pub disk: Option<BackupDiskInfo>,
|
|
pub timestamp: DateTime<Utc>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
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,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct BackupServiceInfo {
|
|
pub enabled: bool,
|
|
pub pending_jobs: u32,
|
|
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,
|
|
Warning,
|
|
Failed,
|
|
Unknown,
|
|
}
|