Cloud-Watch Metric Query to select instances based on tags or particular environment instances

0

I'm trying to create alarm for multiple instances using cloud watch metric query. I have used the sample query as shown below.

SELECT MAX(CPUUtilization) FROM "AWS/EC2" GROUP BY InstanceId ORDER BY MAX() ASC LIMIT 10

I have different environments in my aws account in same region. If i use above query then its shown all instances. I want only to select particular environment instances. Is there a way to achieve it.

3 Answers
0

That's incorrect, tags are not available for filtering CloudWatch metrics insights queries. Currently the only way to filter CloudWatch metrics insights queries is to use the WHERE clause with metrics dimensions and the = or != operator.

profile pictureAWS
Jsc
answered a year ago
0

The only way I know is by setting up extra infrastructure. But AWS has something prepared for you: https://aws.amazon.com/blogs/mt/use-tags-to-create-and-maintain-amazon-cloudwatch-alarms-for-amazon-ec2-instances-part-1/

answered 8 months ago
-3

Yes, you can modify your CloudWatch metric query to select only instances belonging to a specific environment by adding a filter based on tags. Here's an example of how you can modify your query to achieve this:

SELECT MAX(CPUUtilization) FROM "AWS/EC2" WHERE Tag.Environment = 'YourEnvironment' GROUP BY InstanceId ORDER BY MAX() ASC LIMIT 10

In the above query, replace 'YourEnvironment' with the specific value of the tag key-value pair that represents your environment. By adding the WHERE clause with the appropriate tag filter, you can narrow down the instances to only those with the specified tag value.

Make sure you have applied the appropriate tags to your instances with the desired environment value. You can use the AWS Management Console, AWS CLI, or SDKs to add tags to your instances.

By adding the tag filter to your query, you'll limit the results to instances that match the specified environment, allowing you to create alarms specific to that environment.

answered a year ago
  • Hi Good Afternoon Himanshu, Thanks for answaaring...

    I tried to run the above query but It say syntax error.

  • Hey, ChatGPT answers in the exactly same wrong way. Good job.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions