Project Oxygen & Ideo-LabIDEO LAB Dashboard 2026

📊 ELK / Elastic Stack – Logs, Recherche & Dashboards

Guide IDEO-Lab densifié : architecture ELK, ingestion (Beats/Logstash), indexation Elasticsearch, dashboards Kibana, sécurité, ILM, scaling, troubleshooting + cheat-sheet.

1.1

ELK en bref

Pourquoi ELK, quels usages, et comment penser “log pipeline”.

logssearchdashboards
1.2

Composants (E/L/K + Beats)

Elasticsearch, Logstash, Kibana, Filebeat/Metricbeat


ESLogstashKibana
1.3

Architecture type

Agents → ingest → index → queries → dashboards / alerting.

pipelineingestILM
2.1

Installation (Docker / Linux)

Docker Compose rapide + checklist prod (sysctl, vm.max_map_count).

dockercomposelinux
2.2

Filebeat / Agents

Collecte logs Nginx/Django, multiline, champs, processors.

filebeatnginxdjango
2.3

Logstash (parse & enrich)

Grok, mutate, geoip, fingerprint, routing par index.

grokgeoipenrich
3.1

Elasticsearch (indexation)

Mappings, analyzers, shards/replicas, templates, data streams.

mappingshardsqueries

3.2 ILM & rétention

Hot/Warm/Cold, rollover, delete, optimiser coût & perf.

ILMretention
3.3

Kibana (dashboards)

Discover, Lens, dashboards, saved searches, spaces.

discoverlensspaces

4.1 Sécurité

TLS, auth, RBAC, API keys, hardening, réseaux.

TLSRBAChardening
4.2

Scaling & sizing

Volumes, CPU/RAM, shards strategy, ingest throughput.

sizingshardsperf
4.3

Troubleshooting

Index bloqués, mapping explosion, pipeline drops, slow queries.

errorsmappinglatency
1.1 ELK – Vue d’ensemble, cas d’usage & mental model
ELK (Elastic Stack) sert Ă  quoi ?

Centraliser des logs (serveurs, apps, containers) puis permettre : recherche ultra rapide, corrĂ©lation, dashboards, et alerting. C’est l’équivalent “Google pour tes logs”, mais industrialisĂ©.

Centralisation Recherche / queries Dashboards Alertes Audit / sécurité

Quand ELK est un bon choix ?
  • Beaucoup de services / serveurs → besoin d’un “log hub”.
  • Investigations incidents (500, timeouts, erreurs DB, attaques).
  • Besoin d’audit : “qui a fait quoi”, “quand”, “depuis quelle IP”.
  • Recherche full-text sur logs + filtres structurĂ©s (JSON).
ELK vs alternatives rapides
StackPoint fortQuand
ELK/ElasticSearch + enrich + dashboards richesSi tu veux “tout” + gros volumes
EFKFluent Bit/Fluentd en K8sPipeline Kubernetes standard
Loki + GrafanaSimple, souvent moins coûteuxLogs orientés time-series
OpenSearchÉcosystùme proche ESSi tu veux alternative compatible
Bon pattern : logs JSON structurĂ©s (app) + enrich (geoip/request_id) → dashboards qui “racontent” l’incident.
Flux ELK (mental model)
[Apps / Servers / Containers]
   │ logs (files, stdout, syslog)
   ▌
[Agents]
  - Filebeat / Elastic Agent
  - Fluent Bit (si K8s)
   │
   ▌
[Ingest layer]
  - Logstash (grok, enrich, route)
  - Elasticsearch ingest pipelines (option)
   │
   ▌
[Elasticsearch]
  - index / data stream
  - mappings + analyzers
  - shards + replicas
  - ILM (retention)
   │
   ▌
[Kibana]
  - Discover (recherche)
  - Dashboards (Lens)
  - Alerting
        

Objectif : rĂ©duire le temps “incident → cause → fix” en rendant les logs consultables en 10 secondes.

Use-cases infra / web
  • Nginx : top 404/500, latences, IPs, user-agents suspects.
  • SystĂšme : auth.log, sudo, ssh brute-force, kernel messages.
  • K8s : logs pods + events, corrĂ©lations par namespace/app.
