ivan_sobolevskiy

Untitled

Aug 19th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.23 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. PREFIX='nginx'
  4. URL='nginx/nginx_status'
  5.  
  6. CURL='/usr/bin/curl'
  7. SENDER='/usr/bin/zabbix_sender'
  8. CONFIG='/etc/zabbix/zabbix_agentd.conf'
  9.  
  10. if [ ! -x ${CURL} ]
  11. then echo Seems, path to curl is incorrect or not installed. && exit 0
  12. else if [ ! -x ${SENDER} ]
  13. then echo Seems, path to zabbix_sender is incorrect or not installed. && exit 0
  14. else if [ ! -f ${CONFIG} ]
  15. then echo Seems, path to zabbix_agentd.conf is incorrect && exit 0
  16. fi fi fi
  17.  
  18.  
  19. function sendData {
  20.     local PROTOCOL=$1
  21.  
  22.     nginx_status="$(${CURL} --no-keepalive -s -m 5 ${PROTOCOL}://${URL} -w 'ping: %{time_total}')"
  23.     arr=($nginx_status)
  24.  
  25.     if [[ "${arr[7]}" =~ ([0-9]+) ]]
  26.     then
  27.     echo "\
  28.     - ${PREFIX}.accepts ${arr[7]}
  29.     - ${PREFIX}.connections.active ${arr[2]}
  30.     - ${PREFIX}.connections.reading ${arr[11]}
  31.     - ${PREFIX}.connections.waiting ${arr[15]}
  32.     - ${PREFIX}.connections.writing ${arr[13]}
  33.     - ${PREFIX}.handled ${arr[8]}
  34.     - ${PREFIX}.requests ${arr[9]}" | ${SENDER} -c ${CONFIG} -i - > /dev/null 2>&1
  35.     echo "${nginx_status}" | awk '/^ping:/ {print $2}' | sed 's/,/./'
  36.     else
  37.     echo '-0.001'
  38.     fi
  39. }
  40.  
  41. if [ $(${CURL} -s -o /dev/null -I -w "%{http_code}" http://${URL}) = "200" ];then
  42.     sendData 'http'
  43. else
  44.     sendData '-k https'
  45. fi
  46.  
  47. exit 1
Add Comment
Please, Sign In to add comment