LoginSignup
3
4

More than 5 years have passed since last update.

Apache, nginxのaccess_logからHit数の多いドメインを抽出

Last updated at Posted at 2015-10-15

まず、access_logにawkを通すときに、スペースの処理をします。
非常に便利なスクリプトがありました。
http://qiita.com/richmikan@github/items/fcf457041bb3c0e60179
https://gist.github.com/richmikan/7254345
ここからスクリプト apalognorm をwgetして、~/bin/に配置します。
それからaccess_logのフォーマットにドメイン名を追加します。
apacheの場合 %v
nginxの場合 $host

httpd.conf
   #...
   LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %D %v" combined
   #...
nginx.conf
   #...
   log_format main '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $host;
   #...
cmd
wget https://gist.githubusercontent.com/richmikan/7254345/raw/50ae183eb83f3843c273705400f18d3875dcf097/apalognorm -O ~/bin/apalognorm
chmod 755 ~/bin/apalognorm
# print $11の部分はスペース区切りで数えた12番目の項目。上記access_logのフォーマットの%vが出てくるように指定
cat /var/log/apache2/access_log | ~/bin/apalognorm | awk '{print $11}'
#上のコマンドでドメイン名だけがずらずら並ぶようになれば、あとは集計&ソート
cat /var/log/apache2/access_log | ~/bin/apalognorm | awk '{print $11}' | sort | uniq | sort -r
3
4
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
3
4