Use-cases app (Django)
  • Erreurs 500 : stack traces + contexte request.
  • Slow endpoints : corrĂ©ler logs app ↔ logs DB ↔ Nginx.
  • TraçabilitĂ© : request_id / trace_id du front au back.
Use-cases sécurité
  • Audit : “quel user a modifiĂ© quoi” (admin/backoffice).
  • DĂ©tection anomalies : spikes d’échecs login, scans URL.
  • GeoIP + reputation (enrich) → dashboards “attaque”.
KPI simples
  • Errors/minute (5xx)
  • Top endpoints (p95 latency)
  • Top IPs / countries
  • Volume logs / jour (coĂ»t)
PiÚges classiques (et comment les éviter)
PiĂšgeSymptĂŽmeSolution
Mapping explosiontrop de champs uniquesLogs JSON maßtrisés, dynamic templates
Trop de shardscluster lent / instableshards raisonnables + ILM rollover
Grok trop lourdCPU Logstash highpréférer logs JSON + parse léger
Rétention oubliéedisque exploseILM + delete policy
1.2 Composants ELK – Elasticsearch, Logstash, Kibana + Beats
Elasticsearch (E)
  • Moteur d’indexation + recherche (full-text + filtres).
  • Stockage “document” (JSON) avec mapping (types).
  • DistribuĂ© : shards (scaling) + replicas (HA).
Logstash (L)
  • Pipeline ingestion : input → filter → output.
  • Parse (grok), enrich (geoip), normalise, route vers index.
  • TrĂšs flexible mais peut coĂ»ter cher en CPU si mal rĂ©glĂ©.
Kibana (K)
  • Interface web : Discover, Lens, dashboards, alerting.
  • Gestion index patterns / data views, spaces.
  • Outil principal d’analyse incident (timepicker + filtres).
Beats / Agents (collecte)
AgentRĂŽleExemple
Filebeatlogs fichiers/var/log/nginx/access.log
Metricbeatmetrics systĂšmeCPU, RAM, FS, process
Heartbeatuptime probesHTTP/ICMP checks
Auditbeataudit sécuritésyscalls, file integrity
Best practice : privilégier logs JSON structurés cÎté app (moins de grok, moins de CPU).
1.3 Architecture ELK – patterns, index naming & conventions
3 patterns courants
PatternFluxQuand
Direct to ESBeats → ElasticsearchSimple, faible parsing
Via LogstashBeats → Logstash → ESParsing/enrich avancĂ©
Ingest pipelines ESBeats → ES (pipeline)Moins de briques, parsing modĂ©rĂ©
Rule of thumb:
- Si tu peux: logs JSON → Beats → ES (pipeline lĂ©ger)
- Si tu dois: formats hĂ©tĂ©rogĂšnes → Logstash (grok + enrich)
        
Nommage d’index (lisible + ILM)
Exemples:
- logs-nginx-prod-YYYY.MM.DD
- logs-django-prod-YYYY.MM.DD
- logs-system-dev-YYYY.MM.DD

Ou en data streams (recommandé):
- logs-nginx-prod (data stream) -> backing indices gérés par rollover/ILM
        

But : query facile + rétention facile (ILM) + séparation prod/dev.

Champs standard (minimum viable schema)
ChampUsageExemple
@timestamptime picker2026-01-10T09:15:12Z
service.namefiltre servicedjango-api
envprod/devprod
log.levelINFO/WARN/ERRORERROR
http.response.status_code5xx dashboards500
trace.id / request_idcorrélation2f3a

QualitĂ© des donnĂ©es (ELK “pro”)
  • DĂ©cider : JSON logs ou texte + grok (JSON recommandĂ©).
  • Normaliser niveaux : DEBUG/INFO/WARN/ERROR.
  • Ajouter request_id dans Nginx + app (corrĂ©lation).
  • Éviter champs dynamiques (risque mapping explosion).
