Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Java app monitoring with ELK Stack Blog Series


$ git clone

Code run

To start the ELK stack

docker-compose up

will read the docker-compose.yml and start the ELK containers.

you can do

docker ps
to see the running containers
CONTAINER ID        IMAGE                   COMMAND                CREATED             STATUS              PORTS                                            NAMES
ab4b849bcb62        elkintrogithub_kibana   "/docker-entrypoint.   8 minutes ago       Up 39 seconds>5601/tcp                           elkintrogithub_kibana_1          
3cd9a4e56841        logstash:latest         "/docker-entrypoint.   9 minutes ago       Up 40 seconds>5000/tcp                           elkintrogithub_logstash_1        
8a199941f859        elasticsearch:latest    "/docker-entrypoint.   9 minutes ago       Up 40 seconds>9200/tcp,>9300/tcp   elkintrogithub_elasticsearch_1   

you can easily get the ip of any container - logstash, kibana, elasticsearch
docker inspect --format '{{ .NetworkSettings.IPAddress }}' container_id
so you can for ex. open the browser and open Kibana http://ip_from_above:5601

For event generation you can use provided script **** with the container name from above **docker ps** command
./ elkintrogithub_logstash_1
this does
docker run -it --link $1:logstash_host --rm --name event_generator -v ~/.m2/:/root/.m2 -v "$PWD":/usr/src/mymaven -w /usr/src/mymaven maven:3.3.3-jdk-8 mvn clean compile exec:java
so basically inside a Java docker container we invoke the **maven-exec** plugin to run the **Start.main(String args[])** as configured in [pom.xml](
    --link $1:logstash_host   -> link with the logstash container so we can reference directly in logback config 
    -v ~/.m2/:/root/.m2       -> map the user's maven directory to the one in the container so the dependencies would not have to be downloaded whenever the container is recreated

The number and type of events and is configured in the **[jobs.conf](** file:
 events {
             name:login, //defined bellow
 login {
    class : ro.fortsoft.elk.testdata.generator.event.LoginEvent
 submit {
    class : ro.fortsoft.elk.testdata.generator.event.SubmitOrderEvent
you can create and add your own event by extending **[BaseEvent](** and adding it to the list of jobs. 

#### How the events are run

The code that fires the events:

ExecutorService executorService = Executors.newFixedThreadPool(numberOfConcurrentThreads);

/** From 0->numberOfEvents we produce an Event(extends Runnable) which 
we submit to the Executor service **/
IntStream.rangeClosed(0, numberOfEvents)

//since all the jobs have been submitted we notify the pool that it can shutdown

try {
      //wait for the submitted tasks to finish, but no more 
      executorService.awaitTermination(5, TimeUnit.MINUTES);  
} catch (InterruptedException ignored) {
} finally {
     //signal the async shipping to Logstash threads to terminate

**_Executors.newFixedThreadPool(numberOfThreads)_** method which creates an ExecutorService with a pool of threads, but also as parameter an unbounded(MAX_INT) - **LinkedBlockingQueue**-.
If we submit more jobs than there are free threads in the pool, the new jobs which are held "in store" until one of the worker threads is free to take a new job from the queue. 

This means the ExecutorService can accept quickly all the submitted jobs. It's not blocking at any of the executorService.submit() call, since the **BlockingQueue** is unbounded).
IntStream.rangeClosed(0, numberOfEvents)

Since all the jobs have been submitted quite fast, we notify the pool that it can shutdown so the Main thread can eventually exit

but we need to wait for the jobs that were submitted and not yet processed - those stored in the BlockingQueue- to finish with a generous grace period

executorService.awaitTermination(5, TimeUnit.MINUTES); 

In the end, the shutdownLogger command is necessary to stop the async threads which are pushing the log events into Logstash and to close the connection


Blog entry about using the ELK Stack



No releases published


No packages published