Upload
-
View
538
Download
4
Embed Size (px)
Citation preview
Motivate for Dev and Ops by mackerel
@koudaiii at 2014/12/15
Profile
id: koudaiii fullname: Kodai Sakabe
Attention
• 小規模なWebサイト
Agenda1. 今までの監視と行動
2. mackerel
3. fluentd
4. mackerel + fluentd
5. chef
6. LTSV
7. fluent-plugin
8. グラフの追加
9. Motivate
今までの監視と行動• Metrics(メトリクス設定)
• Graf(メトリクス毎にWebで閲覧)
• Notification(閾値設定してアラート通知)
• Job(バッチを流したり)
今までの監視と行動• Service Check(サービスのチェック)
• Situation Analysis(状況判断切り分け)
• Maintenance(メンテナンスページ切替)
• Announce(Webサイト、Blog、SNS、Mail、Telephone)
• Take the action(人力で対応する!)
• Patch Release(緊急リリース)
監視っていつ使われる?
普段からガンガン分析してと言うよりは、 問題があった時に触れることが多い。 または、定例的にチェックする程度。
mackerel
what’s mackerel?• 貴重なエンジニアをもっと開発に集中!
• 管理/監視サーバー不要/パフォーマンス管理ツール!!
• API等のツール連携
• グラフで時系列にデータを可視化。(差分・重ねあわせ)
• サービス(Hatena-Blog)/ロール(Web/App/DB)でサーバーを整理
mackerelhttps://mackerel.io
fluentd
fluentd
Build Your Unified Logging Layer
what’s Fluentd?• ログ収集システム
• ログをJSONとして扱う
• 豊富なプラグイン
• 5000台以上のサーバー から一日あたり5TB以上、ピークタイムには秒間50,000メッセージにものぼるログを収集
mackerel + fluentd
AWS cloud
fluentd-plugin-mackerelfluentd-plugin-datacounter
OpsUser
How to~
• Chef
• Logのformat変更
• fluentdのplugin
• 画面を見る
• ちょっと修正
Chef
chef-td-agent cookbook-mackerel-agent
ハマったポイント• td-agentのサポートはUbuntuの場合、LTS
• Vagrantでテストする際にOpscodeのBENTO使っても動かなかったのでubuntu/trusyを利用
• mackerel-agentのapiがconfファイルに適応されない
• https://github.com/mackerelio/cookbook-mackerel-agent/pull/19 Mergeして欲しい…
LTSV
What’s LTSV ?• Labeled Tab-Separated Values
• テキストデータのフォーマット名
• タブ区切りで値に名前を付けただけ
• やっておくとparse しやすいのとfluentdが対応
• nginx やapacheのlogとか
nginxのaccess_log
log_format ltsv "time:$time_local" "\thost:$remote_addr" "\tforwardedfor:$http_x_forwarded_for" "\treq:$request" "\tstatus:$status" "\tsize:$body_bytes_sent" "\treferer:$http_referer" "\tua:$http_user_agent" "\treqtime:$request_time" "\tcache:$upstream_http_x_cache" "\truntime:$upstream_http_x_runtime" “\tvhost:$host";access_log /var/log/nginx/access.log ltsv;
before after LTSV.
before$ 222.186.31.196 - - [14/Dec/2014:16:19:49 +0900] "POST / HTTP/1.1" 403 162 "-" "Mozilla/5.0" “-"!after$ time:14/Dec/2014:21:41:11 +0900 host:116.80.20.96forwardedfor:- req:GET / HTTP/1.1status:304 size:0 referer:-ua:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36reqtime:0.000 cache:-runtime:- vhost:matsuri4.doyomeki.com
fluentd in_tailの設定
<source> type tail format ltsv time_format %d/%b/%Y:%H:%M:%S %z path /var/log/nginx/access.log pos_file /var/log/nginx/access_log.pos tag access.nginx</source>
fluentdに渡すとこうなる
$ 2014-12-05T15:37:44+09:00 access.nginx{"host":"66.249.75.80","forwardedfor":"-","req":"GET / HTTP/1.1","status":"200","size":"6686","referer":"-","ua":"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)","reqtime":"0.000","cache":"-","runtime":"-","vhost":"matsuri4.doyomeki.com"}
fluent-plugin
fluent-plugin-datacounter
<match access.nginx> type datacounter count_interval 1m #間隔 count_key status #statusをcount aggregate all tag nginx.status pattern1 2xx ^2\d\d$ pattern2 3xx ^3\d\d$ pattern3 4xx ^4\d\d$ pattern4 5xx ^5\d\d$</match>
fluent-plugin-mackerel
<match ...> type mackerel api_key <投稿先オーガニゼーションのAPIキー> service <投稿先のサービス名> metrics_name http_status.${out_key} out_keys <投稿するメトリックのキー。例: 2xx_count,3xx_count,4xx_count,5xx_count></match>
あれ? 極端に2XX_countが増えてるのはなんでだろう?
グラフの追加
fluent-plugin-datacounter !修正
<match access.nginx> type copy # 追加。これがないと正しく動かない # 既存のmatchをstoreに変更、下記追加 <store> type datacounter count_interval 1m count_key referer aggregate all tag nginx.referer pattern1 facebook facebook pattern2 twitter t\.co pattern3 hoku hoku\.in </store></match>
fluent-plugin-mackerel !も修正# 新しく追加<match nginx.referer.**> type mackerel api_key <投稿先オーガニゼーションのAPIキー> service <投稿先のサービス名> metrics_name access_referer.${out_keyZ! out_keys facebook_count,twitter_count,hoku_count</match>
サービスメトリックaccessのステータスの数とrefererでどこからのリンクから来ているか把握
requestの数とか知りたい!!
カスタムメトリックの設定 nginx
$/etc/nginx/conf.d/default.confserver { listen 80; server_name localhost; ・・・・ location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; deny all; } } $ service nginx restart
カスタムメトリックの設定 mackerel-agent
$ apt-get install mackerel-agent-plugins!$ vim /etc/mackerel-agent/mackerel-agent.conf[plugin.metrics.nginx]command = "/usr/local/bin/mackerel-plugin-nginx -host localhost -port 80"!$ service mackerel-agent restart
カスタムメトリックConnection / Connetcion Status / Requests
Motivate(まとめ)
監視から将来の展望を• LoadAverageがやべえええ!!!より、アクセスがやべええ!の方がテンション上がる
• 仮説を立てて、fluentdとサーバーでグラフを見比べて検証できる
• fluent-pluginで自分が書いたコードがどれくらい使われてるか
• また負荷はどうなんだろう?って気付く。
よりOffensiveな監視へ• どちらかと言うと問題があった時に見ることが多い印象(あとは定例作業?)
• Systemの監視を行いつつ、Service状態を把握
• よりパフォーマンス管理を!
• 円グラフでServiceの特徴とかピーク時間帯がmackerelで見れたらいいなぁ(ボソ
イメージです><
before
after
Reference• https://github.com/mackerelio/cookbook-mackerel-agent
• https://github.com/mackerelio/cookbook-mackerel-agent/pull/19
• https://github.com/treasure-data/chef-td-agent
• http://www.rubydoc.info/gems/fluent-plugin-datacounter/
• https://github.com/tksmd/fluent-plugin-mackerel
• http://qiita.com/tksmd/items/1212331a5a18afe520df
• http://d.hatena.ne.jp/naoya/20130209/1360381374
• http://help-ja.mackerel.io/entry/advanced/fluentd
• http://qiita.com/key/items/038b7913b3bb0298c625