Monitoring serveur
Ce guide vous explique comment surveiller les performances de votre VPS Linux avec différents outils.
Outils en ligne de commande
htop - Moniteur interactif
htop est une version améliorée de top avec une interface colorée et interactive.
# Installation
sudo apt update
sudo apt install htop
# Lancement
htop
Raccourcis htop :
| Touche | Action |
|---|---|
F2 | Configuration |
F3 | Rechercher un processus |
F5 | Vue arborescente |
F6 | Trier par colonne |
F9 | Tuer un processus |
F10 | Quitter |
u | Filtrer par utilisateur |
Autres commandes utiles
# Utilisation mémoire
free -h
# Espace disque
df -h
# Utilisation par dossier
du -sh /var/*
# Charge système
uptime
# Connexions réseau
ss -tuln
# Processus consommant le plus de RAM
ps aux --sort=-%mem | head
# Processus consommant le plus de CPU
ps aux --sort=-%cpu | head
Netdata - Dashboard temps réel
Netdata offre un tableau de bord web avec des métriques en temps réel.
Installation
# Installation automatique
bash <(curl -Ss https://get.netdata.cloud/kickstart.sh)
Accès
Ouvrez http://VOTRE_IP:19999 dans votre navigateur.
Sécuriser l'accès
Par défaut, Netdata est accessible publiquement. Pour le sécuriser :
sudo nano /etc/netdata/netdata.conf
[web]
bind to = 127.0.0.1
Puis utilisez un reverse proxy Nginx avec authentification :
server {
listen 80;
server_name monitoring.example.com;
auth_basic "Monitoring";
auth_basic_user_file /etc/nginx/.htpasswd;
location / {
proxy_pass http://127.0.0.1:19999;
proxy_set_header Host $host;
}
}
Créer le fichier de mots de passe :
sudo apt install apache2-utils
sudo htpasswd -c /etc/nginx/.htpasswd admin
Grafana + Prometheus - Monitoring avancé
Pour un monitoring plus complet avec historique et alertes.
Installation avec Docker Compose
version: '3.8'
services:
prometheus:
image: prom/prometheus:latest
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
ports:
- "9090:9090"
restart: unless-stopped
node-exporter:
image: prom/node-exporter:latest
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
command:
- '--path.procfs=/host/proc'
- '--path.sysfs=/host/sys'
- '--path.rootfs=/rootfs'
ports:
- "9100:9100"
restart: unless-stopped
grafana:
image: grafana/grafana:latest
volumes:
- grafana_data:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_PASSWORD=votre_mot_de_passe
ports:
- "3000:3000"
restart: unless-stopped
volumes:
prometheus_data:
grafana_data:
Configuration Prometheus
Créez prometheus.yml :
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node'
static_configs:
- targets: ['node-exporter:9100']
Lancement
docker compose up -d
Configuration Grafana
- Accédez à
http://VOTRE_IP:3000 - Connectez-vous (admin / votre_mot_de_passe)
- Ajoutez Prometheus comme source de données :
- URL :
http://prometheus:9090
- URL :
- Importez un dashboard :
- Dashboard ID :
1860(Node Exporter Full)
- Dashboard ID :
Alertes par email
Avec Grafana
- Configuration > Alerting > Contact points
- Ajoutez un point de contact email
- Créez des règles d'alerte sur vos dashboards
Script simple d'alerte
#!/bin/bash
# /root/scripts/alert.sh
# Seuils
CPU_THRESHOLD=90
MEM_THRESHOLD=90
DISK_THRESHOLD=80
# Vérification CPU
CPU=$(top -bn1 | grep "Cpu(s)" | awk '{print $2}' | cut -d'.' -f1)
if [ $CPU -gt $CPU_THRESHOLD ]; then
echo "Alerte CPU: ${CPU}%" | mail -s "Alerte VPS" votre@email.com
fi
# Vérification mémoire
MEM=$(free | grep Mem | awk '{print int($3/$2 * 100)}')
if [ $MEM -gt $MEM_THRESHOLD ]; then
echo "Alerte Mémoire: ${MEM}%" | mail -s "Alerte VPS" votre@email.com
fi
# Vérification disque
DISK=$(df / | tail -1 | awk '{print $5}' | sed 's/%//')
if [ $DISK -gt $DISK_THRESHOLD ]; then
echo "Alerte Disque: ${DISK}%" | mail -s "Alerte VPS" votre@email.com
fi
Ajoutez à cron :
*/5 * * * * /root/scripts/alert.sh
Comparaison des outils
| Outil | Complexité | Historique | Interface | Idéal pour |
|---|---|---|---|---|
| htop | Simple | Non | Terminal | Debug rapide |
| Netdata | Facile | Limité | Web | Monitoring basique |
| Grafana | Avancé | Oui | Web | Production |
Conseil
Commencez par htop et Netdata. Passez à Grafana/Prometheus quand vous avez plusieurs serveurs à surveiller.