Professional Documents
Culture Documents
Table of Contents
Grafana and AWS - Implementation and Usage ....................................................................... 1
What is Grafana?......................................................................................................................... 2
Exploring metrics and logs ......................................................................................................... 2
Grafana Implementation ............................................................................................................. 2
Adding AWS CloudWatch as Datasource in Grafana ................................................................ 4
Grafana Dashboard for Amazon AWS ECS ............................................................................... 7
Importing the Amazon AWS ECS Dashboard in Grafana.......................................................... 7
Adding load on SampleApp-Web service................................................................................. 10
Grafana Dashboard for AWS Cloudwatch Data ....................................................................... 11
Grafana CloudWatch Logs Insights Custom Queries ............................................................... 14
Grafana in Production ............................................................................................................... 16
Conclusion ................................................................................................................................ 17
References ................................................................................................................................. 17
What is Grafana?
Grafana is an open source visualization and analytics software. It allows you to query, alert,
visualize, and explore your metrics no matter where they are stored. It provides you with the
tools to turn your time-series database (TSDB) data into beautiful graphs and visualizations.
Grafana Implementation
Though there are several methods of implementing Grafana, we shall broadly look into its
installation and usage on:
Linux
AWS
Docker
Implementing Grafana is relatively simple and involves few steps in the installation. Its usage is
rather complex and can involve several steps to accomplish stages from data collection, data
sources, database connections and finally querying and visualizations.
For Linux, visit Install Grafana webpage covers the most popular Linux distributions like
CentOS, Fedora, OpenSuse, RedHat and others.
For AWS, one can follow Amazon Managed Service for Grafana and Grafana Integration with
CloudWatch sections.
For Docker, it is also given on the link above in “Install Grafana” for Linux.
Grafana is only for visualizations and requires a database connection to fetch data to display
several types of graphs. There are several exercises available for monitoring and visualization.
Following are a few images taken from such exercises carried out for Grafana implementation.
|
Figure: Grafana dashboard connected to influxDB
version: '3'
services:
grafana:
image: grafana/grafana
container_name: grafana
networks:
- grafana
environment:
- GF_PATHS_DATA=/var/lib/grafana
ports:
- 3000:3000
volumes:
- ./data:/var/lib/grafana
networks:
grafana: {}
# docker-compose up -d
Creating grafana ... done
After adding the Cloudwatch datasource, we can now get data from Amazon AWS ECS as has
been configured in the last few steps.
Grafana Dashboard for Amazon AWS ECS
Many Grafana Dashboards are readily available here https://grafana.com/grafana/dashboards that
can be imported inside the Grafana user interface to perform specific analytics operations and
visualizations.
Source: https://grafana.com/grafana/dashboards/551
Figure: Provide the Dashboard number, here which is 551 for AWS ECS
Figure: Verify the dashboard being imported
Run the script. It will run the commands in batch mode, just to make the test run continuously for
long enough.
Document Path: /
Document Length: 3032 bytes
Figure: On the top right, change interval to Last 5 minutes and refresh rate to 5 seconds
Figure: The load started at 15:44 as per this graph
Figure: CPU utilisation starts linearly, becomes constant and decreases in 3 minutes
Figure: Graph after Changing interval to Last 1 hour on top right
After we are done with the Grafana’s testing of metrics and visualisation, it may be desirable to
stop the container service.
This will also close the ports open for public access.
Using the same Cloudwatch Data Source in Grafana UI open the explore window on the left side
tool bar, and browse Cloud Watch logs.
Run the Grafana CloudWatch Logs Insights Query as given below for SampleApp-API Logs
Group :
Figure: Custom CloudWatch Logs Insights Query for SampleApp-API Logs Group
The query here is to extract all lines in the logs with a “WARN“ message and display the time on
the graph when the log message was generated.
Grafana in Production
Grafana can be setup in production by following any of the methods of implementation as given
in the beginning of this article. Once you set it up, considering that we are using the
example.com domain with SSL, Grafana will be available on the following URL:
Conclusion
Grafana is flexible to provide a wide variety of visualizations using data from several types of
sources. Activities on Grafana is a continuous process and we are likely to see more action with
this tool in future.
References
Grafana documentation
https://grafana.com/docs/grafana/latest