one line log parser

原创文章,转载请注明来源并保留原文链接

ruby-one-liners

ruby global variables

log文件形如:

method=GET path=/v1/foods/near_by_want1 format=html controller=api/v1/foods action=near_by_want status=200 duration=2005.69 view=0.20
method=GET path=/v1/foods/near_by_want2 format=html controller=api/v1/foods action=near_by_want status=200 duration=2005.69 view=0.20
method=GET path=/v1/foods/near_by_want3 format=html controller=api/v1/foods action=near_by_want status=200 duration=2005.69 view=0.20
method=GET path=/v1/foods/near_by_want  format=html controller=api/v1/foods action=near_by_want status=200 duration=2005.69 view=0.20
method=GET path=/v1/foods/near_by_want4 format=html controller=api/v1/foods action=near_by_want status=200 duration=2005.69 view=0.20
method=GET path=/v1/foods/near_by_want  format=html controller=api/v1/foods action=near_by_want status=200 duration=2005.69 view=0.20

得到near_by_want的平均处理时间

grep 'near_by_want' production.log-20130827 | awk '{print $7}' | ruby -n -e '@sum ||= 0; $_ =~ /^duration=(.+)/; @sum += $1.to_f; END { puts @sum / $. }'

Leave a Reply

Your email address will not be published. Required fields are marked *