Last active
December 18, 2015 19:00
-
-
Save jonatw/5830089 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWS_ACCESS_KEY_ID="YOURAWSACCESSKEYID" | |
AWS_SECRET_KEY="YOURAWSSECRETKEY" | |
EC2_REGION=$(wget -q -O - http://169.254.169.254/latest/dynamic/instance-identity/document | grep region | awk -F\" '{print $4}') | |
EC2_INSTANCE_ID=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id) | |
EC2_CLOUDWATCH_NAMESPACE='WebService' | |
NGINX_CONNECTIONS=$(wget -q -O - http://127.0.0.1/nginx_status | grep 'connections' | awk '{print $3}') | |
/usr/bin/mon-put-data --region \"$EC2_REGION\" --metric-name HttpConnections --namespace \"$EC2_CLOUDWATCH_NAMESPACE\" --dimensions \"InstanceId=$EC2_INSTANCE_ID\" --value \"$NGINX_CONNECTIONS\" -I \"$AWS_ACCESS_KEY_ID\" -S \"$AWS_SECRET_KEY\" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apt-add-repository ppa:awstools-dev/awstools | |
apt-get update | |
apt-get install moncli |
使用時請注意 API request 產生的相關費用
http://aws.amazon.com/pricing/cloudwatch/
Amazon CloudWatch Custom Metrics
$0.50 per metric per month
Amazon CloudWatch API Requests
$0.01 per 1,000 Get, List, or Put requests
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
reference:
nginx show active connections => http://www.lowendguide.com/3/monitoring/nginx-show-active-connections/
awstool => http://alestic.com/2012/05/aws-command-line-packages
publish custom metric => http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/publishingMetrics.html
find region from linux cli => http://stackoverflow.com/questions/4249488/find-region-from-within-ec2-instance
why we cannot insert cloudwatch values into AWS/EC2 namespace => http://stackoverflow.com/questions/7345277/how-do-i-publish-per-instance-metrics-in-the-aws-ec2-namespace-for-amazon-cloudw