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
질문됨 한 달 전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
전문가
답변함 한 달 전
profile picture
전문가
검토됨 한 달 전

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

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

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

관련 콘텐츠