]> arthur.barton.de Git - netdata.git/blob - charts.d/opensips.chart.sh
rename chart fields to avoid conflicts with backends; fixes #1962
[netdata.git] / charts.d / opensips.chart.sh
1 # no need for shebang - this file is loaded from charts.d.plugin
2
3 # netdata
4 # real-time performance and health monitoring, done right!
5 # (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
6 # GPL v3+
7 #
8
9 opensips_opts="fifo get_statistics all"
10 opensips_cmd=
11 opensips_update_every=5
12 opensips_timeout=2
13 opensips_priority=80000
14
15 opensips_get_stats() {
16         run -t $opensips_timeout "$opensips_cmd" $opensips_opts |\
17                 grep "^\(core\|dialog\|net\|registrar\|shmem\|siptrace\|sl\|tm\|uri\|usrloc\):[a-zA-Z0-9_-]\+[[:space:]]*[=:]\+[[:space:]]*[0-9]\+[[:space:]]*$" |\
18                 sed \
19                         -e "s|[[:space:]]*[=:]\+[[:space:]]*\([0-9]\+\)[[:space:]]*$|=\1|g" \
20                         -e "s|[[:space:]:-]\+|_|g" \
21                         -e "s|^|opensips_|g"
22
23         local ret=$?
24         [ $ret -ne 0 ] && echo "opensips_command_failed=1"
25         return $ret
26 }
27
28 opensips_check() {
29         # if the user did not provide an opensips_cmd
30         # try to find it in the system
31         if [ -z "$opensips_cmd" ]
32                 then
33                 require_cmd opensipsctl || return 1
34         fi
35
36         # check once if the command works
37         local x="$(opensips_get_stats | grep "^opensips_core_")"
38         if [ ! $? -eq 0 -o -z "$x" ]
39         then
40                 error "cannot get global status. Please set opensips_opts='options' whatever needed to get connected to opensips server, in $confd/opensips.conf"
41                 return 1
42         fi
43
44         return 0
45 }
46
47 opensips_create() {
48         # create the charts
49         cat <<EOF
50 CHART opensips.dialogs_active '' "OpenSIPS Active Dialogs" "dialogs" dialogs '' area $((opensips_priority + 1)) $opensips_update_every
51 DIMENSION dialog_active_dialogs active absolute 1 1
52 DIMENSION dialog_early_dialogs early absolute -1 1
53
54 CHART opensips.users '' "OpenSIPS Users" "users" users '' line $((opensips_priority + 2)) $opensips_update_every
55 DIMENSION usrloc_registered_users registered absolute 1 1
56 DIMENSION usrloc_location_users location absolute 1 1
57 DIMENSION usrloc_location_contacts contacts absolute 1 1
58 DIMENSION usrloc_location_expires expires incremental -1 1
59
60 CHART opensips.registrar '' "OpenSIPS Registrar" "registrations/s" registrar '' line $((opensips_priority + 3)) $opensips_update_every
61 DIMENSION registrar_accepted_regs accepted incremental 1 1
62 DIMENSION registrar_rejected_regs rejected incremental -1 1
63
64 CHART opensips.transactions '' "OpenSIPS Transactions" "transactions/s" transactions '' line $((opensips_priority + 4)) $opensips_update_every
65 DIMENSION tm_UAS_transactions UAS incremental 1 1
66 DIMENSION tm_UAC_transactions UAC incremental -1 1
67
68 CHART opensips.core_rcv '' "OpenSIPS Core Receives" "queries/s" core '' line $((opensips_priority + 5)) $opensips_update_every
69 DIMENSION core_rcv_requests requests incremental 1 1
70 DIMENSION core_rcv_replies replies incremental -1 1
71
72 CHART opensips.core_fwd '' "OpenSIPS Core Forwards" "queries/s" core '' line $((opensips_priority + 6)) $opensips_update_every
73 DIMENSION core_fwd_requests requests incremental 1 1
74 DIMENSION core_fwd_replies replies incremental -1 1
75
76 CHART opensips.core_drop '' "OpenSIPS Core Drops" "queries/s" core '' line $((opensips_priority + 7)) $opensips_update_every
77 DIMENSION core_drop_requests requests incremental 1 1
78 DIMENSION core_drop_replies replies incremental -1 1
79
80 CHART opensips.core_err '' "OpenSIPS Core Errors" "queries/s" core '' line $((opensips_priority + 8)) $opensips_update_every
81 DIMENSION core_err_requests requests incremental 1 1
82 DIMENSION core_err_replies replies incremental -1 1
83
84 CHART opensips.core_bad '' "OpenSIPS Core Bad" "queries/s" core '' line $((opensips_priority + 9)) $opensips_update_every
85 DIMENSION core_bad_URIs_rcvd bad_URIs_rcvd incremental 1 1
86 DIMENSION core_unsupported_methods unsupported_methods incremental 1 1
87 DIMENSION core_bad_msg_hdr bad_msg_hdr incremental 1 1
88
89 CHART opensips.tm_replies '' "OpenSIPS TM Replies" "replies/s" transactions '' line $((opensips_priority + 10)) $opensips_update_every
90 DIMENSION tm_received_replies received incremental 1 1
91 DIMENSION tm_relayed_replies relayed incremental 1 1
92 DIMENSION tm_local_replies local incremental 1 1
93
94 CHART opensips.transactions_status '' "OpenSIPS Transactions Status" "transactions/s" transactions '' line $((opensips_priority + 11)) $opensips_update_every
95 DIMENSION tm_2xx_transactions 2xx incremental 1 1
96 DIMENSION tm_3xx_transactions 3xx incremental 1 1
97 DIMENSION tm_4xx_transactions 4xx incremental 1 1
98 DIMENSION tm_5xx_transactions 5xx incremental 1 1
99 DIMENSION tm_6xx_transactions 6xx incremental 1 1
100
101 CHART opensips.transactions_inuse '' "OpenSIPS InUse Transactions" "transactions" transactions '' line $((opensips_priority + 12)) $opensips_update_every
102 DIMENSION tm_inuse_transactions inuse absolute 1 1
103
104 CHART opensips.sl_replies '' "OpenSIPS SL Replies" "replies/s" core '' line $((opensips_priority + 13)) $opensips_update_every
105 DIMENSION sl_1xx_replies 1xx incremental 1 1
106 DIMENSION sl_2xx_replies 2xx incremental 1 1
107 DIMENSION sl_3xx_replies 3xx incremental 1 1
108 DIMENSION sl_4xx_replies 4xx incremental 1 1
109 DIMENSION sl_5xx_replies 5xx incremental 1 1
110 DIMENSION sl_6xx_replies 6xx incremental 1 1
111 DIMENSION sl_sent_replies sent incremental 1 1
112 DIMENSION sl_sent_err_replies error incremental 1 1
113 DIMENSION sl_received_ACKs ACKed incremental 1 1
114
115 CHART opensips.dialogs '' "OpenSIPS Dialogs" "dialogs/s" dialogs '' line $((opensips_priority + 14)) $opensips_update_every
116 DIMENSION dialog_processed_dialogs processed incremental 1 1
117 DIMENSION dialog_expired_dialogs expired incremental 1 1
118 DIMENSION dialog_failed_dialogs failed incremental -1 1
119
120 CHART opensips.net_waiting '' "OpenSIPS Network Waiting" "kilobytes" net '' line $((opensips_priority + 15)) $opensips_update_every
121 DIMENSION net_waiting_udp UDP absolute 1 1024
122 DIMENSION net_waiting_tcp TCP absolute 1 1024
123
124 CHART opensips.uri_checks '' "OpenSIPS URI Checks" "checks / sec" uri '' line $((opensips_priority + 16)) $opensips_update_every
125 DIMENSION uri_positive_checks positive incremental 1 1
126 DIMENSION uri_negative_checks negative incremental -1 1
127
128 CHART opensips.traces '' "OpenSIPS Traces" "traces / sec" traces '' line $((opensips_priority + 17)) $opensips_update_every
129 DIMENSION siptrace_traced_requests requests incremental 1 1
130 DIMENSION siptrace_traced_replies replies incremental -1 1
131
132 CHART opensips.shmem '' "OpenSIPS Shared Memory" "kilobytes" mem '' line $((opensips_priority + 18)) $opensips_update_every
133 DIMENSION shmem_total_size total absolute 1 1024
134 DIMENSION shmem_used_size used absolute 1 1024
135 DIMENSION shmem_real_used_size real_used absolute 1 1024
136 DIMENSION shmem_max_used_size max_used absolute 1 1024
137 DIMENSION shmem_free_size free absolute 1 1024
138
139 CHART opensips.shmem_fragments '' "OpenSIPS Shared Memory Fragmentation" "fragments" mem '' line $((opensips_priority + 19)) $opensips_update_every
140 DIMENSION shmem_fragments fragments absolute 1 1
141 EOF
142
143         return 0
144 }
145
146 opensips_update() {
147         # the first argument to this function is the microseconds since last update
148         # pass this parameter to the BEGIN statement (see bellow).
149
150         # do all the work to collect / calculate the values
151         # for each dimension
152
153         # 1. get the counters page from opensips
154         # 2. sed to remove spaces; replace . with _; remove spaces around =; prepend each line with: local opensips_
155         # 3. egrep lines starting with:
156         #    local opensips_client_http_ then one or more of these a-z 0-9 _ then = and one of more of 0-9
157         #    local opensips_server_all_ then one or more of these a-z 0-9 _ then = and one of more of 0-9
158         # 4. then execute this as a script with the eval
159         #    be very carefull with eval:
160         #    prepare the script and always grep at the end the lines that are usefull, so that
161         #    even if something goes wrong, no other code can be executed
162
163         unset \
164                 opensips_dialog_active_dialogs \
165                 opensips_dialog_early_dialogs \
166                 opensips_usrloc_registered_users \
167                 opensips_usrloc_location_users \
168                 opensips_usrloc_location_contacts \
169                 opensips_usrloc_location_expires \
170                 opensips_registrar_accepted_regs \
171                 opensips_registrar_rejected_regs \
172                 opensips_tm_UAS_transactions \
173                 opensips_tm_UAC_transactions \
174                 opensips_core_rcv_requests \
175                 opensips_core_rcv_replies \
176                 opensips_core_fwd_requests \
177                 opensips_core_fwd_replies \
178                 opensips_core_drop_requests \
179                 opensips_core_drop_replies \
180                 opensips_core_err_requests \
181                 opensips_core_err_replies \
182                 opensips_core_bad_URIs_rcvd \
183                 opensips_core_unsupported_methods \
184                 opensips_core_bad_msg_hdr \
185                 opensips_tm_received_replies \
186                 opensips_tm_relayed_replies \
187                 opensips_tm_local_replies \
188                 opensips_tm_2xx_transactions \
189                 opensips_tm_3xx_transactions \
190                 opensips_tm_4xx_transactions \
191                 opensips_tm_5xx_transactions \
192                 opensips_tm_6xx_transactions \
193                 opensips_tm_inuse_transactions \
194                 opensips_sl_1xx_replies \
195                 opensips_sl_2xx_replies \
196                 opensips_sl_3xx_replies \
197                 opensips_sl_4xx_replies \
198                 opensips_sl_5xx_replies \
199                 opensips_sl_6xx_replies \
200                 opensips_sl_sent_replies \
201                 opensips_sl_sent_err_replies \
202                 opensips_sl_received_ACKs \
203                 opensips_dialog_processed_dialogs \
204                 opensips_dialog_expired_dialogs \
205                 opensips_dialog_failed_dialogs \
206                 opensips_net_waiting_udp \
207                 opensips_net_waiting_tcp \
208                 opensips_uri_positive_checks \
209                 opensips_uri_negative_checks \
210                 opensips_siptrace_traced_requests \
211                 opensips_siptrace_traced_replies \
212                 opensips_shmem_total_size \
213                 opensips_shmem_used_size \
214                 opensips_shmem_real_used_size \
215                 opensips_shmem_max_used_size \
216                 opensips_shmem_free_size \
217                 opensips_shmem_fragments
218
219         opensips_command_failed=0
220         eval "local $(opensips_get_stats)"
221         [ $? -ne 0 ] && return 1
222
223         [ $opensips_command_failed -eq 1 ] && error "failed to get values, disabling." && return 1
224
225         # write the result of the work.
226         cat <<VALUESEOF
227 BEGIN opensips.dialogs_active $1
228 SET dialog_active_dialogs = $opensips_dialog_active_dialogs
229 SET dialog_early_dialogs = $opensips_dialog_early_dialogs
230 END
231 BEGIN opensips.users $1
232 SET usrloc_registered_users = $opensips_usrloc_registered_users
233 SET usrloc_location_users = $opensips_usrloc_location_users
234 SET usrloc_location_contacts = $opensips_usrloc_location_contacts
235 SET usrloc_location_expires = $opensips_usrloc_location_expires
236 END
237 BEGIN opensips.registrar $1
238 SET registrar_accepted_regs = $opensips_registrar_accepted_regs
239 SET registrar_rejected_regs = $opensips_registrar_rejected_regs
240 END
241 BEGIN opensips.transactions $1
242 SET tm_UAS_transactions = $opensips_tm_UAS_transactions
243 SET tm_UAC_transactions = $opensips_tm_UAC_transactions
244 END
245 BEGIN opensips.core_rcv $1
246 SET core_rcv_requests = $opensips_core_rcv_requests
247 SET core_rcv_replies = $opensips_core_rcv_replies
248 END
249 BEGIN opensips.core_fwd $1
250 SET core_fwd_requests = $opensips_core_fwd_requests
251 SET core_fwd_replies = $opensips_core_fwd_replies
252 END
253 BEGIN opensips.core_drop $1
254 SET core_drop_requests = $opensips_core_drop_requests
255 SET core_drop_replies = $opensips_core_drop_replies
256 END
257 BEGIN opensips.core_err $1
258 SET core_err_requests = $opensips_core_err_requests
259 SET core_err_replies = $opensips_core_err_replies
260 END
261 BEGIN opensips.core_bad $1
262 SET core_bad_URIs_rcvd = $opensips_core_bad_URIs_rcvd
263 SET core_unsupported_methods = $opensips_core_unsupported_methods
264 SET core_bad_msg_hdr = $opensips_core_bad_msg_hdr
265 END
266 BEGIN opensips.tm_replies $1
267 SET tm_received_replies = $opensips_tm_received_replies
268 SET tm_relayed_replies = $opensips_tm_relayed_replies
269 SET tm_local_replies = $opensips_tm_local_replies
270 END
271 BEGIN opensips.transactions_status $1
272 SET tm_2xx_transactions = $opensips_tm_2xx_transactions
273 SET tm_3xx_transactions = $opensips_tm_3xx_transactions
274 SET tm_4xx_transactions = $opensips_tm_4xx_transactions
275 SET tm_5xx_transactions = $opensips_tm_5xx_transactions
276 SET tm_6xx_transactions = $opensips_tm_6xx_transactions
277 END
278 BEGIN opensips.transactions_inuse $1
279 SET tm_inuse_transactions = $opensips_tm_inuse_transactions
280 END
281 BEGIN opensips.sl_replies $1
282 SET sl_1xx_replies = $opensips_sl_1xx_replies
283 SET sl_2xx_replies = $opensips_sl_2xx_replies
284 SET sl_3xx_replies = $opensips_sl_3xx_replies
285 SET sl_4xx_replies = $opensips_sl_4xx_replies
286 SET sl_5xx_replies = $opensips_sl_5xx_replies
287 SET sl_6xx_replies = $opensips_sl_6xx_replies
288 SET sl_sent_replies = $opensips_sl_sent_replies
289 SET sl_sent_err_replies = $opensips_sl_sent_err_replies
290 SET sl_received_ACKs = $opensips_sl_received_ACKs
291 END
292 BEGIN opensips.dialogs $1
293 SET dialog_processed_dialogs = $opensips_dialog_processed_dialogs
294 SET dialog_expired_dialogs = $opensips_dialog_expired_dialogs
295 SET dialog_failed_dialogs = $opensips_dialog_failed_dialogs
296 END
297 BEGIN opensips.net_waiting $1
298 SET net_waiting_udp = $opensips_net_waiting_udp
299 SET net_waiting_tcp = $opensips_net_waiting_tcp
300 END
301 BEGIN opensips.uri_checks $1
302 SET uri_positive_checks = $opensips_uri_positive_checks
303 SET uri_negative_checks = $opensips_uri_negative_checks
304 END
305 BEGIN opensips.traces $1
306 SET siptrace_traced_requests = $opensips_siptrace_traced_requests
307 SET siptrace_traced_replies = $opensips_siptrace_traced_replies
308 END
309 BEGIN opensips.shmem $1
310 SET shmem_total_size = $opensips_shmem_total_size
311 SET shmem_used_size = $opensips_shmem_used_size
312 SET shmem_real_used_size = $opensips_shmem_real_used_size
313 SET shmem_max_used_size = $opensips_shmem_max_used_size
314 SET shmem_free_size = $opensips_shmem_free_size
315 END
316 BEGIN opensips.shmem_fragments $1
317 SET shmem_fragments = $opensips_shmem_fragments
318 END
319 VALUESEOF
320
321         return 0
322 }