1 # no need for shebang - this file is loaded from charts.d.plugin
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"
9 # _update_every is a special variable - it holds the number of seconds
10 # between the calls of the _update() function
14 declare -a nginx_response=()
15 nginx_active_connections=0
23 nginx_response=($(curl -Ss ${nginx_curl_opts} "${nginx_url}"))
24 [ $? -ne 0 -o "${#nginx_response[@]}" -eq 0 ] && return 1
26 if [ "${nginx_response[0]}" != "Active" \
27 -o "${nginx_response[1]}" != "connections:" \
28 -o "${nginx_response[3]}" != "server" \
29 -o "${nginx_response[4]}" != "accepts" \
30 -o "${nginx_response[5]}" != "handled" \
31 -o "${nginx_response[6]}" != "requests" \
32 -o "${nginx_response[10]}" != "Reading:" \
33 -o "${nginx_response[12]}" != "Writing:" \
34 -o "${nginx_response[14]}" != "Waiting:" \
37 echo >&2 "nginx: Invalid response from nginx server: ${nginx_response[*]}"
41 nginx_active_connections="${nginx_response[2]}"
42 nginx_accepts="${nginx_response[7]}"
43 nginx_handled="${nginx_response[8]}"
44 nginx_requests="${nginx_response[9]}"
45 nginx_reading="${nginx_response[11]}"
46 nginx_writing="${nginx_response[13]}"
47 nginx_waiting="${nginx_response[15]}"
49 if [ -z "${nginx_active_connections}" \
50 -o -z "${nginx_accepts}" \
51 -o -z "${nginx_handled}" \
52 -o -z "${nginx_requests}" \
53 -o -z "${nginx_reading}" \
54 -o -z "${nginx_writing}" \
55 -o -z "${nginx_waiting}" \
58 echo >&2 "nginx: empty values got from nginx server: ${nginx_response[*]}"
65 # _check is called once, to find out if this chart should be enabled or not
71 echo >&2 "nginx: cannot find stub_status on URL '${nginx_url}'. Please set nginx_url='http://nginx.server/stub_status' in $confd/nginx.conf"
76 # - 0 to enable the chart
77 # - 1 to disable the chart
82 # _create is called once, to create the charts
85 CHART nginx_local.connections '' "nginx Active Connections" "connections" nginx nginx.connections line $((nginx_priority + 1)) $nginx_update_every
86 DIMENSION active '' absolute 1 1
88 CHART nginx_local.requests '' "nginx Requests" "requests/s" nginx nginx.requests line $((nginx_priority + 2)) $nginx_update_every
89 DIMENSION requests '' incremental 1 1
91 CHART nginx_local.connections_status '' "nginx Active Connections by Status" "connections" nginx nginx.connections.status line $((nginx_priority + 3)) $nginx_update_every
92 DIMENSION reading '' absolute 1 1
93 DIMENSION writing '' absolute 1 1
94 DIMENSION waiting idle absolute 1 1
96 CHART nginx_local.connect_rate '' "nginx Connections Rate" "connections/s" nginx nginx.connections.rate line $((nginx_priority + 4)) $nginx_update_every
97 DIMENSION accepts accepted incremental 1 1
98 DIMENSION handled '' incremental 1 1
104 # _update is called continiously, to collect the values
106 # the first argument to this function is the microseconds since last update
107 # pass this parameter to the BEGIN statement (see bellow).
109 # do all the work to collect / calculate the values
111 # remember: KEEP IT SIMPLE AND SHORT
113 nginx_get || return 1
115 # write the result of the work.
117 BEGIN nginx_local.connections $1
118 SET active = $((nginx_active_connections))
120 BEGIN nginx_local.requests $1
121 SET requests = $((nginx_requests))
123 BEGIN nginx_local.connections_status $1
124 SET reading = $((nginx_reading))
125 SET writing = $((nginx_writing))
126 SET waiting = $((nginx_waiting))
128 BEGIN nginx_local.connect_rate $1
129 SET accepts = $((nginx_accepts))
130 SET handled = $((nginx_handled))