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-logo

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_layers

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.

consul-server01

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

consul-server02

Now lets add both the servers to the Consul service ring

consul-server01-02-join

Now lets join the client for a Consul UI

consul-client01

Lets have a look on the UI

consul-webui

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

consul-client-status

Services

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 172.17.0.115 at port 80

{
 "service":{
 "name": "apache2",
 "tags": ["server-02"],
 "address": "172.17.0.115",
 "port":80,
 "check":{
 "script" : "curl 172.17.0.115:80 >/dev/null 2>&1",
 "interval": "10s"
 }
}
}

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

{
"service":{
 "name":"gerrit",
 "tags":["server-01","gerrit"],
 "address": "172.17.0.114",
 "port": 8080,
 "check":{
 "script": "curl 172.17.0.114:8080 >/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 0.0.0.0 -ui-dir /opt/dist -join 172.17.0.115 -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

consul-client-status-apache2

Lets have a look in detail about the services

consul-client-status-indetail

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

consul-client-status-indetail-statusfails

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:

WordPress.com Logo

You are commenting using your WordPress.com 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