paint-brush
AWS CloudWatch Monitoring with Grafanaby@mlabouardy
16,942 reads
16,942 reads

AWS CloudWatch Monitoring with Grafana

by Mohamed LabouardyMarch 24th, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

<strong>Hybrid cloud</strong> is the new reality. Therefore, you will need a single tool, general purpose dashboard and graph composer for your global infrastructure. That’s where <strong>Grafana</strong> comes into play. Due to it’s pluggable architecture, you have access to many widgets and plugins to create interactive &amp; user-friendly dashboards. In this post, I will walk you through on how to create dashboards in Grafana to monitor in real-time your <strong>EC2</strong> instances based on metrics collected in <strong>AWS CloudWatch</strong>.

Company Mentioned

Mention Thumbnail
featured image - AWS CloudWatch Monitoring with Grafana
Mohamed Labouardy HackerNoon profile picture

Hybrid cloud is the new reality. Therefore, you will need a single tool, general purpose dashboard and graph composer for your global infrastructure. That’s where Grafana comes into play. Due to it’s pluggable architecture, you have access to many widgets and plugins to create interactive & user-friendly dashboards. In this post, I will walk you through on how to create dashboards in Grafana to monitor in real-time your EC2 instances based on metrics collected in AWS CloudWatch.

To get started, create an IAM role with the following IAM policy:

Launch an EC2 instance with the user-data script below. Make sure to associate to the instance the role we created earlier:

On the security group section, allow inbound traffic on port 3000 (Grafana Dashboard).

Once created, point your browser to the http://instance_dns_name:3000, you should see Grafana Login page (default credentials: admin/admin) :

Grafana ships with built in support for CloudWatch, so add a new data source:

Note: In case you are using an IAM Role (recommended), keep the other fields empty as above, otherwise, create a new file at _~/.aws/credentials_with your own AWS Access Key & Secret key.

Create a new dashboard, and add new graph to the panel, select AWS/EC2 as namespace, CPUUtilization as metric, and the instance id of the instance you want to monitor in the dimension field:

That’s great !

Well, instead of hard-coding the InstanceId in the query, we can use a feature in Grafana called “Query Variables“. Create a new variable to hold list of AWS supported regions :

And, create a second variable to store list of instances ids per selected AWS region:

Now, go back to your graph and update the query as below:

That’s it, go ahead and create other widgets:

Note: You can download the dashboard from GitHub.

Now you’re ready to build interactive & dynamic dashboards for your CloudWatch metrics.