23/10/25
This commit is contained in:
parent
afbe59ca68
commit
b01e5c5f4f
116
observabilite_service/Services/Tuto.txt
Normal file
116
observabilite_service/Services/Tuto.txt
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
1️⃣ Objectif
|
||||||
|
Métriques Apache → récupérées via Apache Exporter → Prometheus → Grafana.
|
||||||
|
Logs Apache → récupérés via Promtail → Loki → Grafana.
|
||||||
|
Vue complète dans Grafana avec métriques + logs.
|
||||||
|
|
||||||
|
2️⃣ Sur la VM qui héberge Apache (la VM à superviser)
|
||||||
|
|
||||||
|
2.1 Installer Apache Exporter
|
||||||
|
Télécharger l’exporter et le rendre exécutable :
|
||||||
|
|
||||||
|
wget https://github.com/Lusitaniae/apache_exporter/releases/download/v1.0.10/apache_exporter-1.0.10.linux-amd64.tar.gz
|
||||||
|
tar -xvf apache_exporter-1.0.10.linux-amd64.tar.gz
|
||||||
|
sudo mv apache_exporter-1.0.10.linux-amd64/apache_exporter /usr/local/bin/
|
||||||
|
|
||||||
|
Créer un service systemd pour Apache Exporter :
|
||||||
|
***
|
||||||
|
sudo tee /etc/systemd/system/apache_exporter.service <<EOF
|
||||||
|
[Unit]
|
||||||
|
Description=Prometheus Apache Exporter
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=root
|
||||||
|
ExecStart=/usr/local/bin/apache_exporter --scrape_uri="http://localhost/server-status?auto"
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
***
|
||||||
|
Activer et démarrer le service :
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl enable --now apache_exporter
|
||||||
|
sudo systemctl status apache_exporter
|
||||||
|
|
||||||
|
Vérifier le endpoint des métriques :
|
||||||
|
curl http://localhost:9117/metrics
|
||||||
|
|
||||||
|
2.2 Configurer Promtail pour les logs Apache
|
||||||
|
|
||||||
|
Créer le répertoire de config :
|
||||||
|
sudo mkdir -p /etc/promtail
|
||||||
|
sudo nano /etc/promtail/promtail-config.yml
|
||||||
|
|
||||||
|
Exemple de configuration pour séparer access et error logs :
|
||||||
|
**
|
||||||
|
server:
|
||||||
|
http_listen_port: 9080
|
||||||
|
grpc_listen_port: 0
|
||||||
|
|
||||||
|
positions:
|
||||||
|
filename: /var/log/promtail-positions.yaml
|
||||||
|
|
||||||
|
clients:
|
||||||
|
- url: http://<IP_VM_SUPERVISION>:3100/loki/api/v1/push
|
||||||
|
|
||||||
|
scrape_configs:
|
||||||
|
- job_name: apache_access
|
||||||
|
static_configs:
|
||||||
|
- targets: ['localhost']
|
||||||
|
labels:
|
||||||
|
job: apache_access
|
||||||
|
host: apache_vm
|
||||||
|
__path__: /var/log/apache2/access.log
|
||||||
|
|
||||||
|
- job_name: apache_error
|
||||||
|
static_configs:
|
||||||
|
- targets: ['localhost']
|
||||||
|
labels:
|
||||||
|
job: apache_error
|
||||||
|
host: apache_vm
|
||||||
|
__path__: /var/log/apache2/error.log
|
||||||
|
|
||||||
|
*****
|
||||||
|
Remplace <IP_VM_SUPERVISION> par l’IP de la VM où tourne Loki.
|
||||||
|
****
|
||||||
|
Créer le service systemd pour Promtail :
|
||||||
|
***
|
||||||
|
sudo tee /etc/systemd/system/promtail.service <<EOF
|
||||||
|
[Unit]
|
||||||
|
Description=Promtail service for Apache logs
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=root
|
||||||
|
ExecStart=/usr/local/bin/promtail -config.file /etc/promtail/promtail-config.yml
|
||||||
|
Restart=always
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
****
|
||||||
|
Activer et démarrer Promtail :
|
||||||
|
**
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo systemctl enable --now promtail
|
||||||
|
sudo systemctl status promtail
|
||||||
|
**
|
||||||
|
Générer une erreur pour tester :
|
||||||
|
curl http://localhost/page-inexistante
|
||||||
|
Vérifier error.log :
|
||||||
|
tail -f /var/log/apache2/error.log
|
||||||
|
|
||||||
|
4️⃣ Dans Grafana
|
||||||
|
Ajouter Prometheus comme datasource (port 9090).
|
||||||
|
Ajouter Loki comme datasource (port 3100).
|
||||||
|
Créer un dashboard avec :
|
||||||
|
**
|
||||||
|
Métriques Apache : requêtes, connexions, status codes depuis Prometheus.
|
||||||
|
**
|
||||||
|
Logs Apache :
|
||||||
|
job="apache_access" → access logs
|
||||||
|
job="apache_error" → error logs
|
||||||
|
**
|
||||||
|
Tester :
|
||||||
|
Faire une requête curl http://vmApache/page-inexistante → devrait apparaître dans apache_error.
|
||||||
|
Vérifier les logs et métriques dans Grafana.
|
||||||
Loading…
x
Reference in New Issue
Block a user