LoginSignup
2
2

More than 5 years have passed since last update.

さっきまで動いていた Amazon CloudWatch Monitoring Scripts for Linux が急にお亡くなりになった件

Last updated at Posted at 2016-01-29

概要

  • mon-put-instance-data.pl が急に The Auto Scaling metrics will not be reported this time. とか言い出した
  • AMI 作り変えたときのキャッシュが原因で /var/tmp/aws-mon古いインスタンス ID が残ってた
  • /var/tmp/aws-mon/instance-id 書き換えたら直った

背景

複数台のインスタンスを AutoScaling で上げたり下げたりするとき、メモリ使用率の全台数平均とかディスク容量とかを AutoScalingGroup 単位でまとめたいって思いますよね?
そんなときどうするかって言ったらやっぱりAmazon CloudWatch Monitoring Scripts for Linuxですよね。
Windows? 知らん

事象

ミドルウェア構成に変更があったから AutoScaling 用の AMI 更新しなきゃなー、といつものようにインスタンス立ち上げて色々設定して AMI を作成して LaunchConfig 更新して、新しいインスタンスも立ち上がって無事入れ替え完了わーよかったよかった

と思った10分後、大量の INSUFFICIENT_DATA アラートがががが。
スクリーンショット 2016-01-29 19.15.24.png
※画像はイメージです

アラーム元をよく見てみると全部 AutoScaling のアラート。よもや更新した時に cron 設定消えるとかそんな馬鹿なことがと cron のログ確認してみるも動いている・・・。

こんな時は手動で走らせてみるに限るとコマンド実行してみると

# /usr/local/aws-scripts-mon/mon-put-instance-data.pl --mem-util --disk-space-util --disk-path=/ --auto-scaling=only

The Auto Scaling metrics will not be reported this time.

あれ?何故か取れていない。

試しに --auto-scaling=only 外して ASG から外してみると送信される。
IAM 変わってないから権限も問題ないはず(送信できてるし)。
--verbose オプションつけてみても HTTP レスポンスコードは 200 で何の問題もない。
しかしなぜか AutoScalingGroup としてのメトリクスが取れない。

原因が全く思い当たらないのでゆとりらしくエラーメッセージそのままで Google 先生にお問い合わせしたところいきなりジャストなトピックが。

IAM はちゃんとしてるんだよー --verbose つけてもわからないんだよーと思いながら下まで見に行ってみたら

I came across this same issue. For me the reason was that my AMI was created from an instance that also ran this monitoring script previously.

When the monitoring script runs it caches the instance_id under /var/tmp/aws-mon. One of the filters it uses when getting the auto scaling group name is the instance id. The TTL on this is 6 hours, so if your AMI has this cache, the query will use the wrong instance id for up to 6 hours after the instance is created which results in it failing to retrieve the auto scaling group name.

Hope that helps! Make sure your AMI doesn't have this cache in it.

-Avi

AMI 作る前にモニタリングスクリプト走らせてると /var/tmp/aws-mon に古いインスタンス ID キャッシュされてちゃんと動かなくなるよ。これ 6 時間生きてるから気をつけてね(笑)(ゆとり意訳)

とのこと。
/var/tmp/aws-mon/instance-id 見てみたらまさに AMI 更新のために使ってたインスタンス ID が記載されてました。
一応このファイルバックアップとって現行のインスタンス ID に書き換えて実行したところ

$ /usr/local/aws-scripts-mon/mon-put-instance-data.pl --mem-util --disk-space-util --disk-path=/ --auto-scaling=only

Successfully reported metrics to CloudWatch. Reference Id: hogehoge

やったー!

2
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2