Last active
September 6, 2023 01:53
-
-
Save sphinxid/2a3c8136b95c756e66d1d54a0466bfde to your computer and use it in GitHub Desktop.
This bash script is to help count request per seconds (rps) of nginx access log. (method: tailing the streamed file logs)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# sphinxid <[email protected]> | |
# | |
# Example: ./count_per_second_nginx_log.sh /var/log/nginx/*.log | |
# | |
RAND_STR=`cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1` | |
INTERVAL=10 #seconds | |
LOG_FILES=$1 | |
TMP_FILE="/tmp/$RAND_STR.log" | |
BASEVAL=`tail -q -n0 -F $LOG_FILES > $TMP_FILE & sleep $INTERVAL; kill $! ; wc -l $TMP_FILE | cut -f1 -d " " && rm -f $TMP_FILE` | |
REALVAL=$((($BASEVAL / $INTERVAL) + ($BASEVAL % $INTERVAL > 0))) | |
echo $REALVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment