ELBのhttp_status_codeをfluentdを使って可視化してみる

前回記事の下りが長すぎるので、短くいきます!
AWS Advent Calender 24日目です!クリスマスですが、クリスマスには全く関係ありません!
途中までしか動作確認できていませんのであしからず・・・
そしてネタ的にもAWSあんまり関係な・・・

構成図はこんな感じ

やりたいことは
・fluentdでaccessログのステータスコードをカウント
・カウント結果をZabbixに放り込む
・ELBからインスタンスが外れた場合にアラートメール
※fluentdのプラグインでCloudwatchとか出来たら・・・・それ使いますw
※fluentd流行っているみたいなので波に乗っかりました・・・

となっております。

まずはWebサーバーにfluentd(td-agent)インストールとプラグインインストール。


# cat /etc/yum.repos.d/td.repo
[treasuredata]
name=TreasureData
baseurl=http://packages.treasure-data.com/redhat/$basearch
gpgcheck=0
# /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-datacounter fluent-plugin-zabbix fluent-plugin-forest

td-agentd.confを編集


# vim /etc/td-agent/td-agent.conf


type tail
format apache
path /var/log/httpd/access_log
tag apache.access
pos_file /var/log/td-agent/access_log.pos

# accessログのレスポンスコードごとにカウント

type copy

compress gzip
type file
path /var/log/td-agent/access_log


type datacounter
count_key code
aggregate all
tag count.apache.access.code
pattern1 2xx ^2\d\d$
pattern2 3xx ^3\d\d$
pattern3 4xx ^4\d\d$
pattern4 5xx ^5\d\d$

# ファイルとして保存

type copy

type file
path /var/log/td-agent/countaccess_log


type zabbix
zabbix_server ***.***.***.***
host zabbio-test
port 10051
name_key_pattern [2345]xx_count
add_key_prefix apache


上記設定後、td-agent起動


service td-agent start
chkconfig td-agent on

accesslogがこのような形に変換されます


2012-12-24T14:35:10+00:00 count.apache.access.code {"unmatched_count":0,"unmatched_rate":0.0,"unmatched_percentage":0.0,"2xx_count":2,"2xx_rate":0.03,"2xx_percentage":100.0,"3xx_count":0,"3xx_rate":0.0,"3xx_percentage":0.0,"4xx_count":0,"4xx_rate":0.0,"4xx_percentage":0.0,"5xx_count":0,"5xx_rate":0.0,"5xx_percentage":0.0}
2012-12-24T14:37:10+00:00 count.apache.access.code {"unmatched_count":0,"unmatched_rate":0.0,"unmatched_percentage":0.0,"2xx_count":2,"2xx_rate":0.03,"2xx_percentage":16.666666666666668,"3xx_count":0,"3xx_rate":0.0,"3xx_percentage":0.0,"4xx_count":10,"4xx_rate":0.16,"4xx_percentage":83.33333333333333,"5xx_count":0,"5xx_rate":0.0,"5xx_percentage":0.0}

設定完了後、Zabbixに監視項目を登録

keyは、2xx_percentageや、2xx_rateも使えるのでELBの下にぶら下がるインスタンスの生存確認等に使ってみるのもいいのではないかと思いましたー。

これで、Zabbixでhttp_status_code毎のグラフを表示したいのですが、続きは次回・・・!?