DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • Using Kong Ingress Controller with Spring Boot Services
  • Component Tests for Spring Cloud Microservices
  • Migration of Microservice Applications From WebLogic to Openshift

Trending

  • My LLM Journey as a Software Engineer Exploring a New Domain
  • Unlocking the Benefits of a Private API in AWS API Gateway
  • Understanding and Mitigating IP Spoofing Attacks
  • MySQL to PostgreSQL Database Migration: A Practical Case Study
  1. DZone
  2. Coding
  3. Frameworks
  4. Setting Up the ELK Stack With Spring Boot Microservices

Setting Up the ELK Stack With Spring Boot Microservices

Learn about the ELK monitoring and logging stack and how to collate logs for multiple microservices in one location.

By 
Joydip Kumar user avatar
Joydip Kumar
·
Sep. 29, 18 · Tutorial
Likes (23)
Comment
Save
Tweet
Share
49.4K Views

Join the DZone community and get the full member experience.

Join For Free

One of the important phases in IT is the post-production phase, and one of the major challenges is to identify issues in post-production. When multiple applications spit out different logs in different systems, it is important to collate them in one place for the IT team to manage. Here, the ELK stack comes to the rescue. In this tutorial, I will cover what ELK is and how to aggregate the logs from different microservices and push them to one common location.

What Is ELK?

ELK is an acronym for Elasticsearch, Logstash, and Kibana. It is an open-source software owned by Elastic.

Elasticsearch is an Apache Lucene-based search engine which searches, stores, and analyzes huge volumes of data in almost real time. Elasticsearch can be installed on-premise or can be used as a SaaS application.

Logstash is the log aggregator, which has a pipeline to take the input, filter the data, and send the output. Logstash can take logs from various sources using different input plugins and send the output in a desired manner.

Kibana is a software to visualize the Elasticsearch data. It comes as a plugin with Elasticsearch. Elasticsearch and Kibana can be deployed as a cloud service and hosted on AWS or GCP. Kibana can also be installed in on-premise infrastructure. In this tutorial, we will use the Docker image of ELK and set it up in EC2.

Design Architecture:

Capture

In the above design, different microservices will be spitting out logs. We will have the Syslog driver to push the logs generated from different microservices to Logstash, which will filter the logs and push them to Elasticsearch. All the aggregated logs will be visible in Kibana.

Setting Up ELK on EC2

We will be setting up ELK on an EC2 Ubuntu machine using the official Docker images. Log in to EC2 server and create a directory called "elk" in the path /home/ubuntu/.

Install Docker on EC2 by following the steps mentioned here.

Navigate into the "elk" directory and create a file called docker-compose.yml

version: '2'
services:
    elasticsearch:
        image: docker.elastic.co/elasticsearch/elasticsearch:6.3.2
        ports:
            - '9200:9200'
            - '9300:9300'
    kibana:
        image: docker.elastic.co/kibana/kibana:6.3.2
        ports:
            - '5601:5601'
        depends_on:
            -  elasticsearch
    logstash:
        image: docker.elastic.co/logstash/logstash:6.3.2
        ports:
            - '25826:25826'
        volumes:
            - $PWD/elk-config:/elk-config
        command: logstash -f /elk-config/logstash.config
        depends_on:
            -  elasticsearch

Elasticsearch uses a mmapfs directory by default to store its indices. The default operating system limits on mmap counts is likely to be too low, which may result in out of memory exceptions.

On Linux, you can increase the limits by running the following command as root to allocate maximum memory:

sudo sysctl -w vm.max_map_count=262144

Run docker-compose up to spin up all the containers of ELK.

Validate whether Kibana is up by hitting port 5601. You should see the below page:

Untitled

Set up the index pattern in Kibana.

Run telnet [IP of logstash] [port of logstash] and enter any text (e.g. telnet 52.207.254.8 25826)

Once you can see the text in Kibana, that means the connectivity is set for ELK.

Next, we will see how we can push logs from microservices to ELK.

Set Up the Syslog Driver

In order to send the logs from the microservices hosted in EC2, we can use syslog driver to push the logs to Logstash. I am using this project for the logs. We will be running this project in EC2.

We need to make a change in rsyslog.conf present in the Ubuntu machine.

vi /etc/rsyslog.conf

Uncomment the below lines:

Image title

Now add the below lines in logback.xml of the spring boot project:

<appender name=”SYSLOG” class=”ch.qos.logback.classic.net.SyslogAppender”>
	<syslogHost>{logstash host }</syslogHost>
	<port>{ logstash port 25826 }</port>
	<facility>LOCAL1</facility>
	<suffixPattern>[%thread] %logger %msg</suffixPattern>
</appender>

The above setup will push the logs to Logstash.

If the project is built using Docker, then we need to add the drivers with the docker run command:

 –log-driver syslog –log-opt syslog-address=tcp://{logstashhost}:{logstashport}

On starting the server and hitting the API, you can see the logs in Kibana.

Image title

All the best!

Spring Framework microservice Spring Boot

Published at DZone with permission of Joydip Kumar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • Using Kong Ingress Controller with Spring Boot Services
  • Component Tests for Spring Cloud Microservices
  • Migration of Microservice Applications From WebLogic to Openshift

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!