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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值