]> arthur.barton.de Git - netdata.git/blobdiff - charts.d/crsproxy.chart.sh
Merge remote-tracking branch 'upstream/master'
[netdata.git] / charts.d / crsproxy.chart.sh
index 711b257dff4e5c358d7b13e839cdf73eb16c0305..9ad8b3382d6ced45058d8b214484ccec3eef7f65 100755 (executable)
@@ -1,26 +1,49 @@
 #!/bin/sh
 
-crsproxy_url="http://127.0.0.1:7999/counters?"
-crsproxy_cmds=""
+crsproxy_url=
+crsproxy_cmds=
 crsproxy_update_every=15
 
+crsproxy_get() {
+       wget 2>/dev/null -O - "$crsproxy_url" |\
+               sed \
+                       -e "s/ \+/ /g" \
+                       -e "s/\./_/g" \
+                       -e "s/ =/=/g" \
+                       -e "s/= /=/g" \
+                       -e "s/^/crsproxy_/g" |\
+               egrep "^crsproxy_[a-zA-Z][a-zA-Z0-9_]*=[0-9]+$"
+}
+
 crsproxy_check() {
+       # make sure we have all the commands we need
+       require_cmd wget || return 1
+       
+       if [ -z "$crsproxy_url" ]
+               then
+               echo >&2 "$PROGRAM_NAME: crsproxy: not configured. Please set crsproxy_url='url' in $confd/crsproxy.conf"
+               return 1
+       fi
+
        # check once if the url works
        wget 2>/dev/null -O /dev/null "$crsproxy_url"
        if [ ! $? -eq 0 ]
        then
-               echo >&2 "crsproxy: cannot fetch the url: $crsproxy_url. Please set crsproxy_url='url' in $confd/crsproxy.conf"
+               echo >&2 "$PROGRAM_NAME: crsproxy: cannot fetch the url: $crsproxy_url. Please set crsproxy_url='url' in $confd/crsproxy.conf"
                return 1
        fi
 
+       # if the user did not request specific commands
+       # find the commands available
        if [ -z "$crsproxy_cmds" ]
        then
-               crsproxy_cmds="`wget 2>/dev/null -O - "$crsproxy_url" | egrep "^cmd_[a-zA-Z][a-zA-Z0-9]_[a-z_]+ *= *[0-9]+$" | cut -d '_' -f 2 | sort -u`"
-               echo
+               crsproxy_cmds="$(crsproxy_get | cut -d '=' -f 1 | sed "s/^crsproxy_cmd_//g" | sort -u)"
        fi
+
+       # if no commands are available
        if [ -z "$crsproxy_cmds" ]
        then
-               echo >&2 "crsproxy: cannot find command list automatically. Please set crsproxy_cmds='...' in $confd/crsproxy.conf"
+               echo >&2 "$PROGRAM_NAME: crsproxy: cannot find command list automatically. Please set crsproxy_cmds='...' in $confd/crsproxy.conf"
                return 1
        fi
        return 0
@@ -34,18 +57,18 @@ DIMENSION web '' absolute 1 1
 DIMENSION native '' absolute 1 1
 DIMENSION virtual '' absolute 1 1
 CHART crsproxy.requests '' "CRS Proxy Requests Rate" "requests / min" crsproxy '' area 20001 $crsproxy_update_every
-DIMENSION web '' incremental 60 $crsproxy_update_every
-DIMENSION native '' incremental -60 $crsproxy_update_every
+DIMENSION web '' incremental 60 1
+DIMENSION native '' incremental -60 1
 CHART crsproxy.clients '' "CRS Proxy Clients Rate" "clients / min" crsproxy '' area 20010 $crsproxy_update_every
-DIMENSION web '' incremental 60 $crsproxy_update_every
-DIMENSION native '' incremental -60 $crsproxy_update_every
-DIMENSION virtual '' incremental 60 $crsproxy_update_every
+DIMENSION web '' incremental 60 1
+DIMENSION native '' incremental -60 1
+DIMENSION virtual '' incremental 60 1
 CHART crsproxy.replies '' "CRS Replies Rate" "replies / min" crsproxy '' area 20020 $crsproxy_update_every
-DIMENSION ok '' incremental 60 $crsproxy_update_every
-DIMENSION failed '' incremental -60 $crsproxy_update_every
+DIMENSION ok '' incremental 60 1
+DIMENSION failed '' incremental -60 1
 CHART crsproxy.bconnections '' "Back-End Connections Rate" "connections / min" crsproxy '' area 20030 $crsproxy_update_every
-DIMENSION ok '' incremental 60 $crsproxy_update_every
-DIMENSION failed '' incremental -60 $crsproxy_update_every
+DIMENSION ok '' incremental 60 1
+DIMENSION failed '' incremental -60 1
 EOF
 
        local x=
@@ -74,9 +97,7 @@ crsproxy_update() {
        # remember: KEEP IT SIMPLE AND SHORT
 
        # get the values from crsproxy
-       eval "`wget 2>/dev/null -O - "$crsproxy_url" |\
-               sed -e "s/ \+/ /g" -e "s/\./_/g" -e "s/ = /=/g" -e "s/^/crsproxy_/g" |\
-               egrep "^crsproxy_[a-zA-Z][a-zA-Z0-9_]*=[0-9]+$"`"
+       eval "$(crsproxy_get)"
 
 
        # write the result of the work.