# shellcheck shell=bash # no need for shebang - this file is loaded from charts.d.plugin # SPDX-License-Identifier: GPL-3.0-or-later # netdata # real-time performance and health monitoring, done right! # (C) 2016 Costa Tsaousis # # if this chart is called X.chart.sh, then all functions and global variables # must start with X_ nginx_url="http://127.0.0.1:80/stub_status" nginx_curl_opts="" # _update_every is a special variable - it holds the number of seconds # between the calls of the _update() function nginx_update_every= nginx_priority=60000 declare -a nginx_response=() nginx_active_connections=0 nginx_accepts=0 nginx_handled=0 nginx_requests=0 nginx_reading=0 nginx_writing=0 nginx_waiting=0 nginx_get() { # shellcheck disable=SC2207 nginx_response=($(run curl -Ss ${nginx_curl_opts} "${nginx_url}")) # shellcheck disable=SC2181 if [ $? -ne 0 ] || [ "${#nginx_response[@]}" -eq 0 ]; then return 1; fi if [ "${nginx_response[0]}" != "Active" ] ||\ [ "${nginx_response[1]}" != "connections:" ] ||\ [ "${nginx_response[3]}" != "server" ] ||\ [ "${nginx_response[4]}" != "accepts" ] ||\ [ "${nginx_response[5]}" != "handled" ] ||\ [ "${nginx_response[6]}" != "requests" ] ||\ [ "${nginx_response[10]}" != "Reading:" ] ||\ [ "${nginx_response[12]}" != "Writing:" ] ||\ [ "${nginx_response[14]}" != "Waiting:" ] then error "Invalid response from nginx server: ${nginx_response[*]}" return 1 fi nginx_active_connections="${nginx_response[2]}" nginx_accepts="${nginx_response[7]}" nginx_handled="${nginx_response[8]}" nginx_requests="${nginx_response[9]}" nginx_reading="${nginx_response[11]}" nginx_writing="${nginx_response[13]}" nginx_waiting="${nginx_response[15]}" if [ -z "${nginx_active_connections}" ] ||\ [ -z "${nginx_accepts}" ] ||\ [ -z "${nginx_handled}" ] ||\ [ -z "${nginx_requests}" ] ||\ [ -z "${nginx_reading}" ] ||\ [ -z "${nginx_writing}" ] ||\ [ -z "${nginx_waiting}" ] then error "empty values got from nginx server: ${nginx_response[*]}" return 1 fi return 0 } # _check is called once, to find out if this chart should be enabled or not nginx_check() { nginx_get # shellcheck disable=2181 if [ $? -ne 0 ] then # shellcheck disable=SC2154 error "cannot find stub_status on URL '${nginx_url}'. Please set nginx_url='http://nginx.server/stub_status' in $confd/nginx.conf" return 1 fi # this should return: # - 0 to enable the chart # - 1 to disable the chart return 0 } # _create is called once, to create the charts nginx_create() { cat <