How do I check to see if the CloudWatch agent has been installed on any given instance using the CLI?

0

This would have been a cinch using the mon-version [https://docs.aws.amazon.com/AmazonCloudWatch/latest/cli/cli-mon-cmd.html#w2aab9c11b9] command, but it's no longer supported.

I have a script in place to loop through all the instances in all my accounts, but I have no easy way to verify whether or not the CloudWatch agent is running on any of them.

What is the best way to do that?

Jonny
已提問 1 個月前檢視次數 667 次
1 個回答
1
已接受的答案

you can adopt several approaches depending on the specific details of your environment, such as the operating systems of the instances and whether you're using AWS Systems Manager. Here are a couple of methods that might fit your needs:

  • Ensure AWS Systems Manager (SSM) Agent is installed on your instances.
  • Verify instances have IAM roles with permissions for Systems Manager.
  • Use AWS CLI with SSM send-command for checking CloudWatch agent status:
    • Linux: aws ssm send-command --document-name "AWS-RunShellScript" --targets "Key=instanceids,Values=<instance-id>" --parameters commands="sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status" --output text
    • Windows: aws ssm send-command --document-name "AWS-RunPowerShellScript" --targets "Key=instanceids,Values=<instance-id>" --parameters commands="& 'C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1' -m ec2 -a status" --output text
  • Alternatively, directly access instances via SSH (Linux) or Remote PowerShell (Windows) to check status:
    • Linux SSH: ssh user@instance-ip 'sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status'
    • Windows PowerShell: Invoke-Command -ComputerName instance-ip -ScriptBlock { & 'C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1' -m ec2 -a status }
  • Integrate chosen method into your existing script for automated checking across all instances.
profile picture
專家
已回答 1 個月前
profile picture
專家
已審閱 1 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南