2016-10-21 04:01:34 -05:00
+++
title = "AWS CloudWatch"
description = "Guide for using CloudWatch in Grafana"
keywords = ["grafana", "cloudwatch", "guide"]
type = "docs"
[menu.docs]
name = "AWS Cloudwatch"
identifier = "cloudwatch"
parent = "datasources"
weight = 10
+++
# Using AWS CloudWatch in Grafana
2015-10-26 08:21:38 -05:00
2015-10-26 09:41:08 -05:00
Grafana ships with built in support for CloudWatch. You just have to add it as a data source and you will
be ready to build dashboards for you CloudWatch metrics.
2015-10-26 08:21:38 -05:00
## Adding the data source
2016-10-21 04:01:34 -05:00
![](img/docs/cloudwatch/cloudwatch_add.png)
2015-10-26 08:21:38 -05:00
1. Open the side menu by clicking the the Grafana icon in the top header.
2. In the side menu under the `Dashboards` link you should find a link named `Data Sources` .
> NOTE: If this link is missing in the side menu it means that your current user does not have the `Admin` role for the current organization.
3. Click the `Add new` link in the top header.
2015-10-26 09:41:08 -05:00
4. Select `CloudWatch` from the dropdown.
2016-10-24 04:05:16 -05:00
> NOTE: If at any moment you have issues with getting this datasource to work and grafana is giving you undescriptive errors then dont forget to check your log file (try looking in /var/log/grafana/).
2015-10-26 08:21:38 -05:00
Name | Description
------------ | -------------
Name | The data source name, important that this is the same as in Grafana v1.x if you plan to import old dashboards.
Default | Default data source means that it will be pre-selected for new panels.
2015-10-29 06:22:01 -05:00
Credentials profile name | Specify the name of the profile to use (if you use `~/aws/credentials` file), leave blank for default. This option was introduced in Grafana 2.5.1
Default Region | Used in query editor to set region (can be changed on per query basis)
2016-05-18 06:27:19 -05:00
Custom Metrics namespace | Specify the CloudWatch namespace of Custom metrics
Assume Role Arn | Specify the ARN of the role to assume
2015-10-26 08:21:38 -05:00
2015-10-26 09:41:08 -05:00
## Authentication
### IAM Roles
2015-10-26 23:02:04 -05:00
Currently all access to CloudWatch is done server side by the Grafana backend using the official AWS SDK. If you grafana
2015-10-26 09:41:08 -05:00
server is running on AWS you can use IAM Roles and authentication will be handled automatically.
2016-03-02 22:33:52 -06:00
Checkout AWS docs on [IAM Roles ](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html )
2015-10-26 09:41:08 -05:00
### AWS credentials file
Create a file at `~/.aws/credentials` . That is the `HOME` path for user running grafana-server.
2016-10-24 04:05:16 -05:00
> NOTE: If you think you have the credentials file in the right place but it is still not working then you might try moving your .aws file to '/usr/share/grafana/' and make sure your credentials file has at most 0644 permissions.
2015-10-26 09:41:08 -05:00
Example content:
[default]
aws_access_key_id = asdsadasdasdasd
aws_secret_access_key = dasdasdsadasdasdasdsa
region = us-west-2
2015-10-26 09:51:34 -05:00
## Metric Query Editor
2015-10-26 09:41:08 -05:00
2016-10-21 04:01:34 -05:00
![](img/docs/cloudwatch/query_editor.png)
2015-10-26 09:41:08 -05:00
You need to specify a namespace, metric, at least one stat, and at least one dimension.
2015-10-29 09:46:10 -05:00
## Templated queries
CloudWatch Datasource Plugin provides the following functions in `Variables values query` field in Templating Editor to query `region` , `namespaces` , `metric names` and `dimension keys/values` on the CloudWatch.
Name | Description
------- | --------
`regions()` | Returns a list of regions AWS provides their service.
`namespaces()` | Returns a list of namespaces CloudWatch support.
`metrics(namespace)` | Returns a list of metrics in the namespace.
`dimension_keys(namespace)` | Returns a list of dimension keys in the namespace.
2015-12-03 10:04:50 -06:00
`dimension_values(region, namespace, metric, dimension_key)` | Returns a list of dimension values matching the specified `region` , `namespace` , `metric` and `dimension_key` .
2016-03-11 03:14:29 -06:00
`ebs_volume_ids(region, instance_id)` | Returns a list of volume id matching the specified `region` , `instance_id` .
`ec2_instance_attribute(region, attribute_name, filters)` | Returns a list of attribute matching the specified `region` , `attribute_name` , `filters` .
2015-10-29 09:46:10 -05:00
For details about the metrics CloudWatch provides, please refer to the [CloudWatch documentation ](https://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CW_Support_For_AWS.html ).
2016-03-27 19:20:33 -05:00
## Example templated Queries
Example dimension queries which will return list of resources for individual AWS Services:
Service | Query
------- | -----
2016-09-02 13:49:28 -05:00
ELB | `dimension_values(us-east-1,AWS/ELB,RequestCount,LoadBalancerName)`
2016-03-27 19:20:33 -05:00
ElastiCache | `dimension_values(us-east-1,AWS/ElastiCache,CPUUtilization,CacheClusterId)`
RedShift | `dimension_values(us-east-1,AWS/Redshift,CPUUtilization,ClusterIdentifier)`
RDS | `dimension_values(us-east-1,AWS/RDS,CPUUtilization,DBInstanceIdentifier)`
S3 | `dimension_values(us-east-1,AWS/S3,BucketSizeBytes,BucketName)`
## ec2_instance_attribute JSON filters
The `ec2_instance_attribute` query take `filters` in JSON format.
You can specify [pre-defined filters of ec2:DescribeInstances ](http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html ).
2016-03-11 03:14:29 -06:00
Specify like `{ filter_name1: [ filter_value1 ], filter_name2: [ filter_value2 ] }`
Example `ec2_instance_attribute()` query
ec2_instance_attribute(us-east-1, InstanceId, { "tag:Environment": [ "production" ] })
2016-10-21 04:01:34 -05:00
![](img/docs/v2/cloudwatch_templating.png)
2015-10-26 09:41:08 -05:00
2015-10-26 09:51:34 -05:00
## Cost
2015-10-26 09:41:08 -05:00
2016-06-12 10:37:07 -05:00
Amazon provides 1 million CloudWatch API requests each month at no additional charge. Past this,
it costs $0.01 per 1,000 GetMetricStatistics or ListMetrics requests. For each query Grafana will
2015-10-26 23:02:04 -05:00
issue a GetMetricStatistics request and every time you pick a dimension in the query editor
2015-10-26 09:41:08 -05:00
Grafana will issue a ListMetrics request.
2015-10-26 08:21:38 -05:00