0
0

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 3 years have passed since last update.

特定の文字列(日時)のアクセスログのステータスコードの数をカウントする方法

Last updated at Posted at 2021-02-08

何かデプロイをして、エラーのテストをする時、膨大な量のアクセスログの中で、特定のエラーが発生しているかどうかをカウントするシェルコマンド集

50x エラーの数をカウントする

フォーマット

grep [絞り込みたい文字列(日付)] [アクセスログ保存先] | awk '( $8 ~ /50[0-9]/ ){print$0}'

例: 2021/2/1 の /var/log/nginx/access_log のアクセスログから、500~509 エラーの数をカウントする

grep 01/Feb/2021 /var/log/nginx/access_log | awk '( $8 ~ /50[0-9]/ ){print$0}'

4xx エラーの数をカウントする

フォーマット

grep [絞り込みたい文字列(日付)] [アクセスログ保存先] | awk '( $8 ~ /4[0-9][0-9]/ ){print$0}'

例: 2021/2/1 の /var/log/nginx/access_log のアクセスログから、400~499 エラーの数をカウントする

grep 01/Feb/2021 /var/log/nginx/access_log | awk '( $8 ~ /4[0-9][0-9]/ ){print$0}'

4xx & 5xx エラーの数をカウントする

ちょっと手抜きで 50x から 5xx に変わっている

フォーマット

grep [絞り込みたい文字列(日付)] [アクセスログ保存先] | awk '( $8 ~ /[4-5][0-9][0-9]/ ){print$0}'

例: 2021/2/1 の /var/log/nginx/access_log のアクセスログから、400~499 & 500~599 エラーの数をカウントする

grep 01/Feb/2021 /var/log/nginx/access_log | awk '( $8 ~ /[4-5][0-9][0-9]/ ){print$0}'
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?