0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

今更ながらgoaccessでnginxのログ解析をしてみたのでメモ

Posted at

やりたかったこと

  • alpでnginxのアクセスログを解析したかった・・・がltsvになってなくてできなかった

やったこと

  • goaccess でログ解析して、レポートとかもきれいに出せた

やりかた

インストール

簡単かつ一撃。

brew install goaccess

rcファイルを作る

当該nginxサーバーは自分が立ち上げたものではないのだが、おそらくログ設定とかデフォルトと思われる。
それに合わせる場合のgoaccessのrcファイルの一例は以下。

% cat ~/.goaccessrc
time-format %T
date-format %F
log-format %h - %^ [ %dT%t+00:00 ] "%r" %s %b "%^" "%T" "%^"

このtime-format, data-formatに何が書けるかは、 man strftime とかすれば出てくる。
goaccessとしての変数補完は、 このあたり に書いてある。

実行

イメージはこんな感じ。

% cat *access.log* > report.html
% open report.html

htmlへの標準入力に、実際にaccess.logのどの部分を食わせるかは前段のコマンドとかで制御しちゃえば良いような気がする。
一応staticアクセスとか、404なアクセスはレポート内部で分類してくれるっぽかった。

こんな感じでgoaccessのページに有るようなレポートがきれいに表示されたので目的達成。

ということで備忘録でした。

0
2
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?