Forked from odony/munin plugin for monitoring nginx request times
Created
August 8, 2018 15:41
-
-
Save cynovg/81cddbb75abc01db53231770b930139f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Setup an appropriate nginx log_format in the `http` section of your nginx config: | |
log_format main '$remote_addr $time_iso8601 "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_host" ' | |
'"$http_user_agent" "$http_x_forwarded_for" ' | |
'$request_time '; | |
# Then save the following as a munin plugin to monitor the last 5 minutes of your nginx access.log file | |
#!/bin/bash | |
#%# family=manual | |
LOGFILE=/var/log/nginx/access.log | |
[[ -e $LOGFILE ]] || exit 0 | |
case $1 in | |
config) | |
echo graph_title Nginx requests time | |
echo graph_category nginx | |
echo "avg_request_time.label Average request time (s)" | |
echo avg_request_time.warning 1 | |
echo avg_request_time.critical 3 | |
exit 0 | |
;; | |
esac | |
avg=$(cat $LOGFILE | grep -av '/longpolling' | tail -n 60000 | awk -v threshold=`date -Isec -d '5 min ago'` 'threshold < $2 { sum += $NF; n++ } END { if(n > 0) print sum/n }') | |
echo -n "avg_request_time.value " | |
echo ${avg:-0} | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment