3 # if this chart is called X.chart.sh, then all functions and global variables
6 nginx_url="http://127.0.0.1:80/stub_status"
8 # _update_every is a special variable - it holds the number of seconds
9 # between the calls of the _update() function
13 declare -a nginx_response=()
14 nginx_active_connections=0
22 nginx_response=($(curl -Ss "${nginx_url}"))
23 [ $? -ne 0 -o "${#nginx_response[@]}" -eq 0 ] && return 1
25 if [ "${nginx_response[0]}" != "Active" \
26 -o "${nginx_response[1]}" != "connections:" \
27 -o "${nginx_response[3]}" != "server" \
28 -o "${nginx_response[4]}" != "accepts" \
29 -o "${nginx_response[5]}" != "handled" \
30 -o "${nginx_response[6]}" != "requests" \
31 -o "${nginx_response[10]}" != "Reading:" \
32 -o "${nginx_response[12]}" != "Writing:" \
33 -o "${nginx_response[14]}" != "Waiting:" \
36 echo >&2 "nginx: Invalid response from nginx server: ${nginx_response[*]}"
40 nginx_active_connections="${nginx_response[2]}"
41 nginx_accepts="${nginx_response[7]}"
42 nginx_handled="${nginx_response[8]}"
43 nginx_requests="${nginx_response[9]}"
44 nginx_reading="${nginx_response[11]}"
45 nginx_writing="${nginx_response[13]}"
46 nginx_waiting="${nginx_response[15]}"
48 if [ -z "${nginx_active_connections}" \
49 -o -z "${nginx_accepts}" \
50 -o -z "${nginx_handled}" \
51 -o -z "${nginx_requests}" \
52 -o -z "${nginx_reading}" \
53 -o -z "${nginx_writing}" \
54 -o -z "${nginx_waiting}" \
57 echo >&2 "nginx: empty values got from nginx server: ${nginx_response[*]}"
64 # _check is called once, to find out if this chart should be enabled or not
70 echo >&2 "nginx: cannot find stub_status on URL '${nginx_url}'. Please set nginx_url='http://nginx.server/stub_status' in $confd/nginx.conf"
75 # - 0 to enable the chart
76 # - 1 to disable the chart
81 # _create is called once, to create the charts
84 CHART nginx.connections '' "nginx Active Connections" "connections" nginx nginx.connections line $[nginx_priority + 1] $nginx_update_every
85 DIMENSION active '' absolute 1 1
87 CHART nginx.requests '' "nginx Requests" "requests/s" nginx nginx.requests line $[nginx_priority + 2] $nginx_update_every
88 DIMENSION requests '' incremental 1 1
90 CHART nginx.connections_status '' "nginx Active Connections by Status" "connections" nginx nginx.connections.status line $[nginx_priority + 3] $nginx_update_every
91 DIMENSION reading '' absolute 1 1
92 DIMENSION writing '' absolute 1 1
93 DIMENSION waiting idle absolute 1 1
95 CHART nginx.connect_rate '' "nginx Connections Rate" "connections/s" nginx nginx.connections.rate line $[nginx_priority + 4] $nginx_update_every
96 DIMENSION accepts accepted incremental 1 1
97 DIMENSION handled '' incremental 1 1
103 # _update is called continiously, to collect the values
105 # the first argument to this function is the microseconds since last update
106 # pass this parameter to the BEGIN statement (see bellow).
108 # do all the work to collect / calculate the values
110 # remember: KEEP IT SIMPLE AND SHORT
112 nginx_get || return 1
114 # write the result of the work.
116 BEGIN nginx.connections $1
117 SET active = $[nginx_active_connections]
119 BEGIN nginx.requests $1
120 SET requests = $[nginx_requests]
122 BEGIN nginx.connections_status $1
123 SET reading = $[nginx_reading]
124 SET writing = $[nginx_writing]
125 SET waiting = $[nginx_waiting]
127 BEGIN nginx.connect_rate $1
128 SET accepts = $[nginx_accepts]
129 SET handled = $[nginx_handled]