Skip to content
Snippets Groups Projects
Commit b025454a authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch '6588-add-couchdb-check' into 'master'

6588 add couchdb check

See merge request !153
parents 3b45c80d ac30a2ea
Branches
No related tags found
1 merge request!1536588 add couchdb check
......@@ -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,17 +52,25 @@ 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
$_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":'
_status=$( jq 'with_entries(.value |= .value)' <<< "${RESPONSE}" )
typeset -i _iValue
typeset -i _iDelta
"up")
REQ=/_up
abortOnWrongResponse "${REQ}" '"status":"'
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
_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
;;
_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"
......
......@@ -18,7 +18,7 @@ Check couchdb status.
______________________________________________________________________
CHECK_COUCHDB
v0.6
v0.7
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
......@@ -39,17 +39,25 @@ 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:
check_couchdb -m up
Check if couchdb is up and running
check_couchdb -m httpd_methods
Show counters and change rate per sec of GET, POST, and other methods
check_couchdb -c /opt/couchdb/myconfig.sh -m up
Source another config to define COUCH_URL
```
## Installation
......@@ -74,34 +82,86 @@ With parameter ``-c CFGFILE`` can define another location where to find the vari
With the parameter ``-m METHOD`` you define what kind of check to perform.
### up
### httpd
Simple check if couchdb is up and running.
Show counters for http request types.
From url ``/up`` it fetches the value status.
It switches to critical if one of the seeds is not "ok".
All values are taken from ``/_node/_local/_stats/couchdb/httpd``
`check_couchdb -m up` returns
``check_couchdb -m httpd_methods`` returns
```txt
OK: Couchdb :: health status (value 'status' in /_up is 'ok')
Reponse of /_up:
{
"status": "ok",
"seeds": {
"couchdb@192.168.25.172": {
"timestamp": "2023-08-28T07:27:54.938619Z",
"last_replication_status": "ok",
"pending_updates": {
"_nodes": 0,
"_dbs": 0,
"_users": 0
}
},
"couchdb@192.168.25.61": {}
}
}
OK: Couchdb :: Http request methods
______________________Property____Counter______Delta
aborted_requests 0 0 per sec
bulk_requests 0 0 per sec
requests 190116 1 per sec
view_timeouts 0 0 per sec
find_timeouts 0 0 per sec
explain_timeouts 0 0 per sec
all_docs_timeouts 0 0 per sec
partition_view_requests 0 0 per sec
partition_find_requests 0 0 per sec
partition_explain_requests 0 0 per sec
partition_all_docs_requests 0 0 per sec
partition_view_timeouts 0 0 per sec
partition_find_timeouts 0 0 per sec
partition_explain_timeouts 0 0 per sec
partition_all_docs_timeouts 0 0 per sec
temporary_view_reads 0 0 per sec
view_reads 0 0 per sec
clients_requesting_changes 0 0 per sec
purge_requests 0 0 per sec
|abortedrequests=0;; bulkrequests=0;; requests=1;; viewtimeouts=0;; findtimeouts=0;; explaintimeouts=0;; alldocstimeouts=0;; partitionviewrequests=0;; partitionfindrequests=0;; partitionexplainrequests=0;; partitionalldocsrequests=0;; partitionviewtimeouts=0;; partitionfindtimeouts=0;; partitionexplaintimeouts=0;; partitionalldocstimeouts=0;; temporaryviewreads=0;; viewreads=0;; clientsrequestingchanges=0;; purgerequests=0;;
```
### httpd_methods
Show counters for http request methods.
All values are taken from ``/_node/_local/_stats/couchdb/httpd_request_methods``
``check_couchdb -m httpd_methods`` returns
```txt
OK: Couchdb :: Http request methods
____Method____Counter______Delta
COPY 0 0 per sec
DELETE 1 0 per sec
GET 190332 1 per sec
HEAD 0 0 per sec
OPTIONS 0 0 per sec
POST 0 0 per sec
PUT 0 0 per sec
|copy=0;; delete=0;; get=1;; head=0;; options=0;; post=0;; put=0;;
```
### open_databases
Show number of open databases
The value is taken from ``/_node/_local/_stats/couchdb/open_databases``
This check sends performance data.
``check_couchdb -m open_databases`` returns
```txt
OK: Couchdb :: open_databases = 0
|opendatabases=0;;
```
### open_os_files
Show number of file descriptors CouchDB has open
The value is taken from ``/_node/_local/_stats/couchdb/open_os_files``
This check sends performance data.
``check_couchdb -m open_os_files`` returns
```txt
OK: Couchdb :: open_os_files = 0
|openosfiles=0;;
```
### pending
......@@ -168,59 +228,32 @@ Reponse: of /_up
}
```
### open_databases
### up
Show number of open databases
Simple check if couchdb is up and running.
This check sends performance data.
From url ``/up`` it fetches the value status.
It switches to critical if one of the seeds is not "ok".
``check_couchdb -m open_databases`` returns
`check_couchdb -m up` returns
```txt
OK: Couchdb :: open_databases = 0
Reponse: of /_node/_local/_stats/couchdb/open_databases
OK: Couchdb :: health status (value 'status' in /_up is 'ok')
Reponse of /_up:
{
"value": 0,
"type": "counter",
"desc": "number of open databases"
"status": "ok",
"seeds": {
"couchdb@192.168.25.172": {
"timestamp": "2023-08-28T07:27:54.938619Z",
"last_replication_status": "ok",
"pending_updates": {
"_nodes": 0,
"_dbs": 0,
"_users": 0
}
},
"couchdb@192.168.25.61": {}
}
|opendatabases=0;;
```
### open_os_files
Show number of file descriptors CouchDB has open
This check sends performance data.
``check_couchdb -m open_os_files`` returns
```txt
OK: Couchdb :: open_os_files = 0
Reponse: of /_node/_local/_stats/couchdb/open_os_files
{
"value": 0,
"type": "counter",
"desc": "number of file descriptors CouchDB has open"
}
|openosfiles=0;;
```
### httpd_methods
Show counters for http request methods.
``check_couchdb -m httpd_methods`` returns
```txt
OK: Couchdb :: Http request methods
Method Counter Delta
COPY 0 0 per sec
DELETE 1 0 per sec
GET 116122 1 per sec
HEAD 0 0 per sec
OPTIONS 0 0 per sec
POST 0 0 per sec
PUT 0 0 per sec
|copy=0;; delete=0;; get=1;; head=0;; options=0;; post=0;; put=0;;
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment