Last active
June 29, 2018 01:38
-
-
Save cm-watanabeseigo/65d4d769c280505a13b1d1ab23803f75 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
#!/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