2.1 Installation ELK – Docker Compose + checklist prod
Docker Compose minimal (lab)
version: "3.8"
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0
    environment:
      - discovery.type=single-node
      - xpack.security.enabled=false
      - ES_JAVA_OPTS=-Xms1g -Xmx1g
    ulimits:
      memlock: { soft: -1, hard: -1 }
    ports: ["9200:9200"]
  kibana:
    image: docker.elastic.co/kibana/kibana:8.12.0
    environment:
      - ELASTICSEARCH_HOSTS=http://elasticsearch:9200
    ports: ["5601:5601"]
    depends_on: [elasticsearch]
  logstash:
    image: docker.elastic.co/logstash/logstash:8.12.0
    ports: ["5044:5044"]
    depends_on: [elasticsearch]
        
En prod : sécurité ON, TLS, users, et cluster multi-nodes (pas single-node).
Pré-requis Linux (trÚs fréquent)
# Elasticsearch a souvent besoin de :
sudo sysctl -w vm.max_map_count=262144
# (persist: /etc/sysctl.conf)

# Vérifier mémoire/disque:
free -h
df -h
        

Si ES refuse de démarrer, vm.max_map_count est souvent la cause.

Checklist production
ThùmeÀ faire
HA≄ 3 nodes ES (master/data), replicas > 0
DisqueSurveiller watermark + ILM delete
SecurityTLS, auth, RBAC, network restrictions
RétentionILM rollover + delete (jours)
BackupSnapshots repository (S3/NFS)
Ports courants
9200 : Elasticsearch HTTP API
9300 : Elasticsearch transport (cluster interne)
5601 : Kibana
5044 : Logstash beats input
        

En prod : Ă©viter d’exposer 9200 publiquement (WAF/VPN + auth + TLS).

2.2 Filebeat – collecte logs Nginx/Django + multiline + processors
Collecte Nginx
filebeat.inputs:
- type: filestream
  id: nginx-access
  paths:
    - /var/log/nginx/access.log
  fields:
    service: nginx
    env: prod
  fields_under_root: true

output.logstash:
  hosts: ["logstash:5044"]
        

Idéal : logs Nginx en JSON (sinon grok cÎté Logstash).

Collecte logs app Django
filebeat.inputs:
- type: filestream
  id: django-app
  paths:
    - /opt/app/logs/django.log
  fields:
    service: django
    env: prod
  fields_under_root: true

processors:
  - add_host_metadata: ~
  - add_cloud_metadata: ~
        

Si tes logs Django sont JSON → tu peux parser directement (moins de grok).

Multiline (stack traces)
parsers:
  - multiline:
      type: pattern
      pattern: '^\['
      negate: true
      match: after
        

Objectif : une exception Python = un seul “event” indexĂ©.

Best practices agents
  • Ajouter service, env, host en champs standard.
  • Limiter bruit : DEBUG en prod seulement si nĂ©cessaire.
  • Rotation logs cĂŽtĂ© OS/app + vĂ©rifier permissions.
  • Éviter donnĂ©es sensibles (tokens, passwords) dans logs.
2.3 Logstash – inputs, grok, enrich, routing vers index
Pipeline type
input {
  beats { port => 5044 }
}

filter {
  # parse/enrich ici
}

output {
  elasticsearch {
    hosts => ["http://elasticsearch:9200"]
    index => "logs-%{service}-%{env}-%{+YYYY.MM.dd}"
  }
}
        
Grok (si logs texte)
filter {
  if [service] == "nginx" {
    grok {
      match => { "message" => "%{IPORHOST:client_ip} - %{DATA:remote_user} \[%{HTTPDATE:ts}\] \"%{WORD:method} %{DATA:uri} HTTP/%{NUMBER:http_version}\" %{NUMBER:status} %{NUMBER:bytes}" }
    }
  }
}
        

Grok est puissant mais coûteux : si possible, préfÚre logs JSON.

Enrichissement (geoip + fingerprint)
filter {
  if [client_ip] {
    geoip { source => "client_ip" }
  }
  fingerprint {
    source => ["message"]
    target => "event_hash"
    method => "SHA1"
  }
}
        
Routing vers index différents
output {
  if [service] == "django" {
    elasticsearch { index => "logs-django-%{env}-%{+YYYY.MM.dd}" }
  } else if [service] == "nginx" {
    elasticsearch { index => "logs-nginx-%{env}-%{+YYYY.MM.dd}" }
  } else {
    elasticsearch { index => "logs-misc-%{env}-%{+YYYY.MM.dd}" }
  }
}
        
