Skip to content

Commit 18b4ba4

Browse files
committed
feat: Intégration de la pile EFK (Elasticsearch, Fluentd, Kibana)
- Ajout d'Elasticsearch 8.11.1 pour le stockage et l'indexation des logs - Ajout de Fluentd avec plugin Elasticsearch pour la collecte des logs - Ajout de Kibana 8.11.1 pour la visualisation et l'analyse des logs - Configuration du logging fluentd pour Drupal et PostgreSQL - Création de la configuration Fluentd (fluent.conf et Dockerfile) - Mise à jour du QUICKSTART.md avec les instructions EFK - Création d'une documentation complète (docs/EFK_STACK.md) - Mise à jour du .gitignore pour ignorer les données EFK Les logs sont automatiquement collectés et indexés dans Elasticsearch. Accès Kibana: http://localhost:5601 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent bb255b3 commit 18b4ba4

File tree

6 files changed

+563
-0
lines changed

6 files changed

+563
-0
lines changed

.claude/QUICKSTART.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,42 @@ git push origin main
3737
cp -r . /mnt/user-data/outputs/drupal-mania/
3838
```
3939

40+
## Pile EFK (Elasticsearch, Fluentd, Kibana)
41+
42+
Le projet intègre une pile complète de gestion et visualisation des logs.
43+
44+
### Accès aux services
45+
46+
```bash
47+
# Démarrer tous les services (incluant EFK)
48+
docker compose up -d
49+
50+
# Vérifier l'état des services
51+
docker compose ps
52+
53+
# Accès Kibana (visualisation des logs)
54+
http://localhost:5601
55+
56+
# Accès Elasticsearch (API)
57+
http://localhost:9200
58+
```
59+
60+
### Utilisation de Kibana
61+
62+
1. Ouvrir http://localhost:5601
63+
2. Aller dans "Management" > "Stack Management" > "Index Patterns"
64+
3. Créer un index pattern: `drupal-mania-*`
65+
4. Sélectionner `@timestamp` comme champ de temps
66+
5. Aller dans "Discover" pour voir les logs
67+
68+
### Configuration
69+
70+
- **Elasticsearch**: Port 9200 (données stockées dans `./data/elasticsearch`)
71+
- **Fluentd**: Port 24224 (config dans `./config/fluentd`)
72+
- **Kibana**: Port 5601 (variable `KIBANA_PORT` dans `.env`)
73+
74+
Les logs de Drupal et PostgreSQL sont automatiquement collectés et indexés.
75+
4076
## Règles essentielles
4177

4278
- Toujours partir de la dernière version Git

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ Thumbs.db
4848
# Docker data
4949
data/postgres/
5050
data/drupal/
51+
data/elasticsearch/
52+
data/fluentd/

config/fluentd/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Dockerfile personnalisé pour Fluentd avec plugin Elasticsearch
2+
FROM fluent/fluentd:v1.16-1
3+
4+
# Passer en mode root pour installer les gems
5+
USER root
6+
7+
# Installer le plugin Elasticsearch
8+
RUN gem install fluent-plugin-elasticsearch
9+
10+
# Revenir à l'utilisateur fluent
11+
USER fluent

config/fluentd/fluent.conf

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Configuration Fluentd pour Drupal-Mania
2+
# Collecte des logs de Drupal et PostgreSQL vers Elasticsearch
3+
4+
# Source: écoute des logs Docker via forward
5+
<source>
6+
@type forward
7+
port 24224
8+
bind 0.0.0.0
9+
</source>
10+
11+
# Filtre: Parser les logs Drupal
12+
<filter drupal>
13+
@type parser
14+
key_name log
15+
reserve_data true
16+
<parse>
17+
@type regexp
18+
expression /^\[(?<timestamp>[^\]]+)\] (?<level>\w+): (?<message>.*)$/
19+
time_key timestamp
20+
time_format %Y-%m-%d %H:%M:%S
21+
</parse>
22+
</filter>
23+
24+
# Filtre: Parser les logs PostgreSQL
25+
<filter postgres>
26+
@type parser
27+
key_name log
28+
reserve_data true
29+
<parse>
30+
@type regexp
31+
expression /^(?<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3} \w+) \[(?<process_id>\d+)\] (?<level>\w+): (?<message>.*)$/
32+
time_key timestamp
33+
time_format %Y-%m-%d %H:%M:%S.%N %Z
34+
</parse>
35+
</filter>
36+
37+
# Filtre: Ajouter des métadonnées
38+
<filter **>
39+
@type record_transformer
40+
<record>
41+
hostname "#{Socket.gethostname}"
42+
environment "${ENVIRONMENT:-production}"
43+
project "drupal-mania"
44+
</record>
45+
</filter>
46+
47+
# Output: Envoyer vers Elasticsearch
48+
<match **>
49+
@type elasticsearch
50+
host elasticsearch
51+
port 9200
52+
logstash_format true
53+
logstash_prefix drupal-mania
54+
logstash_dateformat %Y.%m.%d
55+
include_tag_key true
56+
tag_key @log_name
57+
flush_interval 10s
58+
59+
<buffer>
60+
@type file
61+
path /fluentd/log/buffer
62+
flush_mode interval
63+
retry_type exponential_backoff
64+
flush_thread_count 2
65+
flush_interval 10s
66+
retry_forever false
67+
retry_max_interval 30
68+
chunk_limit_size 2M
69+
queue_limit_length 8
70+
overflow_action block
71+
</buffer>
72+
</match>

docker-compose.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ services:
1919
interval: 10s
2020
timeout: 5s
2121
retries: 5
22+
logging:
23+
driver: fluentd
24+
options:
25+
fluentd-address: localhost:24224
26+
tag: postgres
27+
depends_on:
28+
- fluentd
2229

2330
# Service Drupal
2431
drupal:
@@ -46,8 +53,70 @@ services:
4653
networks:
4754
- drupal-network
4855
depends_on:
56+
- fluentd
4957
postgres:
5058
condition: service_healthy
59+
logging:
60+
driver: fluentd
61+
options:
62+
fluentd-address: localhost:24224
63+
tag: drupal
64+
65+
# Service Elasticsearch
66+
elasticsearch:
67+
image: docker.elastic.co/elasticsearch/elasticsearch:8.11.1
68+
container_name: drupal-elasticsearch
69+
restart: unless-stopped
70+
environment:
71+
- discovery.type=single-node
72+
- xpack.security.enabled=false
73+
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
74+
volumes:
75+
- ./data/elasticsearch:/usr/share/elasticsearch/data
76+
networks:
77+
- drupal-network
78+
ports:
79+
- "9200:9200"
80+
- "9300:9300"
81+
healthcheck:
82+
test: ["CMD-SHELL", "curl -f http://localhost:9200/_cluster/health || exit 1"]
83+
interval: 30s
84+
timeout: 10s
85+
retries: 5
86+
87+
# Service Fluentd
88+
fluentd:
89+
build:
90+
context: ./config/fluentd
91+
dockerfile: Dockerfile
92+
container_name: drupal-fluentd
93+
restart: unless-stopped
94+
ports:
95+
- "24224:24224"
96+
- "24224:24224/udp"
97+
volumes:
98+
- ./config/fluentd/fluent.conf:/fluentd/etc/fluent.conf
99+
- ./data/fluentd:/fluentd/log
100+
networks:
101+
- drupal-network
102+
depends_on:
103+
elasticsearch:
104+
condition: service_healthy
105+
106+
# Service Kibana
107+
kibana:
108+
image: docker.elastic.co/kibana/kibana:8.11.1
109+
container_name: drupal-kibana
110+
restart: unless-stopped
111+
ports:
112+
- "${KIBANA_PORT:-5601}:5601"
113+
environment:
114+
- ELASTICSEARCH_HOSTS=http://elasticsearch:9200
115+
networks:
116+
- drupal-network
117+
depends_on:
118+
elasticsearch:
119+
condition: service_healthy
51120

52121
networks:
53122
drupal-network:

0 commit comments

Comments
 (0)