Advertisement
METAJIJI

/etc/zabbix/scripts/nginx_status.sh

May 18th, 2015
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.21 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. URL='http://localhost/nginx_status'
  4. TMP='/tmp/nginx-ping.tmp'
  5. ZABBIX_SENDER='/usr/bin/env zabbix_sender'
  6. CONFIG='/etc/zabbix/zabbix_agentd.conf'
  7.  
  8. # WARNING: Correctly setup 'Hostname=' in config is REQUIRED!
  9.  
  10. #
  11. #Active connections: 94
  12. #server accepts handled requests
  13. # 653963 653963 1747934
  14. #Reading: 0 Writing: 19 Waiting: 75
  15.  
  16. (/usr/bin/env time -f %e /usr/bin/env wget --no-http-keep-alive --quiet --timeout 9 -O - $URL) 2>$TMP | \
  17. awk '/Active connections/ {active=int($NF)}
  18.        / ([0-9]+) ([0-9]+) ([0-9]+)/ {accepts=int($1); handled=int($2); requests=int($3)}
  19.        /Reading:/ {reading=int($2); writing=int($4); waiting=int($6)}
  20.        END {
  21.                print "- nginx.connections.active", active;
  22.                print "- nginx.connections.reading", reading;
  23.                print "- nginx.connections.writing", writing;
  24.                print "- nginx.connections.waiting", waiting;
  25.  
  26.                print "- nginx.accepts", accepts;
  27.                print "- nginx.handled", handled;
  28.                print "- nginx.requests", requests;
  29.        }' | $ZABBIX_SENDER \
  30.         --config $CONFIG \
  31.         --input-file - >/dev/null 2>&1
  32.  
  33. cat $TMP
  34. [ -f $TMP ] && rm $TMP
  35.  
  36. exit 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement