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개 답변
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
답변함 일 년 전
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/

답변함 8달 전
-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.

답변함 일 년 전
  • 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.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