2025-10-23 13:18:31 +02:00

116 lines
3.0 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 lexporter 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 lIP 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.