#90days0fdevops-Day-75: Monitoring Project: Integrating Docker containers with Grafana
Install Grafana in the EC2 instance and configure it. Follow my previous blog for detailed steps.
ln the instance install Docker and create docker images for applications.
In the above screenshot, we have created notes-app & django-cicd images.
Create two containers out of images.
Let's check the total number of containers on the server.
Let's start with the project
Configuring Telegraf
Telegraf is a powerful data collection tool that plays a crucial role in collecting and aggregating metrics and logs for monitoring, observability, and performance analysis. It provides the foundation for building scalable and efficient monitoring solutions in various environments.
Telegraf will be integrated into a database. Telegraf will collect all the docker logs then those will be inserted into the table in the database. Here we are using InfluxDB.
lnstall Telegraf on the EC2 instance through apt package.
Check if the telegraf service is running.
Configure telegraf to send to collect the docker logs by changing the telegraf configuration file.
COPY
COPY
COPY
COPY
COPY
COPY
COPY
COPY
COPY
sudo vi /etc/telegraf/telegraf.conf
Restart the telegraf service and check the status of the service.
Configuring InfluxDB
By utilizing InfluxDB as the backend storage for Telegraf, we can effectively store and analyze time series data, enabling monitoring, performance analysis, and observability of our systems and applications.
Install influxdb in the EC2 instance through ubuntu apt package.
Open the InfluxDB shell by running the following command in your terminal:
COPY
COPY
COPY
COPY
COPY
COPY
COPY
COPY
COPY
influx
Once you are in the InfluxDB shell, execute the following command to create the "telegraf" database:
COPY
COPY
COPY
COPY
COPY
COPY
COPY
COPY
COPY
CREATE DATABASE telegraf
Navigate to telegraf config file and enable the database configuration to connect telegraf to influxdb.
Restart the telegraf service to reflect the changes.
Creating Dashboard
We will create a dashboard having below data:-
Total Containers.
Running Containers.
Stopped Containers.
Images.
Containers memory.
Containers uptime.
We will start one by one from the above.
Total Containers
As the below screenshot shows, make the appropriate settings to reflect the total containers in a stat form.
Choose the data source as influxdb. Grafana will collect the data from influxdb.
In the FROM section select docker. This will configure docker to the dashboard.
In the SELECT section choose n_containers. This will show the total number of containers on the server.
We can choose the colour of the graph.
Running Containers
As the below screenshot shows, make the appropriate settings to reflect the total containers running in a stat form.
Choose the data source as influxdb. Grafana will collect the data from influxdb.
In the FROM section select docker. This will configure docker to the dashboard.
In the SELECT section choose n_containers_running. This will show the total number of containers running on the server.
A name can be given for this graph in the Panel options.
We can choose the colour of the graph.
Stopped Containers
As the below screenshot shows, make the appropriate settings to reflect the stopped containers in a stat form.
Choose the data source as influxdb. Grafana will collect the data from influxdb.
In the FROM section select docker. This will configure docker to the dashboard.
In the SELECT section choose n_containers_stopped. This will show the total number of containers running on the server.
Make the graph red and change the name of the graph.
Images
As the below screenshot shows, make the appropriate settings to reflect the total images on the server in a stat form.
Choose the data source as influxdb. Grafana will collect the data from influxdb.
In the FROM section select docker. This will configure docker to the dashboard.
In the SELECT section choose n_images. This will show the total number of containers running on the server.
Make the graph blue and change the name of the graph.
Containers memory
As the below screenshot shows, make the appropriate settings to reflect all container's memory on the server in a stat form.
Choose the data source as influxdb. Grafana will collect the data from influxdb.
In the FROM section select docker. This will configure docker to the dashboard.
In the SELECT section choose field(usage_percent) &
last(). This will show usage percentage of the containers last used according to the time set.
In GROUP_BY choose time($__interval)
tag(container_name::tag)
fill(null)
This will group all the containers an show corresponding values.
In FORMAT AS choose
Time series
ALIAS $tag_container_name
This will show the tags for the graph. The tags are nothing but the container names displayed on below the graph indicating which graph is for which container.
We can beautify the graph using below settings.
Containers uptime
As the below screenshot shows, make the appropriate settings to reflect all container's uptime on the server in a stat form.
Choose the data source as influxdb. Grafana will collect the data from influxdb.
In the FROM section select docker. This will configure docker to the dashboard.
In SELECT choose
field(uptime_ns)
last()
alias(uptime_ns)
This will display the uptime of each container currently running on the server.
In GROUP BY choose
tag(container_name::tag)
This will group all the containers to show containers uptime
In FORMAT AS choose Table to veiw the details in a tabular form.
Choose the Overrides setting in Table option. create a override and choose Field with name followed by uptime_ns. Then choose Standard options > Unit followed by nanoseconds(ns). This will show the uptime in nanoseconds.
Final Dashboard
Finally, add all the individual unit graphs and tables to the dashboard.
Our Dashboard is ready now!!!!!!!!!!!!