LoginSignup
17
16

More than 5 years have passed since last update.

awkで簡易アクセスログ解析

Last updated at Posted at 2016-02-09

障害調査対応時に使ってみた。
今までExcelとかで集計してたから多少は早くなりそう。

材料(必要な物)

  • awkコマンド。
  • sortコマンド。
  • uniqコマンド。

想定

apacheのLogFormatは以下を想定。

  • 第一フィールドにSorceIPが出力される想定。
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

SourceIP毎に一時間あたり何回アクセスがあったか抽出する。

# awk '{print $1}' /var/log/httpd/access_log |sort |uniq -c |sort |awk '{print $1/3600, "From:"$2"/hour"}'

実行結果。

# awk '{print $1}' /var/log/httpd/access_log |sort |uniq -c |sort |awk '{print $1/3600, "From:"$2"/hour"}'
0.000277778 From:104.131.170.117/hour
0.000277778 From:104.131.187.65/hour
0.000277778 From:104.236.72.31/hour
0.000277778 From:109.234.34.82/hour
0.000277778 From:141.212.122.81/hour
0.000277778 From:142.54.169.164/hour
0.000277778 From:157.55.39.109/hour
0.000277778 From:162.222.227.163/hour
0.000277778 From:180.76.15.11/hour
0.000277778 From:180.76.15.14/hour
0.000277778 From:180.76.15.140/hour
17
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
16