Étape 1 : Installer Apache sur la machine à superviser Pour vérifier si Apache est déjà installé : dpkg -l | grep apache2 Si la commande retourne un numéro de version, Apache est déjà installé. Sinon : Sur Ubuntu/Debian : sudo apt update sudo apt install apache2 -y sudo systemctl enable apache2 sudo systemctl start apache2 sudo systemctl status apache2 Étape 2 : Installer le module de métriques pour Prometheus Prometheus ne peut pas lire directement les métriques Apache. On utilise apache_exporter. 2.1 Télécharger apache_exporter cd /opt sudo wget https://github.com/Lusitaniae/apache_exporter/releases/download/v1.0.10/apache_exporter-1.0.10.linux-amd64.tar.gz sudo 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/ 2.2 Créer un service systemd pour apache_exporter sudo nano /etc/systemd/system/apache_exporter.service -------------> [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 -------------> 2.3 Activer le module status d’Apache sudo a2enmod status sudo systemctl restart apache2 2.4 Démarrer apache_exporter sudo systemctl daemon-reload sudo systemctl enable apache_exporter sudo systemctl start apache_exporter sudo systemctl status apache_exporter Étape 4 : Collecter les logs Apache via Loki + Promtail 4.1 Installer Promtail sur la machine supervisée Si Promtail n’est pas encore installé, tu peux le télécharger depuis Grafana : cd /opt sudo wget https://github.com/grafana/loki/releases/download/v2.9.0/promtail-linux-amd64.zip sudo unzip promtail-linux-amd64.zip sudo mv promtail-linux-amd64 /usr/local/bin/promtail sudo chmod +x /usr/local/bin/promtail 4.2 Créer un fichier de config pour Promtail sudo nano /etc/promtail-config.yaml -------------> server: http_listen_port: 9080 grpc_listen_port: 0 positions: filename: /var/log/promtail-positions.yaml clients: - url: http://: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 -------------> 4.3 Créer un service systemd pour Promtail sudo nano /etc/systemd/system/promtail.service -------------> [Unit] Description=Promtail service for Apache logs After=network.target [Service] User=root ExecStart=/usr/local/bin/promtail -config.file /etc/promtail-config.yaml Restart=always [Install] WantedBy=multi-user.target -------------> sudo systemctl daemon-reload sudo systemctl enable promtail sudo systemctl start promtail sudo systemctl status promtail