Dienstag, 22. Mai 2018

Monitor the JVM within a Docker cluster

In this post we will discuss about how to monitor the JVM (Java Virtual Machine) within a Docker Cluster.

- basic knowledge about Java and the JVM...  (I don't have the pretention to be an expert java developer :) :)  )
- basic understanding of docker and docker-compose
- basic understanding of influxDB and Grafana. (you can also use any time series database of your choice, and any other dashboard tool)

I've been involved in a project where we are building a CI/CD cloud system using docker. That means we have different components each running in docker container within a cluster orchestrated  first with docker-compose (you can have more details with this interesting post) and now we are migrating to Kubernetes  using the Openshift platform.
As component we have tools like Jenkins, Sonarqube, Graylog, Gerrit, grafana, scm, Gitlab, Selenium
Resource consumption in a cloud environment is a critical problem, it's important to know a each time which component is consuming the most memory. We will focus on the JVM Monitoring.

The JMX protocol helps to communicate with a running JVM and gather metrics related to the memory consumption.

JmxTrans is exactly what we need to connect the outside world with the JVM using the JMX protocol. That's the central tool for our monitoring system.

The architecture we will implement will look as follow:

- A docker container will contain the running JVM. It can be our Jenkins, Graylog,  or whatever
- A docker container where Jmxtrans is running, and will talk to the remote JVM
- an InfluxDB running container. InfluxDB is a Time Series Database, exactly what we need in this context. We just need a place where the collected metrics should be written. It can be the standard output :(  , statsD or whatever. Jmxtrans is so wonderful that it can output data to different systems. More details can be found on here 
- Grafana Container. Grafana is a popular dashboard tool and can easily be integrated with Time Series DB like influxDB.

To setup the cluster, we will simply use docker-compose.
The following docker-compose file must be created.

The 4 container are created and linked together.
The influxDBOutputWriter used by Tmxtrans is initialized here.

To start the magic, just clone the github repository referenced here.

just type ``` docker-compose up -d ``` to start the cluster.

You can now open grafana using the http://localhost .

First of all you have  to create a new datasource in Grafana.

After the datasource is created, you can now create your dashboard. For the proof-of-concept i've just created a simple panel graph.

For the next Post, i will just customize the grafana image to add this dashboard as default dashboard.

For those who do not have enough knowledge about InfluxDB and Grafana, here are some interesting resources.

Just enjoy your monitoring dashboards and just give some comments. :) :)