ltsview â LTSVãã©ã¼ããããã£ã«ã¿ (Text::LTSV 0.03)
LTSV が行指向な Key-Value フォーマットで捗る話 - naoyaのはてなダイアリー ã§è©¦ä½ãã LTSV ã®ãã©ã¼ããã¿ãæãã®ä»æã£ãã®ã§ ltsview ã¨ããååã§ããå°ãæ©è½ãæ´ãã¦ã¿ã¾ããã
Text::LTSV ã«å梱ããå½¢ã§å ã»ã© CPAN ã« shipit ããã®ã§ãCPAN ã§åå¾å¯è½ã«ãªã£ãã cpanm Text::LTSV 㧠ltsview ãã¨ã¤ã³ã¹ãã¼ã«ãããã¯ãã§ãããªã github 㯠https://github.com/naoya/perl-Text-LTSV ã§ãã
$ cat example/example_log.ltsv time:05/Feb/2013:15:34:47 +0000 host:192.168.50.1 req:GET / HTTP/1.1 status:304 size:0 referer:- ua:Mozilla/ o) Chrome/25.0.1364.58 Safari/537.22 reqtime:0.000 uprestime:- time:05/Feb/2013:15:34:47 +0000 host:192.168.50.1 req:GET /poweredby.png HTTP/1.1 status:304 size:0 referer:http://192. 537.22 (KHTML, like Gecko) Chrome/25.0.1364.58 Safari/537.22 reqtime:0.000 uprestime:- time:05/Feb/2013:15:34:47 +0000 host:192.168.50.1 req:GET /nginx-logo.png HTTP/1.1 status:304 size:0 referer:htt eWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.58 Safari/537.22 reqtime:0.000 uprestime:- time:05/Feb/2013:15:34:47 +0000 host:192.168.50.1 req:GET /favicon.ico HTTP/
ããããè¥å¹²è¦ã¥ãã LTSV ãã©ã¼ãããã®ãã°ã
$ cat example/example_log.ltsv | ltsview --- host: 192.168.50.1 referer: '-' req: 'GET / HTTP/1.1' reqtime: 0.000 size: 0 status: 304 time: '05/Feb/2013:15:34:47 +0000' ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.58 Safari/537.22' uprestime: '-' --- host: 192.168.50.1 referer: http://192.168.50.6/ req: 'GET /poweredby.png HTTP/1.1' reqtime: 0.000 size: 0 status: 304 time: '05/Feb/2013:15:34:47 +0000' ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.58 Safari/537.22' uprestime: '-'
ã¨è¦ããã表示ãã¾ããæ¨æ¥ã®éããåºåã¯è²ã¥ããã¦è¡¨ç¤ºããã¾ãã
ã³ãã³ãã©ã¤ã³ã§ -k (--keys) ãªãã·ã§ã³ãæå®ããã¨ãæå®ãããã¼ã ããåºåãã¾ããä¾ãã°ãªã¯ã¨ã¹ãã¨ãã¹ãã ãã欲ãããªã
$ cat example/example_log.ltsv | ltsview -k req,host --- host: 192.168.50.1 req: 'GET / HTTP/1.1' --- host: 192.168.50.1 req: 'GET /poweredby.png HTTP/1.1' --- host: 192.168.50.1 req: 'GET /nginx-logo.png HTTP/1.1' --- host: 192.168.50.1 req: 'GET /favicon.ico HTTP/1.1' --- host: 192.168.50.1 req: '-'
ã¨ããã°ãããUser-Agent ã¨æéã¨ãªã¯ã¨ã¹ããªã
$ cat example/example_log.ltsv | ltsview -k ua,time,req --- req: 'GET / HTTP/1.1' time: '05/Feb/2013:15:34:47 +0000' ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.58 Safari/537.22' --- req: 'GET /poweredby.png HTTP/1.1' time: '05/Feb/2013:15:34:47 +0000' ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.58 Safari/537.22' --- req: 'GET /nginx-logo.png HTTP/1.1' time: '05/Feb/2013:15:34:47 +0000' ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.58 Safari/537.22' --- req: 'GET /favicon.ico HTTP/1.1' time: '05/Feb/2013:15:34:47 +0000' ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) A
ã§ãã
éã«ã-i (--ignore-keys) ã§æ¬²ãããªããã¼ãæå®ãããã¨ãã§ãã¾ãã
$ cat example/example_log.ltsv | ltsview -i ua,time,req,size,uprestime --- host: 192.168.50.1 referer: '-' reqtime: 0.000 status: 304 --- host: 192.168.50.1 referer: http://192.168.50.6/ reqtime: 0.000 status: 304 --- host: 192.168.50.1 referer: http://192.168.50.6/ reqtime: 0.000 status: 304 --- host: 192.168.50.1 referer: '-' reqtime: 0.000 status: 404 --- host: 192.168.50.1 referer: '-' reqtime: 0.000 status: 400
ltsview ã¯ãã£ã«ã¿ã¹ã¯ãªãããªã®ã§ããã¤ã & ãã£ã«ã¿ã§ä»ã®åºåã¨çµã¿åããããã¨ãã§ãã¾ãã
$ tail -f /var/log/access_log.ltsv | ltsview -k host,time,req
㨠tail ã¨çµã¿åããããã¨ãã§ããã
$ tail -f /var/log/access_log.ltsv | grep 'AppleWebKit' | ltsview -k host,time,req
ã¨ãå ã« grep ãæãã§ãã ltsview ã«æµãã¦ãè¯ãã§ãããããããã¯
$ cat example/example_log.ltsv | grep 'AppleWebKit' | ltsview -i ua,time,req,size,uprestime | cat -n 1 --- 2 host: 192.168.50.1 3 referer: '-' 4 reqtime: 0.000 5 status: 304 6 --- 7 host: 192.168.50.1 8 referer: http://192.168.50.6/ 9 reqtime: 0.000 10 status: 304 11 --- 12 host: 192.168.50.1 13 referer: http://192.168.50.6/ 14 reqtime: 0.000 15 status: 304 16 --- 17 host: 192.168.50.1 18 referer: '-' 19 reqtime: 0.000
ã¨è¡çªå·ãä»ä¸ãã¦ã¿ãããåºæ¥ã¾ããã
ã©ãããå©ç¨ãã ãããä»ã«ãããªãªãã·ã§ã³ã欲ãããã¿ããã®ããã£ãããªã¯ã¨ã¹ããå¾ ã¡ãã¦ã¾ã!