AWS documentation for reference
http://docs.aws.amazon.com/AmazonCloudWatch/latest/cli/SetupCLI.html
1) Download CloudWatch-2010-08-01.zip and unzip in your AWS folder
2) Configure the credentials file. the template is in the unzip folder
# cd /opt/AWS/CloudWatch-1.0.20.0
# cat credential-file-path.template
AWSAccessKeyId=<access_key>
AWSSecretKey=<access_seceret_key>
3) Configure /etc/profile and set the env variables as below
export AWS_CLOUDWATCH_HOME=/opt/AWS/CloudWatch-1.0.20.0
export PATH=$PATH:$AWS_CLOUDWATCH_HOME/bin
export AWS_CREDENTIAL_FILE=$AWS_CLOUDWATCH_HOME/credential-file-path.template
export AWS_CLOUDWATCH_URL=http://monitoring.us-east-1.amazonaws.com
export JAVA_HOME=/usr
You will need the actual JAVA_HOME. To find the java folder,
# which java
/bin/java
# cd /bin/
# ls -lt java
lrwxrwxrwx. 1 root root 22 Jul 12 10:49 java -> /etc/alternatives/java
# cd /etc/alternatives/
# ls -lt java
lrwxrwxrwx. 1 root root 72 Jul 12 10:49 java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.el7_2.x86_64/jre/bin/java
Add the JRE folder path to your JAVA_HOME environment variable
# env | grep JAVA
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.el7_2.x86_64/jre
4) run the command to test your env is working or not.
# # mon-cmd
Command Name Description
------------ -----------
help
mon-delete-alarms Delete alarms
mon-describe-alarm-history Describe alarm history
mon-describe-alarms Describe alarms fully.
mon-describe-alarms-for-metric Describe all alarms associated with a single metric
mon-disable-alarm-actions Disable all actions for a given alarm
mon-enable-alarm-actions Enable all actions for a given alarm
mon-get-stats Get metric statistics
mon-list-metrics List user's metrics
mon-put-data Put metric data
mon-put-metric-alarm Create a new alarm or update an existing one
mon-set-alarm-state Manually set the state of an alarm
version Prints the version of the CLI tool and the API.
For help on a specific command, type '<commandname> --help'
# mon-get-stats CPUUtilization --start-time 2016-06-30T10:00:00.000Z --end-time 2016-06-30T21:25:00.000Z --period 60 --statistics "Average,Minimum,Maximum,SampleCount" --namespace "AWS/EC2" --dimensions "InstanceId=i-0ea22089a33d69cdd"
# mon-get-stats CPUUtilization --start-time 2016-06-30T18:00:00.000Z --end-time 2016-06-30T18:30:00.000Z --statistics "Average,Minimum,Maximum,SampleCount" --namespace "AWS/EC2" --dimensions "InstanceId=i-0f6578719a55264ee" --show-table --headers --delimiter "|" --period 600
sample output with headers
Time Samples Average Unit
2013-05-19 00:03:00 2.0 0.19 Percent
This command returns a table that contains the following:
The Amazon CloudWatch CLI displays errors on stderr.
Different AWS CW Metrics for EC2
If you need instance id for automating a code. below is the command to use
# aws ec2 describe-instances | grep InstanceId | awk '{ print $2 }'
"i-0ea22089a33d69cdd",
"i-0f6578719a55264ee",
"i-097fb8cbe37dfb658",
http://docs.aws.amazon.com/AmazonCloudWatch/latest/cli/SetupCLI.html
1) Download CloudWatch-2010-08-01.zip and unzip in your AWS folder
2) Configure the credentials file. the template is in the unzip folder
# cd /opt/AWS/CloudWatch-1.0.20.0
# cat credential-file-path.template
AWSAccessKeyId=<access_key>
AWSSecretKey=<access_seceret_key>
3) Configure /etc/profile and set the env variables as below
export AWS_CLOUDWATCH_HOME=/opt/AWS/CloudWatch-1.0.20.0
export PATH=$PATH:$AWS_CLOUDWATCH_HOME/bin
export AWS_CREDENTIAL_FILE=$AWS_CLOUDWATCH_HOME/credential-file-path.template
export AWS_CLOUDWATCH_URL=http://monitoring.us-east-1.amazonaws.com
export JAVA_HOME=/usr
You will need the actual JAVA_HOME. To find the java folder,
# which java
/bin/java
# cd /bin/
# ls -lt java
lrwxrwxrwx. 1 root root 22 Jul 12 10:49 java -> /etc/alternatives/java
# cd /etc/alternatives/
# ls -lt java
lrwxrwxrwx. 1 root root 72 Jul 12 10:49 java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.el7_2.x86_64/jre/bin/java
Add the JRE folder path to your JAVA_HOME environment variable
# env | grep JAVA
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.91-1.b14.el7_2.x86_64/jre
4) run the command to test your env is working or not.
# # mon-cmd
Command Name Description
------------ -----------
help
mon-delete-alarms Delete alarms
mon-describe-alarm-history Describe alarm history
mon-describe-alarms Describe alarms fully.
mon-describe-alarms-for-metric Describe all alarms associated with a single metric
mon-disable-alarm-actions Disable all actions for a given alarm
mon-enable-alarm-actions Enable all actions for a given alarm
mon-get-stats Get metric statistics
mon-list-metrics List user's metrics
mon-put-data Put metric data
mon-put-metric-alarm Create a new alarm or update an existing one
mon-set-alarm-state Manually set the state of an alarm
version Prints the version of the CLI tool and the API.
For help on a specific command, type '<commandname> --help'
# mon-get-stats CPUUtilization --start-time 2016-06-30T10:00:00.000Z --end-time 2016-06-30T21:25:00.000Z --period 60 --statistics "Average,Minimum,Maximum,SampleCount" --namespace "AWS/EC2" --dimensions "InstanceId=i-0ea22089a33d69cdd"
# mon-get-stats CPUUtilization --start-time 2016-06-30T18:00:00.000Z --end-time 2016-06-30T18:30:00.000Z --statistics "Average,Minimum,Maximum,SampleCount" --namespace "AWS/EC2" --dimensions "InstanceId=i-0f6578719a55264ee" --show-table --headers --delimiter "|" --period 600
sample output with headers
Time Samples Average Unit
2013-05-19 00:03:00 2.0 0.19 Percent
Output
- Time - Time the metrics were taken.
- SampleCount - No description available for this column.
- Average - Average value.
- Sum - Sum of values.
- Minimum - Minimum observed value.
- Maximum - Maximum observed value.
- Unit - Unit of the metric.
Different AWS CW Metrics for EC2
- CPUCreditUsage
- CPUCreditBalance
- CPUUtilization
- DiskReadOps
- DiskWriteOps
- DiskReadBytes
- DiskWriteBytes
- NetworkIn
- NetworkOut
- NetworkPacketsIn
- NetworkPacketsOut
- StatusCheckFailed
- StatusCheckFailed_Instance
- StatusCheckFailed_System
If you need instance id for automating a code. below is the command to use
# aws ec2 describe-instances | grep InstanceId | awk '{ print $2 }'
"i-0ea22089a33d69cdd",
"i-0f6578719a55264ee",
"i-097fb8cbe37dfb658",
No comments:
Post a Comment