2.4 Pipeline de bout en bout – “Nginx + Django → ELK” (prĂȘt incident)
Objectif : corrélation avec request_id
  • Nginx gĂ©nĂšre un $request_id (ou trace header).
  • Django rĂ©cupĂšre ce header et le loggue.
  • Dans Kibana : filtre sur request_id → tu vois le chemin complet.
Nginx (concept)
# access_log JSON + request_id (idéal)
log_format json escape=json '{ "ts":"$time_iso8601", "request_id":"$request_id",
 "status":$status, "method":"$request_method", "uri":"$request_uri",
 "ip":"$remote_addr", "ua":"$http_user_agent", "rt":$request_time }';
access_log /var/log/nginx/access.log json;
          
Django (concept)
# Middleware: inject request_id into logs
# Log JSON: {"service":"django","request_id":"...","level":"ERROR","msg":"..."}
          
Dashboards Kibana “incident”
  • Top 5xx (par uri)
  • Latence p95 (par endpoint)
  • Top IPs / UA
  • Erreurs Django (stack traces) + request_id
Si tu fais JSON logs partout (Nginx + Django), tu rĂ©duis Logstash Ă  “route + enrich”, et ELK devient beaucoup plus stable.
3.1 Elasticsearch – index, mappings, shards/replicas, templates
Concepts essentiels
  • Index : collection de documents (JSON)
  • Document : event log enrichi
  • Mapping : types (keyword/text/date/long
)
  • Analyzer : full-text search (tokenization)
Mapping : éviter les surprises
- keyword : filtres exacts (service, env, status)
- text    : full-text (message)
- date    : @timestamp
- long    : bytes, latency_ms
        

Danger : champs dynamiques non maĂźtrisĂ©s → “mapping explosion”.

Shards/replicas : l’erreur n°1
  • Trop de shards = surcharge metadata + cluster lent.
  • Pas assez = index trop gros, queries lentes.
  • ILM + rollover = stratĂ©gie moderne (index “petits”).
RequĂȘtes utiles (concept Kibana)
service: nginx AND env: prod AND http.response.status_code: >=500
request_id: "abc123"
message: "timeout" AND NOT uri: "/health"
        
3.2 ILM – rĂ©tention, rollover, hot/warm/cold & optimisation coĂ»ts
Pourquoi ILM est indispensable ?
  • MaĂźtriser le disque (sinon “ELK remplit tout”).
  • Optimiser la perf : rĂ©cent = hot, ancien = cold.
  • Automatiser : rollover + delete.
ILM phases (classique):
- hot  : indexation + queries fréquentes
- warm : moins de perf, storage moins cher
- cold : archive
- delete: suppression aprĂšs X jours
          
RĂšgles simples (pragmatiques)
Type logsRétentionNote
Access logs7–30 joursutile incidents + stats
App errors30–90 joursdebug long terme
Audit sĂ©curitĂ©90–365 jourscompliance (selon besoin)

Toujours adapter Ă  tes volumes (GB/jour) et au budget disque.

3.3 Kibana – Discover, Lens, Dashboards, Spaces & Alerting
Discover = enquĂȘte
  • Filtrer par service, env, status, request_id.
  • Timepicker : rĂ©duire la fenĂȘtre pour performance.
  • Sauvegarder des recherches (saved search) pour rĂ©utiliser.
Lens = graphiques rapides
  • Time series : erreurs/minute, latence p95.
  • Top values : top endpoints, top IPs.
  • Breakdown : par env/service.
Dashboards “prod web” recommandĂ©s
  • HTTP 5xx (par endpoint)
  • Latence p95 (par endpoint)
  • Top IP / UA
  • Django ERROR logs (stack traces)
  • DB timeouts / slow queries (si logguĂ©s)
Alerting (concept)
Alert 1: 5xx rate > threshold for 5 minutes
Alert 2: p95 latency > threshold
Alert 3: login failures spike (security)
        

Commencer simple, sinon trop d’alertes = ignorĂ©es.

