Skip to content
Mose edited this page Feb 19, 2014 · 4 revisions

Rails 2 logs

# extract lines for the hour from 7 to 8 am
awk '/2014-02-18 07/,/2014-02-18 08/' /srv/app/shared/log/production.log | \
  head -n -2 > 2014-02-18-07-00.log

# count return codes
grep Completed 2014-02-18-07-00.log | \
  cut -d'|' -f2 | cut -d' ' -f2 | sort | uniq -c

# count domains hits
grep '^Completed in' 2014-02-18-07-00.log | \
  cut -d'|' -f2 | cut -d'/' -f3 | sort | uniq -c | sort -rn

 # count response code per domain
grep '^Completed in' 2014-02-18-07-00.log | \
  sed 's~^[^\|]*| \([0-9]*\) .* \[https*://\([^/]*\).*$~\1 \2~' | \
  sort | uniq -c | \
  sort -rn

# format a csv stream from response per domain
grep '^Completed in' 2014-02-18-07-00.log | \
  sed 's~^[^\|]*| \([0-9]*\) .* \[https*://\(www\.\)\?\([^/]*\).*$~\1 \2~' | \
  sort | uniq -c | \
  awk '{print "2014-02-18-08-00," $1 "," $2 "," $3}'

# extract routing errors
grep "^ActionController::RoutingError" 2014-02-18-07-00.log | \
  sort | uniq -c | sort -n

# csv for routing errors
grep "^ActionController::RoutingError" 2014-02-18-07-00.log | \
  sort | uniq -c | \
  sed 's~\s*\([0-9]*\) ~2014-02-18-07-00,\1,~'
Clone this wiki locally