diff options
author | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2015-11-20 01:19:29 +0200 |
---|---|---|
committer | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2015-11-20 01:19:29 +0200 |
commit | f86722e7a092f5d1c6c7815499bd61866c75045c (patch) | |
tree | 1449a86a8220a42909192ba1508c9d31bfe2b3c1 /charts.d/opensips.chart.sh | |
parent | 93921bbb7cd15c3f3a4e4f52386cf3611eadd8d0 (diff) |
normalized all charts.d plugins
Diffstat (limited to 'charts.d/opensips.chart.sh')
-rwxr-xr-x | charts.d/opensips.chart.sh | 46 |
1 files changed, 15 insertions, 31 deletions
diff --git a/charts.d/opensips.chart.sh b/charts.d/opensips.chart.sh index 3066ec8edb..60ca728749 100755 --- a/charts.d/opensips.chart.sh +++ b/charts.d/opensips.chart.sh @@ -1,14 +1,15 @@ #!/bin/sh opensips_opts="fifo get_statistics all" -opensips_cmd="opensipsctl" +opensips_cmd= opensips_update_every=5 opensips_timeout=2 opensips_get_stats() { timeout $opensips_timeout "$opensips_cmd" $opensips_opts |\ grep "^\(core\|dialog\|net\|registrar\|shmem\|siptrace\|sl\|tm\|uri\|usrloc\):[a-zA-Z0-9_ -]\+[[:space:]]*=[[:space:]]*[0-9]\+[[:space:]]*$" |\ - sed -e "s|-|_|g" \ + sed \ + -e "s|-|_|g" \ -e "s|:|_|g" \ -e "s|[[:space:]]\+=[[:space:]]\+|=|g" \ -e "s|[[:space:]]\+$||" \ @@ -22,13 +23,18 @@ opensips_get_stats() { } opensips_check() { - require_cmd timeout || return 1 + # if the user did not provide an opensips_cmd + # try to find it in the system + if [ -z "$opensips_cmd" ] + then + require_cmd opensipsctl || return 1 + fi - # check once if the url works + # check once if the command works local x="$(opensips_get_stats | grep "^opensips_core_")" if [ ! $? -eq 0 -o -z "$x" ] then - echo >&2 "opensips: cannot get global status. Please set opensips_opts='options' whatever needed to get connected to opensips server, in $confd/opensips.conf" + echo >&2 "$PROGRAM_NAME: opensips: cannot get global status. Please set opensips_opts='options' whatever needed to get connected to opensips server, in $confd/opensips.conf" return 1 fi @@ -141,7 +147,6 @@ opensips_update() { # do all the work to collect / calculate the values # for each dimension - # remember: KEEP IT SIMPLE AND SHORT # 1. get the counters page from opensips # 2. sed to remove spaces; replace . with _; remove spaces around =; prepend each line with: local opensips_ @@ -149,10 +154,9 @@ opensips_update() { # local opensips_client_http_ then one or more of these a-z 0-9 _ then = and one of more of 0-9 # local opensips_server_all_ then one or more of these a-z 0-9 _ then = and one of more of 0-9 # 4. then execute this as a script with the eval - # - # be very carefull with eval: - # prepare the script and always grep at the end the lines that are usefull, so that - # even if something goes wrong, no other code can be executed + # be very carefull with eval: + # prepare the script and always grep at the end the lines that are usefull, so that + # even if something goes wrong, no other code can be executed unset \ opensips_dialog_active_dialogs \ @@ -214,65 +218,54 @@ opensips_update() { eval "local $(opensips_get_stats)" [ $? -ne 0 ] && return 1 - [ $opensips_command_failed -eq 1 ] && echo >&2 "opensips: failed to get values, disabling." && return 1 + [ $opensips_command_failed -eq 1 ] && echo >&2 "$PROGRAM_NAME: opensips: failed to get values, disabling." && return 1 # write the result of the work. cat <<VALUESEOF - BEGIN opensips.dialogs_active $1 SET dialog_active_dialogs = $opensips_dialog_active_dialogs SET dialog_early_dialogs = $opensips_dialog_early_dialogs END - BEGIN opensips.users $1 SET usrloc_registered_users = $opensips_usrloc_registered_users SET usrloc_location_users = $opensips_usrloc_location_users SET usrloc_location_contacts = $opensips_usrloc_location_contacts SET usrloc_location_expires = $opensips_usrloc_location_expires END - BEGIN opensips.registrar $1 SET registrar_accepted_regs = $opensips_registrar_accepted_regs SET registrar_rejected_regs = $opensips_registrar_rejected_regs END - BEGIN opensips.transactions $1 SET tm_UAS_transactions = $opensips_tm_UAS_transactions SET tm_UAC_transactions = $opensips_tm_UAC_transactions END - BEGIN opensips.core_rcv $1 SET core_rcv_requests = $opensips_core_rcv_requests SET core_rcv_replies = $opensips_core_rcv_replies END - BEGIN opensips.core_fwd $1 SET core_fwd_requests = $opensips_core_fwd_requests SET core_fwd_replies = $opensips_core_fwd_replies END - BEGIN opensips.core_drop $1 SET core_drop_requests = $opensips_core_drop_requests SET core_drop_replies = $opensips_core_drop_replies END - BEGIN opensips.core_err $1 SET core_err_requests = $opensips_core_err_requests SET core_err_replies = $opensips_core_err_replies END - BEGIN opensips.core_bad $1 SET core_bad_URIs_rcvd = $opensips_core_bad_URIs_rcvd SET core_unsupported_methods = $opensips_core_unsupported_methods SET core_bad_msg_hdr = $opensips_core_bad_msg_hdr END - BEGIN opensips.tm_replies $1 SET tm_received_replies = $opensips_tm_received_replies SET tm_relayed_replies = $opensips_tm_relayed_replies SET tm_local_replies = $opensips_tm_local_replies END - BEGIN opensips.transactions_status $1 SET tm_2xx_transactions = $opensips_tm_2xx_transactions SET tm_3xx_transactions = $opensips_tm_3xx_transactions @@ -280,11 +273,9 @@ SET tm_4xx_transactions = $opensips_tm_4xx_transactions SET tm_5xx_transactions = $opensips_tm_5xx_transactions SET tm_6xx_transactions = $opensips_tm_6xx_transactions END - BEGIN opensips.transactions_inuse $1 SET tm_inuse_transactions = $opensips_tm_inuse_transactions END - BEGIN opensips.sl_replies $1 SET sl_1xx_replies = $opensips_sl_1xx_replies SET sl_2xx_replies = $opensips_sl_2xx_replies @@ -296,28 +287,23 @@ SET sl_sent_replies = $opensips_sl_sent_replies SET sl_sent_err_replies = $opensips_sl_sent_err_replies SET sl_received_ACKs = $opensips_sl_received_ACKs END - BEGIN opensips.dialogs $1 SET dialog_processed_dialogs = $opensips_dialog_processed_dialogs SET dialog_expired_dialogs = $opensips_dialog_expired_dialogs SET dialog_failed_dialogs = $opensips_dialog_failed_dialogs END - BEGIN opensips.net_waiting $1 SET net_waiting_udp = $opensips_net_waiting_udp SET net_waiting_tcp = $opensips_net_waiting_tcp END - BEGIN opensips.uri_checks $1 SET uri_positive_checks = $opensips_uri_positive_checks SET uri_negative_checks = $opensips_uri_negative_checks END - BEGIN opensips.traces $1 SET siptrace_traced_requests = $opensips_siptrace_traced_requests SET siptrace_traced_replies = $opensips_siptrace_traced_replies END - BEGIN opensips.shmem $1 SET shmem_total_size = $opensips_shmem_total_size SET shmem_used_size = $opensips_shmem_used_size @@ -325,7 +311,6 @@ SET shmem_real_used_size = $opensips_shmem_real_used_size SET shmem_max_used_size = $opensips_shmem_max_used_size SET shmem_free_size = $opensips_shmem_free_size END - BEGIN opensips.shmem_fragments $1 SET shmem_fragments = $opensips_shmem_fragments END @@ -333,4 +318,3 @@ VALUESEOF return 0 } - |