4.1 SĂ©curitĂ© ELK – TLS, Auth, RBAC, rĂ©seau & hardening
Rùgles d’or
  • Ne pas exposer ES (9200) sur Internet sans contrĂŽle strict.
  • Activer auth + TLS (trafic chiffrĂ©, credentials protĂ©gĂ©s).
  • RBAC : sĂ©parer viewers (Kibana) vs admins cluster.
  • Masquer/filtrer donnĂ©es sensibles dans logs.
Segmentation réseau
- ES cluster: réseau privé
- Kibana: accĂšs via VPN / reverse proxy / SSO
- Agents: envoyent vers Logstash/ES via réseau interne
          
ModĂšle rĂŽles (simple)
RĂŽleDroitsQui
Viewerlecture dashboardsdev / support
AnalystDiscover + dashboardsSRE / incident
Adminindex/templates/ILMops plateforme
Important : si tes logs contiennent des tokens, ELK devient un “coffre Ă  secrets” involontaire → Ă  Ă©viter absolument.
4.2 Scaling & Sizing – volumes, shards strategy, perf & coĂ»ts
Questions Ă  poser (dimensionnement)
  • GB/jour de logs ? (nginx + app + system)
  • RĂ©tention ? (jours)
  • Queries ? (combien d’utilisateurs Kibana)
  • Parsing ? (grok lourd ou JSON)
Quick estimation (trĂšs simple)
Stock ≈ (GB/jour) * (jours rĂ©tention) * (facteur overhead 1.2 Ă  2.0)
Ex: 20 GB/jour * 30j * 1.5 ≈ 900 GB
          
Perf : leviers principaux
  • ILM + rollover (indices petits et gĂ©rables).
  • Limiter shards : trop = overhead, pas assez = gros index.
  • PrĂ©fĂ©rer logs JSON (moins de grok → plus de throughput).
  • PrĂ©voir nodes dĂ©diĂ©s (ingest vs data) si gros volumes.
4.3 Troubleshooting – erreurs frĂ©quentes & playbooks
SymptĂŽmes typiques
  • Kibana lent / timeouts
  • Index en read-only / flood stage disk watermark
  • Ingestion qui “drop” (perte events)
  • Mapping explosion (trop de champs)
  • Logstash CPU 100% (grok lourd)
Causes fréquentes
CauseEffet
Disque pleinES bloque writes (read-only)
Trop de shardscluster overhead énorme
Grok trop complexeingestion lente
Champs dynamiquesmapping explosion
Fix rapides (pragmatiques)
  • Activer ILM + rĂ©duire rĂ©tention (si disque).
  • RĂ©duire shards + rollover (indices plus petits).
  • Passer vers logs JSON pour rĂ©duire grok.
  • Limiter champs dynamiques (templates).
Playbook incident ELK
  1. Réduire time range + filtre service/env.
  2. Checker disque + watermark.
  3. Observer ingestion rate (agents/logstash).
  4. Identifier index “heavy” (trop gros / trop shards).
  5. Appliquer ILM / rollover / delete policy.
5.1 Cheat-sheet ELK – rùgles d’or, checklists & commandes utiles
Rùgles d’or
1) Logs JSON si possible (moins de grok)
2) ILM (rollover + delete) dÚs le début
3) Pas d'ES exposé publiquement
4) Shards raisonnables (éviter l'explosion)
5) Champs standards: service/env/@timestamp/request_id
          
Checklist “Go Live”
  • RĂ©tention configurĂ©e (jours)
  • Dashboards incident (5xx, latency, top endpoints)
  • RBAC (viewer vs admin)
  • Alertes simples (5xx rate, latency)
  • Backup snapshots (si requis)
Commandes “concept” (tests)
# Test ES
curl -s http://localhost:9200

# Lister indices (cat)
curl -s "http://localhost:9200/_cat/indices?v"

# Health cluster
curl -s "http://localhost:9200/_cluster/health?pretty"

# Kibana
http://localhost:5601
          
Anti-patterns
  • Pas d’ILM → disque plein
  • Grok partout → CPU Logstash explose
  • Logs non structurĂ©s sans conventions
  • Champs dynamiques incontrĂŽlĂ©s
Si tu veux, je te fais une “modal bonus” : ELK pour IDEO-Lab (Nginx + Gunicorn + Django) avec une convention de logs JSON + dashboards prĂȘts Ă  reproduire.