LoginSignup
5
5

More than 5 years have passed since last update.

Auto Scaling 環境下でmackerelのステータスを自動更新する方法の検討

Last updated at Posted at 2014-06-27

1. したいこと

  1. サーバーが起動したら ステータスを standby にする
  2. サーバーが終了(ターミネート)されたら ステータスを poweroff にする
  3. しばらくステータスが poweroff のやつは自動的に退役する → http://qiita.com/u1tnk/items/228e9115a85cf14f019e これでよい?

2. 検討内容

/etc/init.d/mackerel-status-update

とかいうスクリプト作って、サーバー起動時に start、終了時に stop オプションで呼ばれるようにする。
こんな感じ → http://qiita.com/inouet/items/11b8338bbd0093989e97

終了時には、下記のような感じのコードが実行されるようにする。(したい)

#!/bin/bash

api_key="YOUR_API_KEY"

host_id=$(cat /var/lib/mackerel-agent/id)

curl -H "X-Api-Key: $api_key" \
     -H "Content-Type: application/json" \
     -X POST \
     -d '{"status": "poweroff"}' \
     https://mackerel.io/api/v0/hosts/$host_id/status \

chkconfig で /etc/rc6.d にシンボリックリンクはられるようにする。

3. 課題

  • 自分自身のサーバーIDを知る方法が分からないので、get_hosts でループしてるのがダサい。自分自身のサーバーIDをスマートに知りたい。
    ⇨  /var/lib/mackerel-agent/id に入っている。解決。

  • 現状、get_hosts で poweroff などのステータスのサーバーが取得できないので、これだと起動時に standbyにできない。(サーバーID知れれば解決)

  • いまいち、chkconfigのrun levelの指定方法が分かってない。 rc スクリプトの書き方も怪しいので調査

  • 一度退役にしたサーバーにまた当って再度 起動したときどうしよう。 現役復帰させる?それとも、そもそも退役させない?

5
5
3

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
5
5