feat(agent): service systemd DynamicUser + documentation déploiement
- Ajoute deploy/nanometrics-agent.service avec DynamicUser, ProtectSystem, PrivateTmp, NoNewPrivileges et RestrictAddressFamilies - Ajoute deploy/README.md avec procédure d'installation/désinstallation - Corrige 3 avertissements clippy : iter_kv_map (network.rs) et collapsible_match (mqtt.rs) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
use sysinfo::Networks;
|
||||
|
||||
pub fn get(networks: &Networks) -> (u64, u64) {
|
||||
let rx: u64 = networks.iter().map(|(_, n)| n.total_received()).sum();
|
||||
let tx: u64 = networks.iter().map(|(_, n)| n.total_transmitted()).sum();
|
||||
let rx: u64 = networks.values().map(|n| n.total_received()).sum();
|
||||
let tx: u64 = networks.values().map(|n| n.total_transmitted()).sum();
|
||||
(rx, tx)
|
||||
}
|
||||
|
||||
|
||||
@@ -57,12 +57,10 @@ pub fn start(
|
||||
QoS::AtLeastOnce,
|
||||
);
|
||||
}
|
||||
Ok(Event::Incoming(Packet::Publish(p))) => {
|
||||
if p.topic == config_topic_clone {
|
||||
let _ = incoming_tx.send(MqttIncoming::ConfigUpdate(
|
||||
p.payload.to_vec(),
|
||||
));
|
||||
}
|
||||
Ok(Event::Incoming(Packet::Publish(p))) if p.topic == config_topic_clone => {
|
||||
let _ = incoming_tx.send(MqttIncoming::ConfigUpdate(
|
||||
p.payload.to_vec(),
|
||||
));
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("[mqtt] erreur: {}", e);
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
# Déploiement de l'agent Nanometrics
|
||||
|
||||
## Prérequis
|
||||
|
||||
- Debian/Ubuntu amd64
|
||||
- systemd
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
# Copier le binaire
|
||||
sudo cp ../agent/target/release/nanometrics-agent /usr/local/bin/
|
||||
sudo chmod 755 /usr/local/bin/nanometrics-agent
|
||||
|
||||
# Créer la configuration
|
||||
sudo mkdir -p /etc/nanometrics
|
||||
sudo cp ../agent/config.toml.example /etc/nanometrics/config.toml
|
||||
sudo nano /etc/nanometrics/config.toml # ajuster server.ip
|
||||
|
||||
# Installer et démarrer le service
|
||||
sudo cp nanometrics-agent.service /etc/systemd/system/
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable nanometrics-agent
|
||||
sudo systemctl start nanometrics-agent
|
||||
sudo systemctl status nanometrics-agent
|
||||
```
|
||||
|
||||
## Vérification
|
||||
|
||||
```bash
|
||||
sudo journalctl -u nanometrics-agent -f
|
||||
```
|
||||
|
||||
## Désinstallation
|
||||
|
||||
```bash
|
||||
sudo systemctl stop nanometrics-agent
|
||||
sudo systemctl disable nanometrics-agent
|
||||
sudo rm /etc/systemd/system/nanometrics-agent.service
|
||||
sudo rm /usr/local/bin/nanometrics-agent
|
||||
sudo rm -rf /etc/nanometrics
|
||||
sudo systemctl daemon-reload
|
||||
```
|
||||
@@ -0,0 +1,24 @@
|
||||
[Unit]
|
||||
Description=Nanometrics Agent — collecte de métriques système
|
||||
After=network.target
|
||||
Documentation=https://git.maison43gil.com/gilles/nano_metrics
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/local/bin/nanometrics-agent /etc/nanometrics/config.toml
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
|
||||
DynamicUser=yes
|
||||
ConfigurationDirectory=nanometrics
|
||||
ConfigurationDirectoryMode=0750
|
||||
|
||||
ProtectSystem=strict
|
||||
ProtectHome=read-only
|
||||
PrivateTmp=yes
|
||||
NoNewPrivileges=yes
|
||||
|
||||
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in New Issue
Block a user