1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWS CloudWatch にデータが反映されない

Last updated at Posted at 2019-04-10

スナップショットからボリュームを作成し、新たに作成したインスタンスにボリュームをアタッチして稼働させたところ、いつまで経っても新しいインスタンスのメトリックスが AWS CloudWatch に反映されなかった。その際に対応した内容をメモしておく。

最初に結論

CloudWatchClient.pm モジュールは、インスタンスのメタデータをローカルでキャッシュします。モニタリングスクリプトを実行しているインスタンスから AMI を作成すると、キャッシュ TTL (デフォルト: 6 時間、Auto Scaling グループでは 24 時間) 以内にこの AMI から起動したすべてのインスタンスは、元のインスタンスのインスタンス ID を使用してメトリクスを出力します。キャッシュ TTL 期間が経過した後は、スクリプトは新しいデータを取得し、モニタリングスクリプトは現在のインスタンスのインスタンス ID を使用します。これをすぐに修正するには、次のコマンドを使用してキャッシュされたデータを削除します。
Amazon EC2 Linux インスタンスのメモリとディスクのメトリクスのモニタリング - Amazon Elastic Compute Cloud

30分ぐらい右往左往して気がついたきっかけは、

  • 停止しているインスタンスのメトリックスが出力されている
  • コマンドからメトリックスを送信したところ、稼働中のインスタンスと異なるインスタンス ID が出力されている

ことに気がついたからだった。

ログインしているインスタンス ID を出力する

これは当然、正しいインスタンス ID を返す。

$ curl -s http://169.254.169.254/latest/meta-data/instance-id
i-yourinstanceid
$

CloudWatch モニタリングスクリプトを手動で実行する

コマンドの実行は成功しているが、上記の i-yourinstanceid とは異なる i-wronginstanceid が出力されていた。

$ /opt/aws-scripts-mon/mon-put-instance-data.pl --mem-util --mem-used --mem-avail --swap-util --swap-util --swap-used --disk-path=/dev/xvda --disk-space-util --disk-space-used --disk-space-avail --verbose
... Payload: {"MetricData":[{"Timestamp":1554877228,"Dimensions":[{"Value":"i-wronginstanceID","Name":"InstanceId"}] ...
Received HTTP status 200 on attempt 1

Successfully reported metrics to CloudWatch. Reference Id: 6be2c02f-5b59-11e9-93ef-71bdfa0e6067
$

メタデータのキャッシュを削除する

古いインスタンス ID のキャッシュデータを削除して、CloudWatch にメトリックスが反映されるか確認する。

$ sudo rm /var/tmp/aws-mon/wronginstance-id
1
0
0

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?