Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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