Menu
Amazon CloudWatch
Command Line Reference (API Version 2010-08-01)

Amazon CloudWatch Command Line Interface Reference

AWS provides two sets of command line tools that each support CloudWatch. This section describes the CloudWatch command line interface (CLI). For more information about downloading and installing the CLI, see Set Up the Command Line Interface.

You can also use the AWS Command Line Interface to control and automate CloudWatch on Windows, Mac, and Linux. We also offer the AWS Tools for Windows PowerShell if you prefer to script in the PowerShell environment.

CLI Examples

This section shows some examples of CLI usage.

Note

This section uses CLI for CloudWatch and Amazon EC2. For more information about the Amazon EC2 CLI, go to Getting Started with the Command Line Tools in the Amazon EC2 User Guide for Linux Instances.

  • Use the EC2 ec2-run-instances command as in the following example.

    PROMPT>ec2-run-instances ami-60a54009 -n 3
                --availability-zone us-east-1a

    Note

    If you wanted to automatically monitor all of the EC2 Instances spun up by the preceding command, you would add --monitoring. This lets you skip step 2 in this procedure.

    The command returns a unique identifier for each launched instance. You use the instance ID to manipulate the instance. This includes viewing the status of the instance, terminating the instance, and so on. Launching the instance takes a few minutes.

    RESERVATION r-237fed4a 853279305796 default
    INSTANCE i-d9add0b0 ami-60a54009 pending 0 m1.small 2009-05-14T12:38:24+0000 us-east-1a aki-a71cf9ce ari-a51cf9cc monitoring-disabled
  • Use the mon-list-metrics command to get a list of what metrics are being stored for your AWS account. For example:

    PROMPT>mon-list-metrics

    The mon-list-metrics outputs a table containing the Metric name, Namespace, and Dimension associated with each metric. For example:

    CPUUtilization       AWS/EC2  {InstanceId=i-c385b3aa}
    CPUUtilization       AWS/EC2  {ImageId=ami-11ca2d78}
    CPUUtilization       AWS/EC2  {InstanceType=m1.small}
    CPUUtilization       AWS/EC2
    DiskReadBytes        AWS/EC2  {ImageId=ami-11ca2d78}
    DiskReadBytes        AWS/EC2  {InstanceType=m1.small}
    DiskReadBytes        AWS/EC2
    DiskReadBytes        AWS/EC2  {InstanceId=i-c385b3aa}
    DiskReadOps          AWS/EC2  {InstanceId=i-c385b3aa}
    DiskReadOps          AWS/EC2  {InstanceType=m1.small}
    DiskReadOps          AWS/EC2
    DiskReadOps          AWS/EC2  {ImageId=ami-11ca2d78}
    DiskWriteBytes       AWS/EC2  {InstanceId=i-c385b3aa}
    DiskWriteBytes       AWS/EC2  {InstanceType=m1.small}
    DiskWriteBytes       AWS/EC2  {ImageId=ami-11ca2d78}
    DiskWriteBytes       AWS/EC2
    DiskWriteOps         AWS/EC2  {InstanceId=i-c385b3aa}
    DiskWriteOps         AWS/EC2  {ImageId=ami-11ca2d78}
    DiskWriteOps         AWS/EC2  {InstanceType=m1.small}
    DiskWriteOps         AWS/EC2
    NetworkIn            AWS/EC2
    NetworkIn            AWS/EC2  {InstanceId=i-c385b3aa}
    NetworkIn            AWS/EC2  {ImageId=ami-11ca2d78}
    NetworkIn            AWS/EC2  {InstanceType=m1.small}
    NetworkOut           AWS/EC2  {InstanceType=m1.small}
    NetworkOut           AWS/EC2
    NetworkOut           AWS/EC2  {ImageId=ami-11ca2d78}
    NetworkOut           AWS/EC2  {InstanceId=i-c385b3aa}
    				
  • Use the EC2 ec2-monitor-instances command as in the following example.

    PROMPT> ec2-monitor-instances i-43a4412a

    ec2-monitor-instances returns a table that contains the selected instance IDs and the current monitoring state.

    i-43a4412a monitoring-pending
  • Use the Amazon CloudWatch mon-get-stats command as in the following example.

    PROMPT> mon-get-stats CPUUtilization --start-time
                2013-05-15T00:00:00 --end-time 2013-05-16T00:00:00 --period 60 --statistics "Average" 
    --namespace "AWS/EC2" --dimensions "ImageId=ami-60a54009"

    Amazon CloudWatch returns a response similar to the following (the data has been truncated for brevity):

    2013-05-15 	22:42:00   	0.38   Percent
    2013-05-15 	22:48:00   	0.39   Percent
    2013-05-15 	22:54:00   	0.38   Percent

    Note

    Amazon CloudWatch returns the data for this function in the following order: date, time, sample, CPUUtilization, and unit.