motivate for dev and ops by mackerel

40
Motivate for Dev and Ops by mackerel @koudaiii at 2014/12/15

Upload: -

Post on 13-Jul-2015

533 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: Motivate for dev and ops by mackerel

Motivate for Dev and Ops by mackerel

@koudaiii at 2014/12/15

Page 2: Motivate for dev and ops by mackerel

Profile

id: koudaiii fullname: Kodai Sakabe

Page 3: Motivate for dev and ops by mackerel

Attention

• 小規模なWebサイト

Page 4: Motivate for dev and ops by mackerel

Agenda1. 今までの監視と行動

2. mackerel

3. fluentd

4. mackerel + fluentd

5. chef

6. LTSV

7. fluent-plugin

8. グラフの追加

9. Motivate

Page 5: Motivate for dev and ops by mackerel

今までの監視と行動• Metrics(メトリクス設定)

• Graf(メトリクス毎にWebで閲覧)

• Notification(閾値設定してアラート通知)

• Job(バッチを流したり)

Page 6: Motivate for dev and ops by mackerel

今までの監視と行動• Service Check(サービスのチェック)

• Situation Analysis(状況判断切り分け)

• Maintenance(メンテナンスページ切替)

• Announce(Webサイト、Blog、SNS、Mail、Telephone)

• Take the action(人力で対応する!)

• Patch Release(緊急リリース)

Page 7: Motivate for dev and ops by mackerel

監視っていつ使われる?

普段からガンガン分析してと言うよりは、 問題があった時に触れることが多い。 または、定例的にチェックする程度。

Page 8: Motivate for dev and ops by mackerel

mackerel

Page 9: Motivate for dev and ops by mackerel

what’s mackerel?• 貴重なエンジニアをもっと開発に集中!

• 管理/監視サーバー不要/パフォーマンス管理ツール!!

• API等のツール連携

• グラフで時系列にデータを可視化。(差分・重ねあわせ)

• サービス(Hatena-Blog)/ロール(Web/App/DB)でサーバーを整理

Page 10: Motivate for dev and ops by mackerel

mackerelhttps://mackerel.io

Page 11: Motivate for dev and ops by mackerel

fluentd

Page 12: Motivate for dev and ops by mackerel

fluentd

Build Your Unified Logging Layer

Page 13: Motivate for dev and ops by mackerel

what’s Fluentd?• ログ収集システム

• ログをJSONとして扱う

• 豊富なプラグイン

• 5000台以上のサーバー から一日あたり5TB以上、ピークタイムには秒間50,000メッセージにものぼるログを収集

Page 14: Motivate for dev and ops by mackerel

mackerel + fluentd

Page 15: Motivate for dev and ops by mackerel

AWS cloud

fluentd-plugin-mackerelfluentd-plugin-datacounter

OpsUser

Page 16: Motivate for dev and ops by mackerel

How to~

• Chef

• Logのformat変更

• fluentdのplugin

• 画面を見る

• ちょっと修正

Page 17: Motivate for dev and ops by mackerel

Chef

Page 18: Motivate for dev and ops by mackerel

chef-td-agent cookbook-mackerel-agent

Page 19: Motivate for dev and ops by mackerel

ハマったポイント• td-agentのサポートはUbuntuの場合、LTS

• Vagrantでテストする際にOpscodeのBENTO使っても動かなかったのでubuntu/trusyを利用

• mackerel-agentのapiがconfファイルに適応されない

• https://github.com/mackerelio/cookbook-mackerel-agent/pull/19 Mergeして欲しい…

Page 20: Motivate for dev and ops by mackerel

LTSV

Page 21: Motivate for dev and ops by mackerel

What’s LTSV ?• Labeled Tab-Separated Values

• テキストデータのフォーマット名

• タブ区切りで値に名前を付けただけ

• やっておくとparse しやすいのとfluentdが対応

• nginx やapacheのlogとか

Page 22: Motivate for dev and ops by mackerel

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;

Page 23: Motivate for dev and ops by mackerel

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

Page 24: Motivate for dev and ops by mackerel

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>

Page 25: Motivate for dev and ops by mackerel

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"}

Page 26: Motivate for dev and ops by mackerel

fluent-plugin

Page 27: Motivate for dev and ops by mackerel

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>

Page 28: Motivate for dev and ops by mackerel

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>

Page 29: Motivate for dev and ops by mackerel

あれ? 極端に2XX_countが増えてるのはなんでだろう?

Page 30: Motivate for dev and ops by mackerel

グラフの追加

Page 31: Motivate for dev and ops by mackerel

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>

Page 32: Motivate for dev and ops by mackerel

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>

Page 33: Motivate for dev and ops by mackerel

サービスメトリックaccessのステータスの数とrefererでどこからのリンクから来ているか把握

requestの数とか知りたい!!

Page 34: Motivate for dev and ops by mackerel

カスタムメトリックの設定 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

Page 35: Motivate for dev and ops by mackerel

カスタムメトリックの設定 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

Page 36: Motivate for dev and ops by mackerel

カスタムメトリックConnection / Connetcion Status / Requests

Page 37: Motivate for dev and ops by mackerel

Motivate(まとめ)

Page 38: Motivate for dev and ops by mackerel

監視から将来の展望を• LoadAverageがやべえええ!!!より、アクセスがやべええ!の方がテンション上がる

• 仮説を立てて、fluentdとサーバーでグラフを見比べて検証できる

• fluent-pluginで自分が書いたコードがどれくらい使われてるか

• また負荷はどうなんだろう?って気付く。

Page 39: Motivate for dev and ops by mackerel

よりOffensiveな監視へ• どちらかと言うと問題があった時に見ることが多い印象(あとは定例作業?)

• Systemの監視を行いつつ、Service状態を把握

• よりパフォーマンス管理を!

• 円グラフでServiceの特徴とかピーク時間帯がmackerelで見れたらいいなぁ(ボソ

イメージです><

before

after

Page 40: Motivate for dev and ops by mackerel

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