Over a million developers have joined DZone.

AWS CloudWatch Monitoring with Grafana

DZone 's Guide to

AWS CloudWatch Monitoring with Grafana

With hybrid clouds becoming more and more popular, having a single dashboard for your infrastructure is becoming more and more important. Let's take a look at one solution that can make your life easier.

· Cloud Zone ·
Free Resource

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:

    "Version": "2012-10-17",
    "Statement": [
            "Sid": "1",
            "Effect": "Allow",
            "Action": [
            "Resource": "*"

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

yum install -y https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.0.3-1.x86_64.rpm
service grafana-server start
/sbin/chkconfig --add grafana-server

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, CPU Utilization 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.

cloud ,aws activate ,cloudwatch ,hybrid cloud ,grafana ,dashboard ,devops ,how-to

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}