diff --git a/check_couchdb b/check_couchdb index 1164e6dd51f1b62c15403ac53668c15c0302f07c..243798de72b125873899ef409337adf834ea9bfa 100755 --- a/check_couchdb +++ b/check_couchdb @@ -19,11 +19,12 @@ # 2023-08-28 v0.4 <axel.hahn@unibe.ch> add check "pending" # 2023-08-28 v0.5 <axel.hahn@unibe.ch> add checks "open_databases" + "open_os_files" # 2023-08-28 v0.6 <axel.hahn@unibe.ch> add check "httpd_methods" +# 2023-08-29 v0.7 <axel.hahn@unibe.ch> add check "httpd" # ====================================================================== . $(dirname $0)/inc_pluginfunctions -export self_APPVERSION=0.6 +export self_APPVERSION=0.7 cfgfile=/etc/icingaclient/.couchdb export RESPONSE @@ -51,16 +52,24 @@ OPTIONS: response will be shown MODE is one of - up show general couchdb status - replication show last replication status - pending show count of pending updates for nodes, dbs and users + httpd Show counters for http request types + httpd_methods Show counters for http request methods open_databases show number of open databases open_os_files show number of file descriptors CouchDB has open - httpd_methods Show counters for http request methods + replication show last replication status + pending show count of pending updates for nodes, dbs and users + replication show last replication status + up show general couchdb health status EXAMPLE: $_self -m up - Check if couchdb is up and running + Check if couchdb is up and running + +$_self -m httpd_methods + Show counters and change rate per sec of GET, POST, and other methods + +$_self -c /opt/couchdb/myconfig.sh -m up + Source another config to define COUCH_URL EOF } @@ -118,35 +127,74 @@ fi case "${sMode}" in # ............................................................ - "up") - REQ=/_up - abortOnWrongResponse "${REQ}" '"status":"' + "httpd") + REQ=/_node/_local/_stats/couchdb/httpd + abortOnWrongResponse "${REQ}" '"value":' - _status=$( jq '.status' <<< "${RESPONSE}" | tr -d '"') - if ! echo "$_status" | grep "ok" >/dev/null; then - ph.setStatus critical - fi - ph.status "Couchdb :: health status (value 'status' in ${REQ} is '$_status')" - echo "Reponse of ${REQ}: "; - echo "${RESPONSE}" | jq + typeset -i _iValue + typeset -i _iDelta + + _status=$( jq 'with_entries(.value |= .value)' <<< "${RESPONSE}" | grep '^ "' | grep -v '\{' | sed 's#[", ]##g' ) + # this returns: + # aborted_requests:0 + # bulk_requests:0 + # requests:185531 + # ... + + ph.status "Couchdb :: Http request methods" + printf "%30s %10s %10s\n" "Property" "Counter" "Delta" | tr ' ' '_' + for myVar in $( grep "[a-z\_]" <<< "$_status" | cut -f 1 -d ':' ) + do + _iValue=$( grep "^${myVar}:" <<< "$_status" | cut -f 2 -d ':' ) + _label="couchdb-${myVar//_/-}" # underscrore to minus + _iDelta=$( ph.perfdeltaspeed "${_label}" $_iValue ) + printf "%30s %10s %10s per sec\n" "$myVar" $_iValue $_iDelta + ph.perfadd "${myVar}" "$_iDelta" "" "" + done + echo ;; # ............................................................ - "replication") - REQ=/_up - abortOnWrongResponse "${REQ}" '"status":"' + "httpd_methods") + REQ=/_node/_local/_stats/couchdb/httpd_request_methods + abortOnWrongResponse "${REQ}" '"value":' - _status=$( jq '.seeds[] | .last_replication_status' <<< "${RESPONSE}" | grep -v "null" | tr -d '"') + typeset -i _iValue + typeset -i _iDelta - # there can be multiple sections "seeds" and multiple line responses. - # remove all lines with "ok" and check if there is any "bad content" left - _nonok=$( echo "$_status" | grep -v "ok" ) - if [ -n "$_nonok" ]; then - ph.setStatus critical - fi + _status=$( jq 'with_entries(.value |= .value)' <<< "${RESPONSE}" | sed 's#[", ]##g' | grep '^[A-Z]' ) + # this returns: + # COPY:0 + # DELETE:1 + # GET:188183 + # HEAD:0 + # ... - ph.status "Couchdb :: replication (values 'last_replication_status' in ${REQ} are '$_status')" - echo "Reponse: of ${REQ}"; - echo "${RESPONSE}" | jq + ph.status "Couchdb :: Http request methods" + printf "%10s %10s %10s\n" "Method" "Counter" "Delta" | tr ' ' '_' + for myVar in $( grep "[A-Z]" <<< "$_status" | cut -f 1 -d ':' ) + do + _iValue=$( grep "$myVar" <<< "$_status" | cut -f 2 -d ':' ) + _iDelta=$( ph.perfdeltaspeed "couchdb-method-${myVar}" $_iValue) + printf "%10s %10s %10s per sec\n" "$myVar" $_iValue $_iDelta + ph.perfadd "${myVar}" "$_iDelta" "" "" + done + + # echo "${_status}" | jq + ;; + # ............................................................ + "open_databases"|"open_os_files") + REQ=/_node/_local/_stats/couchdb/${sMode} + abortOnWrongResponse "${REQ}" '"value":' + + typeset -i _iValue + + # descr=$( jq '.desc' <<< "${RESPONSE}" | tr -d '"') + _iValue=$( jq '.value' <<< "${RESPONSE}" ) + ph.perfadd "${sMode}" "$_iValue" "" "" + ph.status "Couchdb :: ${sMode} = $_iValue" + # echo "$descr" + # echo "Reponse: of ${REQ}"; + # echo "${RESPONSE}" | jq ;; # ............................................................ "pending") @@ -176,40 +224,38 @@ case "${sMode}" in echo "${RESPONSE}" | jq ;; # ............................................................ - "open_databases"|"open_os_files") - REQ=/_node/_local/_stats/couchdb/${sMode} - abortOnWrongResponse "${REQ}" '"value":' + "replication") + REQ=/_up + abortOnWrongResponse "${REQ}" '"status":"' - # descr=$( jq '.desc' <<< "${RESPONSE}" | tr -d '"') - value=$( jq '.value' <<< "${RESPONSE}" ) - ph.perfadd "${sMode}" "$value" "" "" - ph.status "Couchdb :: ${sMode} = $value" - # echo "$descr" + _status=$( jq '.seeds[] | .last_replication_status' <<< "${RESPONSE}" | grep -v "null" | tr -d '"') + + # there can be multiple sections "seeds" and multiple line responses. + # remove all lines with "ok" and check if there is any "bad content" left + _nonok=$( echo "$_status" | grep -v "ok" ) + if [ -n "$_nonok" ]; then + ph.setStatus critical + fi + + ph.status "Couchdb :: replication (values 'last_replication_status' in ${REQ} are '$_status')" echo "Reponse: of ${REQ}"; echo "${RESPONSE}" | jq ;; # ............................................................ - "httpd_methods") - REQ=/_node/_local/_stats/couchdb/httpd_request_methods - abortOnWrongResponse "${REQ}" '"value":' + "up") + REQ=/_up + abortOnWrongResponse "${REQ}" '"status":"' - _status=$( jq 'with_entries(.value |= .value)' <<< "${RESPONSE}" ) - typeset -i _iValue - typeset -i _iDelta + _status=$( jq '.status' <<< "${RESPONSE}" | tr -d '"') + if ! echo "$_status" | grep "ok" >/dev/null; then + ph.setStatus critical + fi + ph.status "Couchdb :: health status" + echo "Reponse of ${REQ}: "; + echo "${RESPONSE}" | jq + ;; - ph.status "Couchdb :: Http request methods" - echo " Method Counter Delta" - for myMethod in $( grep "[A-Z]" <<< "$_status" | cut -f 1 -d ':' | tr -d ' ' | tr -d '"') - do - - _iValue=$( grep "$myMethod" <<< "$_status" | cut -f 2 -d ':' | tr -d ',' ) - _iDelta=$( ph.perfdeltaspeed "couchdb-method-${myMethod}" $_iValue) - printf "%10s %10s %10s per sec\n" "$myMethod" $_iValue $_iDelta - ph.perfadd "${myMethod}" "$_iDelta" "" "" - done - # echo "${_status}" | jq - ;; # ............................................................ *) echo "ERRROR: [${sMode}] is an INVALID mode"