Monitoring Micro Services on Docker With Consul

This Topic might be interesting to the people who are looking out for an alternative to monitoring tools like Nagios,Sensu or Service Discovery tools like Etcd.


Consul Comes from a Different Idea where it serves the problem of monitoring and service discovery to keep all the services in a service ring which are in sync all the time and shows their health on a Consul UI.


Consul Works on Gossip Protocol which makes other agents or servers to get attached to the service ring and make them in to a high available cluster environment across data centers.

There is other good post to understand the list of protocols available and how they work.

There is a Better Post of this on How to implement a Consul Cluster and add services to monitor through Consul UI but this tutorial may take a step ahead in installing and creating a consul cluster on a Docker Based Infrastructure.


Consul Service Structure (5)


The Above Diagram Represents the Service Chain of a Consul on a Docker Infrastructure.

Here is the Requirement on how we first initially plan the setup

Container 1 — ubuntu 14.04 — Apache2 Service — Consul Server

Container 2 — ubuntu 14.04 — Gerrit Service — Consul Server

Container 3 — ubuntu 14.04 — Consul Web UI — Consul Client

Lets start the first consul container which runs the gerrit service internally.


We will launch another container and start bootstrapping that with the consul agent as server


Now lets add both the servers to the Consul service ring


Now lets join the client for a Consul UI


Lets have a look on the UI


To see the list of members at the CLI we use consul members command to check the list of servers attached inside a service ring



Services are something like checks on the machines to know if particular service on the machine is running or not.We can relate this mechanism as plugins for any of the monitoring tools we have presently in the market like Nagios,Sensu,Zabbix.

The DSL for writing a Service check Plugin in Cosnul is in JSON format with some defined keys and a syntax to follow.

For this example we have created a service file apache2 service which is running on at port 80

 "name": "apache2",
 "tags": ["server-02"],
 "address": "",
 "script" : "curl >/dev/null 2>&1",
 "interval": "10s"

We have created a service file for Gerrit service as well which we are running on at port 8080

 "address": "",
 "port": 8080,
 "script": "curl >/dev/null 2>&1",
 "interval": "10s"

Before making these service files available for Consul ui we need to create a folder to store these so i created a folder in /opt/services and we need to restart the client to make these service files available for the client to start checking for the services on the remote containers.

with the given below command on the client machine we can join to the service ring and also make the service checks start from the folder and files we have created

consul agent -data-dir /tmp/consul -client -ui-dir /opt/dist -join -config-dir /opt/services > consul-client-01.log 2>&1

Here is how the ui shows the Services based upon the tag which we gave in the service files


Lets have a look in detail about the services


Will Check if the services are working fine and detect if  both the services went wrong.


There are many More Options to explore in Consul like Locks ,Events,Monitor,Watch which i will be covering them in the next post.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s