ãã®ã¨ã³ããªã¯ãã¦ã£ã¼ã¯ãªã¼Fluentdã¦ã¼ã¹ã±ã¼ã¹ã¨ã³ããªãªã¬ã¼ãã¸ã®åå è¨äºã§ãã
ウィークリーFluentdユースケースエントリリレーまとめ(現在12本まで。) - iをgに変えるとorangeになることに気づいたoranieの日記
fluentd ã§ä¸çªæ軽ãªåºå plugin ã¨ããã° out_file ã§ãããpath ãæå®ããã ãã§ãã¡ã¤ã«ã«åºåã§ãã¾ããã使ãæ¹ã«æ°ãã¤ããªãã¨è½ã¨ãç©´ãããããã¨ãã話ã§ãã
ç°¡åãªä½¿ããã
ä¸çªåç´ãªä½¿ãããã¯ãã®ãããªè¨è¿°ã§ã
<match app.**> type file path /path/to/logs/app.log </match>
ãã㧠/path/to/logs/app.log ã«JSONå½¢å¼ã§åºåããã¾ãã
2012-10-27T17:55:00+09:00 app.info {"message":"info message"} 2012-10-27T17:55:00+09:00 app.error {"message":"error message"}
out_file ã®ä»æ§ã«ã¤ãã¦ã¯ tnmt ããã詳ãã解説ããã¦ãã¾ãã®ã§ããã¡ãããåç
§ãã ãããfluentdのout_fileプラグインの仕様について - hack in 3 minites
ããããã¦ã¼ã¹ã±ã¼ã¹
ã¨ããã§ããããã¦ã¼ã¹ã±ã¼ã¹ã¨ãã¦ãç¹å®ã®ã¬ãã«ã®ã¿ (error, warn, info, debug ã®ãã¡ error ã®ã¿ã¨ã)ãç¹å¥ãªå¦çãããããã¨ãããã¾ãããã
- app.error 㯠out_mail ã§ã¡ã¼ã«éä¿¡
- ãã以å¤ã® app.** ã¯ããapp.errorãå«ãã¦ããã¡ã¤ã«ã«åºå
ã¨ããå¦çããããã¨ãã¦ã以ä¸ã®ããã«ç´ ç´ã«è¨è¿°ãã¦ã¿ãã¨ã©ããªããã
<match app.error> type mail host localhost from [email protected] to [email protected] subject app error! outkeys message </match> <match app.**> type file path /path/to/logs/app.log </match>
ãã®è¨è¿°ã§ã¯ãapp.error ã®ã¿ã°ã«ããããããã°ã out_mail ã«éããã¾ãããå¾ãã® app.** ã«ã¯å°éããªãããããã¡ã¤ã«ã«ã¯ app.error ã¯è¨é²ããã¾ãããæ®å¿µã
è¤æ°ç®æã§åä¸ path ãæå®ããã¨â¦
åä¸ã®ãã°ã«å¯¾ãã¦è¤æ°åå¦çãããå ´åã®å®çªãã¿ã¼ã³ã¨ãã¦ãcopy plugin ã使ãæ¹æ³ãããã¾ããã§ã¯ãã®ããã«æ¸ãã¦ã¿ã¾ãã
<match app.error> type copy <store> type file path /path/to/logs/app.log </store> <store> type mail host localhost from [email protected] to [email protected] subject app error! outkeys message </store> </match> <match app.**> type file path /path/to/logs/app.log </match>
app.error 㯠copy ã§è¤è£½ããããã¡ã¤ã«ã¸ã®åºå㨠mail éä¿¡ãè¡ãããã®ãæå³ããè¨è¿°ã§ããããããã§åºåãã£ã¬ã¯ããªãè¦ã¦ã¿ãã¨â¦
$ ls -l -rw-rw-r-- 1 fujiwara fujiwara 12586 Oct 27 18:09 app.log.20121027.b4cd06c6c03a45069 -rw-rw-r-- 1 fujiwara fujiwara 12992 Oct 27 18:09 app.log.20121027.b4cd06c6c03be61ae
ãªãã2ãã¡ã¤ã«çæããã¦ãã¾ããout_file ã¯è¨è¿°ãã¨ã«ãã¡ã¤ã«åºåãè¡ããããåä¸ã® path ãæå®ãã¦ãå¥ãã¡ã¤ã«ã¨ãã¦åºåãããã®ã§ããããã§ã¯ãapp.error ã¨ãã以å¤ã®å 容ãå¥ãã¡ã¤ã«ã«åããã¦ãã¾ãã¾ãã
ã¾ãããã¡ã¤ã«æ«å°¾ã® .b4cd06c6... ã®é¨åã¯ãã¼ãã¼ããããã¨ãã« .0 .1 .2 ã®ããã« rename ãããã®ã§ãããåä¸ã®ãã¡ã¤ã«åã§ã®åºåè¨è¿°ãããå ´åãããç¨ã«ä»¥ä¸ã®ãããªã¨ã©ã¼ãçºçãããã¨ãããã¾ãã
error on output thread error="No such file or directory - (/path/to/logs/app.log.20121027.b4cce432670682745, /path/to/logs/app.log.20121027.b4cce432670682745)"
ãout_file 㧠åä¸ã® path ãè¤æ°ç®æã§æå®ãããã¨ã¯ã§ããªãã
ä¸è¦æ®éã«ã§ããããªã®ã§ããåé¡ãçºçãããã¿ã¼ã³ãªã®ã§ãè¦ãã¦ããã¾ãããã
éå»ã®ãã¼ã¸ã§ã³ã§ã®çµé¨ã§ç¾å¨ã®ææ°çã§ã¯åç¾ã§ããªãã£ãã®ã§ãããåä¸pathãæå®ãã¦ããå ´åã®ãã¼ãã¼ãå¦çã®ã¨ã©ã¼ã§ãfluentd ãå¦çãåæ¢ãã¦ãã¾ã£ãçµé¨ãããã¾ãã
ã§ã¯ã©ãããã°ï¼
æ¨æºã®ãã©ã°ã¤ã³ã§ã¯ããã¾ããããfluent-plugin-rewrite ã使ç¨ãã¦ã¿ã°ãæ¸ãæãã¦ãããã¨ã§å¯è½ã«ãªãã¾ãã
fluent-plugin-rewriteというプラグインを作成した #fluentd - delirious thoughts
<match app.error> type copy <store> type rewrite add_prefix filtered </store> <store> type mail # ç¥ </store> </match> <match app.**> type rewrite add_prefix filtered </match> <match filtered.app.**> type file path /path/to/logs/app.log </match>
- app.error 㯠copy ã§è¤è£½ããã
- rewrite ã«ãã£ã¦ filtered.app.error ã«ã¿ã°ãæ¸ãæãããã
- mail ã«ãã£ã¦ã¡ã¼ã«éä¿¡
- ãã以å¤ã® app.** 㯠rewrite ã«ãã£ã¦ filtered.app.error ã«ã¿ã°ãæ¸ãæãããã
- filtered.app.** ããã¡ã¤ã«ã«åºå
ã¨ããæµãã«ãªãã¾ãã
ã¾ã¨ã
ãout_file 㧠åä¸ã® path ãè¤æ°ç®æã§æå®ãããã¨ã¯ã§ãã¾ããã
åä¸ãã¡ã¤ã«ã«è¤æ°ç®æããã®è¨é²ãè¡ãããå ´åã¯ãrewrite plugin ãªã©ãå©ç¨ãã¦ã¿ã°ãæ¸ãæãã¾ããããå¥ã®ãã£ã¨ç°¡åãªæ¹æ³ããåãã®ããã¯ãæ¯éæãã¦ããã ããã°ã¨æãã¾ãï¼