1 # no need for shebang - this file is loaded from charts.d.plugin
4 # real-time performance and health monitoring, done right!
5 # (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
9 # if this chart is called X.chart.sh, then all functions and global variables
12 nginx_url="http://127.0.0.1:80/stub_status"
15 # _update_every is a special variable - it holds the number of seconds
16 # between the calls of the _update() function
20 declare -a nginx_response=()
21 nginx_active_connections=0
29 nginx_response=($(run curl -Ss ${nginx_curl_opts} "${nginx_url}"))
30 [ $? -ne 0 -o "${#nginx_response[@]}" -eq 0 ] && return 1
32 if [ "${nginx_response[0]}" != "Active" \
33 -o "${nginx_response[1]}" != "connections:" \
34 -o "${nginx_response[3]}" != "server" \
35 -o "${nginx_response[4]}" != "accepts" \
36 -o "${nginx_response[5]}" != "handled" \
37 -o "${nginx_response[6]}" != "requests" \
38 -o "${nginx_response[10]}" != "Reading:" \
39 -o "${nginx_response[12]}" != "Writing:" \
40 -o "${nginx_response[14]}" != "Waiting:" \
43 error "Invalid response from nginx server: ${nginx_response[*]}"
47 nginx_active_connections="${nginx_response[2]}"
48 nginx_accepts="${nginx_response[7]}"
49 nginx_handled="${nginx_response[8]}"
50 nginx_requests="${nginx_response[9]}"
51 nginx_reading="${nginx_response[11]}"
52 nginx_writing="${nginx_response[13]}"
53 nginx_waiting="${nginx_response[15]}"
55 if [ -z "${nginx_active_connections}" \
56 -o -z "${nginx_accepts}" \
57 -o -z "${nginx_handled}" \
58 -o -z "${nginx_requests}" \
59 -o -z "${nginx_reading}" \
60 -o -z "${nginx_writing}" \
61 -o -z "${nginx_waiting}" \
64 error "empty values got from nginx server: ${nginx_response[*]}"
71 # _check is called once, to find out if this chart should be enabled or not
77 error "cannot find stub_status on URL '${nginx_url}'. Please set nginx_url='http://nginx.server/stub_status' in $confd/nginx.conf"
82 # - 0 to enable the chart
83 # - 1 to disable the chart
88 # _create is called once, to create the charts
91 CHART nginx_local.connections '' "nginx Active Connections" "connections" nginx nginx.connections line $((nginx_priority + 1)) $nginx_update_every
92 DIMENSION active '' absolute 1 1
94 CHART nginx_local.requests '' "nginx Requests" "requests/s" nginx nginx.requests line $((nginx_priority + 2)) $nginx_update_every
95 DIMENSION requests '' incremental 1 1
97 CHART nginx_local.connections_status '' "nginx Active Connections by Status" "connections" nginx nginx.connections.status line $((nginx_priority + 3)) $nginx_update_every
98 DIMENSION reading '' absolute 1 1
99 DIMENSION writing '' absolute 1 1
100 DIMENSION waiting idle absolute 1 1
102 CHART nginx_local.connect_rate '' "nginx Connections Rate" "connections/s" nginx nginx.connections.rate line $((nginx_priority + 4)) $nginx_update_every
103 DIMENSION accepts accepted incremental 1 1
104 DIMENSION handled '' incremental 1 1
110 # _update is called continiously, to collect the values
112 # the first argument to this function is the microseconds since last update
113 # pass this parameter to the BEGIN statement (see bellow).
115 # do all the work to collect / calculate the values
117 # remember: KEEP IT SIMPLE AND SHORT
119 nginx_get || return 1
121 # write the result of the work.
123 BEGIN nginx_local.connections $1
124 SET active = $((nginx_active_connections))
126 BEGIN nginx_local.requests $1
127 SET requests = $((nginx_requests))
129 BEGIN nginx_local.connections_status $1
130 SET reading = $((nginx_reading))
131 SET writing = $((nginx_writing))
132 SET waiting = $((nginx_waiting))
134 BEGIN nginx_local.connect_rate $1
135 SET accepts = $((nginx_accepts))
136 SET handled = $((nginx_handled))