现在的位置: 首页 > 综合 > 正文

如何将定制的ec2 监控报表放到 aws cloudwatch 上

2014年12月04日 ⁄ 综合 ⁄ 共 1783字 ⁄ 字号 评论关闭

You can use a simple shell script with cron on EC2 node to collect and report memory utilization to CloudWatch as custom
metrics.


First, you will need to get and configure CloudWatch command line tools.

    Download
Amazon CloudWatch command line tools from here: http://aws.amazon.com/developertools/2534


http://ec2-downloads.s3.amazonaws.com/CloudWatch-2010-08-01.zip

Set up CloudWatch command line tools: http://docs.amazonwebservices.com/AmazonCloudWatch/latest/GettingStartedGuide/SetupCLI.html


Copy, paste, and if needed adjust the following bash script.




#################################################################
File: /home/ec2-user/memreport.sh

#!/bin/bash
 
export AWS_CLOUDWATCH_HOME=/home/ec2-user/CloudWatch-1.0.12.1
export AWS_CREDENTIAL_FILE=$AWS_CLOUDWATCH_HOME/credentials
export AWS_CLOUDWATCH_URL=https://monitoring.amazonaws.com
export PATH=$AWS_CLOUDWATCH_HOME/bin:$PATH
export JAVA_HOME=/usr/lib/jvm/jre
 
# get ec2 instance id
instanceid=`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id`
 
memtotal=`free -m | grep 'Mem' | tr -s ' ' | cut -d ' ' -f 2`
memfree=`free -m | grep 'buffers/cache' | tr -s ' ' | cut -d ' ' -f 4`
let "memused=100-memfree*100/memtotal"

freeStorageSpace='df -m|grep "/dev/xvda"|tr -s ' '|cut -d ' ' -f 4' 

mon-put-data --metric-name
"FreeStorageSpace" --namespace "System/Linux" --dimensions "InstanceId=$instanceid" --value "$freeStorageSpace" --unit "Megabytes"


mon-put-data --metric-name
"FreeMemoryMBytes" --namespace "System/Linux" --dimensions "InstanceId=$instanceid" --value "$memfree" --unit "Megabytes"

 
mon-put-data --metric-name "UsedMemoryPercent" --namespace "System/Linux" --dimensions "InstanceId=$instanceid" --value
"$memused" --unit "Percent"


#################################################################


Now add invocation of this script to the crontab, e.g. call it every 5 minutes.

*/5 * * * * /home/ec2-user/memreport.sh



http://blog.sina.com.cn/s/blog_3d4a28be0100t02i.html

抱歉!评论已关闭.