]> arthur.barton.de Git - netdata.git/blob - charts.d/crsproxy.chart.sh
more informative error messages in python-modules-installer.sh
[netdata.git] / charts.d / crsproxy.chart.sh
1 #!/bin/sh
2
3 crsproxy_url=
4 crsproxy_cmds=
5 crsproxy_update_every=15
6
7 crsproxy_get() {
8         wget 2>/dev/null -O - "$crsproxy_url" |\
9                 sed \
10                         -e "s/ \+/ /g" \
11                         -e "s/\./_/g" \
12                         -e "s/ =/=/g" \
13                         -e "s/= /=/g" \
14                         -e "s/^/crsproxy_/g" |\
15                 egrep "^crsproxy_[a-zA-Z][a-zA-Z0-9_]*=[0-9]+$"
16 }
17
18 crsproxy_check() {
19         # make sure we have all the commands we need
20         require_cmd wget || return 1
21         
22         if [ -z "$crsproxy_url" ]
23                 then
24                 echo >&2 "$PROGRAM_NAME: crsproxy: not configured. Please set crsproxy_url='url' in $confd/crsproxy.conf"
25                 return 1
26         fi
27
28         # check once if the url works
29         wget 2>/dev/null -O /dev/null "$crsproxy_url"
30         if [ ! $? -eq 0 ]
31         then
32                 echo >&2 "$PROGRAM_NAME: crsproxy: cannot fetch the url: $crsproxy_url. Please set crsproxy_url='url' in $confd/crsproxy.conf"
33                 return 1
34         fi
35
36         # if the user did not request specific commands
37         # find the commands available
38         if [ -z "$crsproxy_cmds" ]
39         then
40                 crsproxy_cmds="$(crsproxy_get | cut -d '=' -f 1 | sed "s/^crsproxy_cmd_//g" | sort -u)"
41         fi
42
43         # if no commands are available
44         if [ -z "$crsproxy_cmds" ]
45         then
46                 echo >&2 "$PROGRAM_NAME: crsproxy: cannot find command list automatically. Please set crsproxy_cmds='...' in $confd/crsproxy.conf"
47                 return 1
48         fi
49         return 0
50 }
51
52 crsproxy_create() {
53         # create the charts
54         cat <<EOF
55 CHART crsproxy.connected '' "CRS Proxy Connected Clients" "clients" crsproxy '' line 20000 $crsproxy_update_every
56 DIMENSION web '' absolute 1 1
57 DIMENSION native '' absolute 1 1
58 DIMENSION virtual '' absolute 1 1
59 CHART crsproxy.requests '' "CRS Proxy Requests Rate" "requests / min" crsproxy '' area 20001 $crsproxy_update_every
60 DIMENSION web '' incremental 60 1
61 DIMENSION native '' incremental -60 1
62 CHART crsproxy.clients '' "CRS Proxy Clients Rate" "clients / min" crsproxy '' area 20010 $crsproxy_update_every
63 DIMENSION web '' incremental 60 1
64 DIMENSION native '' incremental -60 1
65 DIMENSION virtual '' incremental 60 1
66 CHART crsproxy.replies '' "CRS Replies Rate" "replies / min" crsproxy '' area 20020 $crsproxy_update_every
67 DIMENSION ok '' incremental 60 1
68 DIMENSION failed '' incremental -60 1
69 CHART crsproxy.bconnections '' "Back-End Connections Rate" "connections / min" crsproxy '' area 20030 $crsproxy_update_every
70 DIMENSION ok '' incremental 60 1
71 DIMENSION failed '' incremental -60 1
72 EOF
73
74         local x=
75         echo "CHART crsproxy.commands '' 'CRS Commands Requests' 'requests / min' crsproxy '' stacked 20100 $crsproxy_update_every"
76         for x in $crsproxy_cmds
77         do
78                 echo "DIMENSION $x '' incremental 60 $crsproxy_update_every"
79         done
80
81         echo "CHART crsproxy.commands_failed '' 'CRS Failed Commands' 'replies / min' crsproxy '' stacked 20110 $crsproxy_update_every"
82         for x in $crsproxy_cmds
83         do
84                 echo "DIMENSION $x '' incremental 60 $crsproxy_update_every"
85         done
86
87         return 0
88 }
89
90
91 crsproxy_update() {
92         # the first argument to this function is the microseconds since last update
93         # pass this parameter to the BEGIN statement (see bellow).
94
95         # do all the work to collect / calculate the values
96         # for each dimension
97         # remember: KEEP IT SIMPLE AND SHORT
98
99         # get the values from crsproxy
100         eval "$(crsproxy_get)"
101
102
103         # write the result of the work.
104         cat <<VALUESEOF
105 BEGIN crsproxy.connected $1
106 SET web = $((crsproxy_web_clients_opened - crsproxy_web_clients_closed))
107 SET native = $((crsproxy_crs_clients_opened - crsproxy_crs_clients_closed))
108 SET virtual = $((crsproxy_virtual_clients_opened - crsproxy_virtual_clients_closed))
109 END
110 BEGIN crsproxy.requests $1
111 SET web = $crsproxy_web_requests
112 SET native = $crsproxy_native_requests
113 END
114 BEGIN crsproxy.clients $1
115 SET web = $crsproxy_web_clients_opened
116 SET native = $crsproxy_crs_clients_opened
117 SET virtual = $crsproxy_virtual_clients_opened
118 END
119 BEGIN crsproxy.replies $1
120 SET ok = $crsproxy_replies_success
121 SET failed = $crsproxy_replies_error
122 END
123 BEGIN crsproxy.bconnections $1
124 SET ok = $crsproxy_connections_nonblocking_established
125 SET failed = $crsproxy_connections_nonblocking_failed
126 END
127 VALUESEOF
128
129         local native_requests="_native_requests"
130         local web_requests="_web_requests"
131         local replies_error="_replies_error"
132         local x=
133
134         echo "BEGIN crsproxy.commands $1"
135         for x in $crsproxy_cmds
136         do
137                 eval "v=\$(( crsproxy_cmd_$x$native_requests + crsproxy_cmd_$x$web_requests ))"
138                 echo "SET $x = $v"
139         done
140         echo "END"
141
142         echo "BEGIN crsproxy.commands_failed $1"
143         for x in $crsproxy_cmds
144         do
145                 eval "v=\$crsproxy_cmd_$x$replies_error"
146                 echo "SET $x = $v"
147         done
148         echo "END"
149
150         return 0
151 }