8000 GitHub - adeelahmedcsku/ELK-STACK-SPRINGBOOT · GitHub
[go: up one dir, main page]

Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Below is a clean, professional README.md that summarizes the full ELK + Spring Boot + Docker process, including the special Windows fix using docker cp. You can paste this directly into your repository.

📦 ELK Stack + Spring Boot Microservice (order-service)

This project demonstrates how to centralize and visualize Spring Boot application logs using the ELK stack (Elasticsearch, Logstash, Kibana, Filebeat) running in Docker.

The Spring Boot service (order-service) writes log files to a shared volume, Filebeat ships logs to Logstash, Logstash parses JSON log entries, and Elasticsearch indexes them for visualization in Kibana.

🚀 Architecture Overview order-service → log files → Filebeat → Logstash → Elasticsearch → Kibana

order-service produces JSON log files

Filebeat reads /var/log/microservices/*.log

Logstash parses and enriches log events

Elasticsearch stores log data

Kibana visualizes logs and dashboards

🧩 Project Structure (important directories) project-root/ ├─ order-service/ │ ├─ Dockerfile │ ├─ src/ │ ├─ logback-spring.xml │ └─ logs/ ← application log files (mounted volume) ├─ elk/ │ ├─ filebeat/ │ │ └─ filebeat.yml │ └─ logstash/ │ └─ pipeline/ │ └─ logstash.conf └─ docker-compose.yml

🐳 Docker Setup

  1. Build and run containers docker-compose up --build

Containers started:

order-service

filebeat

logstash

elasticsearch

kibana

📝 Logging Configuration Spring Boot (logback-spring.xml)

Logs are written to:

/var/log/microservices/order-service.log

This directory is mounted from the host:

./order-service/logs:/var/log/microservices

📄 Filebeat Configuration Normal recommended path (Linux / macOS)

In docker-compose.yml:

filebeat: image: docker.elastic.co/beats/filebeat:8.11.0 user: root environment:

  • FILEBEAT_FORCE_ENABLE=true volumes:
  • ./order-service/logs:/var/log/microservices:ro
  • ./elk/filebeat/filebeat.yml:/usr/share/filebeat/filebeat.yml:ro

Filebeat config (elk/filebeat/filebeat.yml) filebeat.inputs:

  • type: log enabled: true paths:
    • /var/log/microservices/*.log json.keys_under_root: true json.add_error_key: true fields: environment: local fields_under_root: true

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

⚠️ Windows Issue (IMPORTANT)

On Windows, Docker Desktop does not correctly mount the file:

./elk/filebeat/filebeat.yml -> /usr/share/filebeat/filebeat.yml

This causes Filebeat to start with its default config instead of ours.

✔️ Solution: Copy file manually after container starts

Start Docker normally:

docker-compose up -d

Find the Filebeat container name:

docker ps

Example container name:

elk-springboot-full-filebeat-1

Copy filebeat.yml into the container:

docker cp ./elk/filebeat/filebeat.yml elk-springboot-full-filebeat-1:/usr/share/filebeat/filebeat.yml

Restart filebeat:

docker restart elk-springboot-full-filebeat-1

✔️ Verify inside container docker exec -it elk-springboot-full-filebeat-1 bash cat /usr/share/filebeat/filebeat.yml

If you see your custom configuration → OK ✔️

📡 Logstash Pipeline

elk/logstash/pipeline/logstash.conf:

input { beats { port => 5044 } }

filter { json { source => "message" target => "json" } }

output { elasticsearch { hosts => "http://elasticsearch:9200" index => "order-service-%{+YYYY.MM.dd}" } }

🔍 Access Kibana

Open in browser:

http://localhost:5601

Create data view

Kibana → Stack Management

Data Views

Create Data View:

Name: order-service

Pattern: order-service-*

Timestamp: @timestamp

📊 Explore Logs

Go to:

Analytics → Discover

Search examples:

log.level: ERROR message: "Order" environment: local

📈 Recommended Kibana Dashboards

Error count over time (log.level)

Requests per endpoint

Top exception messages

Logs grouped by logger name

🔧 Useful Commands Restart all containers docker-compose down docker-compose up -d

View Filebeat logs docker logs elk-springboot-full-filebeat-1

View Order-Service logs inside container docker exec -it elk-springboot-full-order-service-1 bash ls -l /var/log/microservices

✔️ Checklist Task Status Spring Boot writes JSON log files ✔️ Log files mounted to container ✔️ Filebeat reads /var/log/microservices/*.log ✔️ Windows manual docker cp workaround used ✔️ Logstash pipeline running on port 5044 ✔️ Indices exist in Elasticsearch ✔️ Kibana data view created ✔️ Logs visible in Discover ✔️ 📚 What’s Next?

Add alerts (email / Slack) for high error rate

Add tracing with Elastic APM

Create dashboards

Retention + ILM policies

If you want, I can also generate: ✅ A professional GitHub CHANGELOG.md ✅ Full example dashboards export JSON ✅ ELK troubleshooting guide for Windows

Below is a clean, step-by-step Kibana Dashboard Guide you can paste into your project’s README or share with your team.

🧭 Kibana Dashboard Guide (Filebeat + Logstash + Spring Boot)

This guide explains how to explore and visualize your order-service logs in Kibana using the index pattern you created (e.g., order-service-*).

✔️ 1. Open Kibana

Go to: http://localhost:5601

Wait for Kibana to fully load (first startup might take 1–2 minutes)

✔️ 2. Create a Data View (if not already created)

Go to: Stack Management → Kibana → Data Views

Click Create data view

Enter:

Name: order-service

Index pattern: order-service-*

Select timestamp field (normally @timestamp)

Save

✔️ 3. Explore Logs in “Discover”

Go to Analytics → Discover

Select data view: order-service

You will see live logs coming from order-service.log through Filebeat → Logstash → Elasticsearch

🔍 Useful tips:

Use the top-left time picker (Last 15 min, Last 1 hour, Today, etc.)

Add fields to table:

message

logger_name

level

thread

environment (these come from your Spring Boot JSON logs)

✔️ 4. Build Visualizations Charts recommended:

📊 Log count by Level X-axis: @timestamp Split series by: level

🧯 Top error messages Type: Terms Field: message.keyword Size: 10

🏷️ Top Logger Names e.g. com.example.orderservice.controller

🚨 Error rate over time Filter: level = ERROR

✔️ 5. Create a Dashboard

Go to Analytics → Dashboard

Click New Dashboard

Add visualizations you created:

Log count over time

Error levels

Top services

Error messages

Save dashboard as Order Service Monitoring

✔️ 6. Live Log Tail (Fast Monitoring)

Kibana Discover supports live streaming:

Enable Auto-refresh (top right, choose 5 seconds or 10 seconds)

Now Kibana behaves like tail -f for JSON logs.

✔️ 7. Useful Queries Show only ERROR logs level: "ERROR"

Show WARN and ERROR level: ("WARN" OR "ERROR")

Show logs from a specific class logger_name: "com.company.order.controller"

Show logs containing a phrase message: "payment"

Show logs from staging only environment: "local"

✔️ 8. Troubleshooting (Quick Fixes) ❌ No logs in Discover?

Check Filebeat container logs:

docker logs filebeat

Check Logstash port forwarding:

netstat -ano | findstr 5044

❌ Index pattern not matching?

Run:

curl http://localhost:9200/_cat/indices?v

Look for order-service-*

❌ JSON fields missing?

Ensure logback is outputting structured JSON

✔️ 9. Recommended Dashboard Layout Top row

Total logs (metric)

Error logs (metric)

Warning logs (metric)

Last log timestamp

Middle row

Line chart: Logs over time

Line chart: ERROR vs INFO count

Bottom row

Data table: Top error messages

Data table: Top loggers

✔️ 10. Done 🎉

You now have a fully working observability stack:

Spring Boot → Logback JSON logs

Filebeat → Log shipper

Logstash → Parsing

Elasticsearch → Storage

Kibana → Monitoring & dashboards

Some important commands

docker cp ./elk/filebeat/filebeat.yml elk-springboot-full-filebeat-1:/usr/share/filebeat/filebeat.yml docker exec elk-springboot-full-filebeat-1 filebeat test config docker exec -it elk-springboot-full-filebeat-1 ls /var/log/microservices docker exec filebeat ls /var/log/microservices docker exec -it elk-springboot-full-filebeat-1 bash docker-compose up -d --build docker-compose down curl http://localhost:9200/_cat/indices?v

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0