-
Notifications
You must be signed in to change notification settings - Fork 14
/
check_nginx.sh
executable file
·51 lines (47 loc) · 1.06 KB
/
check_nginx.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
#
# Author: Guanghongwei
# Mail: [email protected]
#
cwdir=`dirname $0`
. $cwdir/function.sh
url=${2:-http://127.0.0.1/nginx_status}
tmpfile=$tmp_dir/.$(str_md5 $url).zbx
web_code() {
/usr/bin/curl -m 10 -o $tmpfile -s -w %{http_code} $url
}
case "$1" in
code)
web_code $url
;;
active)
grep "Active" $tmpfile | awk '{ print $3 }'
;;
server)
grep -A1 "^server" $tmpfile | tail -1 | awk '{ print $1 }'
;;
accepts)
grep -A1 "^server" $tmpfile | tail -1 | awk '{ print $2 }'
;;
handled)
grep -A1 "^server" $tmpfile | tail -1 | awk '{ print $3 }'
;;
requests)
grep -A1 "^server" $tmpfile | tail -1 | awk '{ print $4 }'
;;
reading)
grep -A1 "^Reading" $tmpfile | awk '{ print $2 }'
;;
writing)
grep -A1 "^Reading" $tmpfile | awk '{ print $4 }'
;;
waiting)
grep -A1 "^Reading" $tmpfile | awk '{ print $6 }'
;;
tmpfile_md5)
tmpfile_md5
;;
*)
echo "Usage:$0 {code | active | server | accepts | handled | requests | reading | writing | waiting | tmpfile_md5 [URL]}"
;;
esac