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