タイトル

Need for Answer

2015年4月1日水曜日

fluentdにHTTPヘルスチェックを返答させるのまき

(2015/04/13:RubyGem化しました)

Google Compute Engineの微妙な困りどころとして、「ロードバランサーのヘルスチェックがHTTPプロトコルかつstatus:200を返答しなくてはならない」というのがあります。

つまり『サーバーがHTTPを返答させる必要が無くても、ヘルスチェックのためにHTTPを返答させる必要がある』ということです。

…ということで、みんな大好きfluentdにヘルスチェックを返答させちゃおう!というおはなし。

方針としてはデフォルトで入っている「in_http」プラグインを使って、サブクラス化しちゃうという作戦です。

 module Fluent
  class HttpHealthCheckInput < HttpInput
    Plugin.register_input('http_healthcheck', self)
    def on_request(path_info, params)
      begin
        return ["200 OK", {'Content-type'=>'text/plain'}, ":) < Hello!"]
      end
    end
  end
end

これをfluentdに読み込ませます!念のため、既存のin_httpも動くか確認します。
 
<source>
  type http_healthcheck
  port 8889
  bind 0.0.0.0
</source>

<source>
  type http
  port 8888
  bind 0.0.0.0
  body_size_limit 32m
  keepalive_timeout 10s
</source>


チェックしてみましょう!
 
root@hoge:/etc/google-fluentd/catch-all-inputs.d# curl http://localhost:8889
:) < Hello!
root@hoge:/etc/google-fluentd/catch-all-inputs.d# curl http://localhost:8888
400 Bad Request
'json' or 'msgpack' parameter is required

0 件のコメント:

コメントを投稿