Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cm-watanabeseigo/65d4d769c280505a13b1d1ab23803f75 to your computer and use it in GitHub Desktop.
Save cm-watanabeseigo/65d4d769c280505a13b1d1ab23803f75 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
prog=/usr/bin/mackerel-agent
conf=/etc/mackerel-agent/mackerel-agent.conf
cloudfront_host="CloudFront"
# mkr, AWSCLI インストール
yum install -y -q awscli mkr
# mackerel-agent.conf 初期化
cp /dev/null $conf
$prog init -apikey="$apikey"
# CloudFrontホスト作成
if [ "$(mkr hosts --name $cloudfront_host)" = "null" ]; then
mkr create --status standby --customIdentifier "${cloudfront_host}" "${cloudfront_host}"
fi
# CloudFront監視設定をconfに書き込み
for id in $(aws cloudfront list-distributions --query DistributionList.Items[].Id --output text)
do
echo $cloudfront_host $id
# confへ記述
cat >> $conf << EOF
[plugin.metrics.cloudfront-${id}]
custom_identifier = "${cloudfront_host}"
command = "/usr/bin/mackerel-plugin-aws-cloudfront -identifier $id -metric-key-prefix $id"
EOF
done
echo /usr/bin/mackerel-agent -apikey="$apikey" $opts
$prog $opts &
PID=$!
wait $PID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment