LoginSignup
1
0

More than 5 years have passed since last update.

1行でWebアクセス数(req./sec.)を求める

Last updated at Posted at 2018-03-16

スクリプト

Apache用

count_access.sh
#!/bin/sh
tail -1000 /var/log/apache2/access.log | head -1 | awk -F '[\\[\\]/:]' '{t=systime();today=mktime(strftime("%Y %m %d 00 00 00",t));tod=t-today;tod2=$5*3600+$6*60+$7;print 1000/(tod-tod2), "req/sec" }'

nginx用

count_access.sh
tail -1000 /var/log/nginx/access.log | head -1 | awk '{print $4}' | awk -F '[\\[\\]:]' '{t=systime();today=mktime(strftime("%Y %m %d 00 00 00",t));tod=t-today;tod2=$3*3600+$4*60+$5;print 1000/(tod-tod2), "req/sec" }'

使い方

$ watch -n 10 ./count_access.sh

出力例
Every 10.0s: ./count_access.sh                     Fri Mar 16 12:05:31 2018

165.837 req/sec

やっていること

1,000件前のリクエストがいつだったかを取得し、1000÷(現在時刻との差分) を表示しているだけ。

制限事項

  • 日付変更から1,000リクエストの間は間違った値(負の値)が出ます
  • log rotateから1,000リクエストの間は間違った値(本来より小さい値)が出ます
1
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
1
0