之前 robbin 等人在[url='http://robbin.iteye.com/blog/307271']这里[/url]贴出了他们检测rails app log 文件里最耗费时间action的方法。因为rails环境一直在改变,我的log file文件格式跟他们的不大一样,所以就自己动手写了一个。
这个shell script能从所有的 status 200 请求里面找到最费时间的200个。
这个shell script能从所有的 status 200 请求里面找到最费时间的200个。
#!/bin/sh
# @(#) rails_request_timing.sh 1.0.0.20090610 initial release Peter.Zhang
# Read Me
# This shell script will pick up the first 200 time costly requests from rails development or probduction log.
# Usage:
# rails_request_timing.sh path/to/*/log
if [ -z $1 ] ;then
echo "Usage: rails_request_timing.sh <log filename>"
else
echo "Writing result to [ `pwd`/request_timing.log ] file..."
grep "200 OK" $1 | awk '{print "All: " $3/60000 "m [" $3/1000 "s] View: [" $5/1000 "s] DB: [" $7/1000 "s] URL: " $11 }'| sort -r | head -n 200 > request_timing.log
echo "Done."
fi