Skip to content

Instantly share code, notes, and snippets.

@wokamoto
Created May 10, 2016 03:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save wokamoto/6b0cc19abe53128db959db3b1455079c to your computer and use it in GitHub Desktop.
[AWS] カスタムメトリクスでメールキュー監視するためのやつ
#!/bin/sh
# EC2 のインスタンス ID を取得
instanceid=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
# region を取得
az=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
_length=$(echo $((${#az} - 1)))
region=$(echo ${az} | cut -c 1-${_length})
# mailq
mailq=$(mailq | grep 'Total requests' | awk '{print $3}')
aws cloudwatch put-metric-data \
--region ${region} \
--namespace "System/Linux" \
--dimensions InstanceId=${instanceid} \
--unit Count \
--metric-name "MailQueu" \
--value "$mailq"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment