Query tag data
CloudWatch metrics uses info metrics for all resources discovered while collecting data.
Joins in PromQL
If you chose to include tag data when setting up your scrape job, the info metrics will also include your tag data as labels, with a name of tag_<tag_key>
and value of <tag_value>
. You can join these info metrics to service metrics by utilizing promql’s group_left
function.
As an example, assume the following metric data from EC2 was produced:
{__name__="aws_ec2_cpuutilization_maximum", account_id="asdf", dimension_InstanceId="i-asdf", name="arn:aws:ec2:us-east-2:asdf:instance/i-asdf"}
{__name__="aws_ec2_info", name="arn:aws:ec2:us-east-2:asdf:instance/i-asdf", tag_aws_autoscaling_groupName="eks-asdf", tag_aws_eks_cluster_name="cluster-asdf", tag_eks_nodegroup_name="ng-asdf"}
You can join these two metrics together with a query that looks like the following:
aws_ec2_cpuutilization_maximum + on (name) group_left(tag_aws_eks_cluster_name, tag_eks_nodegroup_name) aws_ec2_info
This will produce an output of:
{account_id="asdf", dimension_InstanceId="i-asdf", name="arn:aws:ec2:us-east-2:asdf:instance/i-asdf", tag_aws_eks_cluster_name="cluster-asdf", tag_eks_nodegroup_name="ng-asdf"}
You can adjust the collection of tags to join by changing the values in the group left. For example, to include tag_aws_autoscaling_groupName
instead of tag_aws_eks_cluster_name
and tag_eks_nodegroup_name
, use group_left(tag_aws_autoscaling_groupName)
.