a53923fd8e
Agent: - SmartMetrics + champ device (nom du disque ex: sda, nvme0) - smart: Option<Vec<SmartMetrics>> — tous les disques, pas seulement le 1er - collect() itère /sys/block, accumule les résultats de tous les disques valides Serveur: - SmartMetrics.Device + Smart []SmartMetrics dans AgentMetrics - InsertMetrics: stocke smart_json (JSON array) au lieu de colonnes plates - GetLastMetrics: désérialise smart_json - Migration: smart_json TEXT ajoutée Dashboard: - Tuile: une icône shield/triangle par disque avec tooltip incluant le nom - Popup détail: un bouton SMART par disque (couleur ok/err) - showSmart(agentId, diskIdx): affiche le disque sélectionné Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
59 lines
2.1 KiB
Rust
59 lines
2.1 KiB
Rust
use nanometrics_agent::payload::{AgentMetrics, SmartMetrics};
|
|
|
|
#[test]
|
|
fn test_serialize_json_complet() {
|
|
let m = AgentMetrics {
|
|
hostname: "srv-01".to_string(),
|
|
ip: "10.0.0.11".to_string(),
|
|
cpu_percent: Some(42.5),
|
|
memory_used: Some(3_000_000_000),
|
|
memory_free: Some(5_000_000_000),
|
|
memory_total: Some(8_000_000_000),
|
|
hdd_used: Some(60_000_000_000),
|
|
hdd_free: Some(140_000_000_000),
|
|
hdd_total: Some(200_000_000_000),
|
|
uptime: Some(1234567),
|
|
network_rx: Some(1024),
|
|
network_tx: Some(512),
|
|
temperature: None,
|
|
smart: None,
|
|
status: "online".to_string(),
|
|
version: "0.0.0".to_string(),
|
|
};
|
|
let json = serde_json::to_string(&m).unwrap();
|
|
assert!(json.contains("\"hostname\":\"srv-01\""));
|
|
assert!(json.contains("\"cpu_percent\":42.5"));
|
|
assert!(json.contains("\"status\":\"online\""));
|
|
assert!(json.contains("\"temperature\":null"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_serialize_avec_smart() {
|
|
let m = AgentMetrics {
|
|
hostname: "srv-01".to_string(),
|
|
ip: "10.0.0.11".to_string(),
|
|
smart: Some(vec![SmartMetrics {
|
|
device: "sda".to_string(),
|
|
passed: true,
|
|
temperature: Some(34),
|
|
reallocated_sectors: Some(0),
|
|
power_on_hours: Some(4213),
|
|
wear_level: Some(98),
|
|
}]),
|
|
status: "online".to_string(),
|
|
..Default::default()
|
|
};
|
|
let json = serde_json::to_string(&m).unwrap();
|
|
assert!(json.contains("\"passed\":true"));
|
|
assert!(json.contains("\"temperature\":34"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_deserialize_depuis_json() {
|
|
let json = r#"{"hostname":"host1","ip":"10.0.0.1","status":"online","cpu_percent":55.0,"memory_used":null,"memory_free":null,"memory_total":null,"hdd_used":null,"hdd_free":null,"hdd_total":null,"uptime":null,"network_rx":null,"network_tx":null,"temperature":null,"smart":null}"#;
|
|
let m: AgentMetrics = serde_json::from_str(json).unwrap();
|
|
assert_eq!(m.hostname, "host1");
|
|
assert_eq!(m.cpu_percent, Some(55.0));
|
|
assert!(m.smart.is_none());
|
|
}
|