Using template variables in CloudWatch queries

    For an introduction to templating and template variables, refer to the Templating documentation.

    The CloudWatch data source provides the following queries that you can specify in the field in the Variable edit view. They allow you to fill a variable’s options list with things like region, namespaces, metric names and dimension keys/values.

    In place of region you can specify default to use the default region configured in the data source for the query, e.g. metrics(AWS/DynamoDB, default) or dimension_values(default, ..., ..., ...).

    Read more about the available dimensions in the CloudWatch Metrics and Dimensions Reference.

    Here is an example of the dimension queries which will return list of resources for individual AWS Services:

    QueryService
    dimension_values(us-east-1,AWS/ELB,RequestCount,LoadBalancerName)ELB
    dimension_values(us-east-1,AWS/ElastiCache,CPUUtilization,CacheClusterId)ElastiCache
    dimension_values(us-east-1,AWS/Redshift,CPUUtilization,ClusterIdentifier)RedShift
    dimension_values(us-east-1,AWS/RDS,CPUUtilization,DBInstanceIdentifier)RDS
    dimension_values(us-east-1,AWS/S3,BucketSizeBytes,BucketName)S3
    dimension_values(us-east-1,CWAgent,disk_used_percent,device,{“InstanceId”:”$instance_id”})CloudWatch Agent
    resource_arns(eu-west-1,elasticloadbalancing:loadbalancer,{“elasticbeanstalk:environment-name”:[“myApp-dev”,”myApp-prod”]})ELB
    resource_arns(eu-west-1,elasticloadbalancing:loadbalancer,{“Component”:[“$service”],”Environment”:[“$environment”]})ELB
    resource_arns(eu-west-1,ec2:instance,{“elasticbeanstalk:environment-name”:[“myApp-dev”,”myApp-prod”]})EC2

    Some queries accept filters in JSON format and Grafana supports the conversion of template variables to JSON.

    If env = 'production', 'staging', following query will return ARNs of EC2 instances which Environment tag is production or staging.

    The ec2_instance_attribute query takes filters in JSON format. You can specify . Note that the actual filtering takes place on Amazon’s servers, not in Grafana.

    Example ec2_instance_attribute() query

    Selecting attributes

    Only 1 attribute per instance can be returned. Any flat attribute can be selected (i.e. if the attribute has a single value and isn’t an object or array). Below is a list of available flat attributes:

    • AmiLaunchIndex
    • Architecture
    • ClientToken
    • Hypervisor
    • IamInstanceProfile
    • ImageId
    • InstanceId
    • InstanceLifecycle
    • InstanceType
    • KernelId
    • KeyName
    • LaunchTime
    • Platform
    • PrivateIpAddress
    • PublicDnsName
    • PublicIpAddress
    • RamdiskId
    • RootDeviceName
    • RootDeviceType
    • SourceDestCheck
    • SpotInstanceRequestId
    • SriovNetSupport
    • SubnetId
    • VpcId

    Tags can be selected by prepending the tag name with

    Example ec2_instance_attribute() query