feat(agent): setup Cargo.toml et structure complète

Initialise la structure de l'agent Rust avec tous les modules stub :
config, payload, metrics (cpu/memory/disk/network/uptime/temperature/smart),
transport (udp/mqtt). Corrige les features sysinfo 0.30 (pas de feature
disk/networks séparées). Compile sans erreurs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Gilles Soulier
2026-05-22 08:21:34 +02:00
parent 395e006014
commit 3f5c735507
16 changed files with 1178 additions and 1 deletions
+81
View File
@@ -0,0 +1,81 @@
// stub — implémenté dans la Task 2
use serde::Deserialize;
use std::path::Path;
#[derive(Deserialize, Debug, Clone, Default)]
pub struct Config {
pub server: ServerConfig,
pub protocols: ProtocolsConfig,
#[serde(default)]
pub metrics: MetricsConfig,
}
#[derive(Deserialize, Debug, Clone, Default)]
pub struct ServerConfig {
pub ip: String,
pub port: u16,
}
#[derive(Deserialize, Debug, Clone, Default)]
pub struct ProtocolsConfig {
#[serde(default)]
pub udp: UdpConfig,
#[serde(default)]
pub mqtt: MqttConfig,
}
#[derive(Deserialize, Debug, Clone, Default)]
pub struct UdpConfig {
#[serde(default)]
pub enabled: bool,
}
#[derive(Deserialize, Debug, Clone, Default)]
pub struct MqttConfig {
#[serde(default)]
pub enabled: bool,
#[serde(default)]
pub host: String,
#[serde(default)]
pub port: u16,
#[serde(default)]
pub topic_base: String,
#[serde(default)]
pub auto_discovery: bool,
#[serde(default)]
pub birth_message: bool,
#[serde(default)]
pub last_will: bool,
}
#[derive(Deserialize, Debug, Clone, Default)]
pub struct MetricsConfig {
#[serde(default)]
pub cpu: MetricProto,
#[serde(default)]
pub memory: MetricProto,
#[serde(default)]
pub disk: MetricProto,
#[serde(default)]
pub network: MetricProto,
#[serde(default)]
pub uptime: MetricProto,
#[serde(default)]
pub temperature: MetricProto,
#[serde(default)]
pub smart: MetricProto,
}
#[derive(Deserialize, Debug, Clone, Default)]
pub struct MetricProto {
#[serde(default)]
pub udp: bool,
#[serde(default)]
pub mqtt: bool,
}
pub fn load(path: &Path) -> Result<Config, Box<dyn std::error::Error>> {
let content = std::fs::read_to_string(path)?;
let config: Config = toml::from_str(&content)?;
Ok(config)
}
+9
View File
@@ -0,0 +1,9 @@
use nanometrics_agent::config;
fn main() {
let cfg_path = std::env::args()
.nth(1)
.unwrap_or_else(|| "config.toml".to_string());
let _cfg = config::load(std::path::Path::new(&cfg_path));
println!("nanometrics-agent starting");
}
+3
View File
@@ -0,0 +1,3 @@
pub fn get(_sys: &sysinfo::System) -> f32 {
0.0
}
+5
View File
@@ -0,0 +1,5 @@
use sysinfo::Disks;
pub fn get(_disks: &Disks) -> (u64, u64, u64) {
(0, 0, 0)
}
+3
View File
@@ -0,0 +1,3 @@
pub fn get(_sys: &sysinfo::System) -> (u64, u64, u64) {
(0, 0, 0)
}
+7
View File
@@ -0,0 +1,7 @@
pub mod cpu;
pub mod disk;
pub mod memory;
pub mod network;
pub mod smart;
pub mod temperature;
pub mod uptime;
+5
View File
@@ -0,0 +1,5 @@
use sysinfo::Networks;
pub fn get(_nets: &Networks) -> (u64, u64) {
(0, 0)
}
+13
View File
@@ -0,0 +1,13 @@
use crate::payload::SmartMetrics;
pub fn is_available() -> bool {
false
}
pub fn parse_json(_: &str) -> Result<SmartMetrics, serde_json::Error> {
serde_json::from_str("null")
}
pub fn collect() -> Option<SmartMetrics> {
None
}
+5
View File
@@ -0,0 +1,5 @@
use sysinfo::Components;
pub fn get(_c: &Components) -> Option<f32> {
None
}
+3
View File
@@ -0,0 +1,3 @@
pub fn get() -> u64 {
0
}
+30
View File
@@ -0,0 +1,30 @@
// stub — implémenté dans la Task 3
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Default)]
pub struct AgentMetrics {
pub hostname: String,
pub ip: String,
pub status: String,
pub cpu_percent: Option<f32>,
pub memory_used: Option<u64>,
pub memory_free: Option<u64>,
pub memory_total: Option<u64>,
pub hdd_used: Option<u64>,
pub hdd_free: Option<u64>,
pub hdd_total: Option<u64>,
pub uptime: Option<u64>,
pub network_rx: Option<u64>,
pub network_tx: Option<u64>,
pub temperature: Option<f32>,
pub smart: Option<SmartMetrics>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SmartMetrics {
pub passed: bool,
pub temperature: Option<i64>,
pub reallocated_sectors: Option<i64>,
pub power_on_hours: Option<i64>,
pub wear_level: Option<i64>,
}
+2
View File
@@ -0,0 +1,2 @@
pub mod mqtt;
pub mod udp;
+22
View File
@@ -0,0 +1,22 @@
use crate::config::MqttConfig;
use std::sync::mpsc::Sender;
pub enum MqttIncoming {
ConfigUpdate(Vec<u8>),
}
pub struct MqttClient;
impl MqttClient {
pub fn clone(&self) -> Self {
MqttClient
}
}
pub fn start(_hostname: &str, _cfg: &MqttConfig, _tx: Sender<MqttIncoming>) -> rumqttc::Client {
let opts = rumqttc::MqttOptions::new("stub", "localhost", 1883);
let (client, _conn) = rumqttc::Client::new(opts, 1);
client
}
pub fn publish_metrics(_client: &rumqttc::Client, _base: &str, _hostname: &str, _json: &str) {}
+9
View File
@@ -0,0 +1,9 @@
pub struct UdpSender;
impl UdpSender {
pub fn new(_ip: &str, _port: u16) -> Self {
UdpSender
}
pub fn send(&self, _json: &str) {}
}