From 3ce72b60d57c3d9ebae522b5712c5aeb79e66575 Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch>
Date: Tue, 29 Aug 2023 15:23:56 +0200
Subject: [PATCH] add checks "open_databases" + "open_os_files"

---
 check_couchdb | 46 ++++++++++++++++++++++++++++++++--------------
 1 file changed, 32 insertions(+), 14 deletions(-)

diff --git a/check_couchdb b/check_couchdb
index 1774c17..1c53b0f 100755
--- a/check_couchdb
+++ b/check_couchdb
@@ -17,11 +17,12 @@
 # 2023-08-28  v0.2  <axel.hahn@unibe.ch>  first check "up"
 # 2023-08-28  v0.3  <axel.hahn@unibe.ch>  add check "replication"
 # 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"
 # ======================================================================
 
 . $(dirname $0)/inc_pluginfunctions
 
-export self_APPVERSION=0.4
+export self_APPVERSION=0.5
 
 cfgfile=/etc/icingaclient/.couchdb
 export RESPONSE
@@ -42,16 +43,18 @@ SYNTAX:
 $_self [-h] [-t FILE] -m MODE
 
 OPTIONS:
-    -h or --help   show this help.
-    -c CFGFILE     set a custom config file
-                   default: ${cfgfile}
-    -m MODE        test a value; for debugging purposes the full json 
-                   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
+  -h or --help    show this help.
+  -c CFGFILE      set a custom config file
+                  default: /etc/icingaclient/.couchdb
+  -m MODE         test a value; for debugging purposes the full json 
+                  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
+  open_databases  show number of open databases
+  open_os_files   show number of file descriptors CouchDB has open
 
 EXAMPLE:
 $_self -m up
@@ -122,7 +125,8 @@ case "${sMode}" in
                 ph.setStatus critical
         fi
         ph.status "Couchdb :: health status (value 'status' in ${REQ} is '$_status')"
-        echo "Reponse of ${REQ}: "; echo "${RESPONSE}" | jq
+        echo "Reponse of ${REQ}: "; 
+        echo "${RESPONSE}" | jq
         ;;
     # ............................................................
     "replication")
@@ -139,7 +143,8 @@ case "${sMode}" in
         fi
 
         ph.status "Couchdb :: replication (values 'last_replication_status' in ${REQ} are '$_status')"
-        echo "Reponse: of ${REQ}"; echo "${RESPONSE}" | jq
+        echo "Reponse: of ${REQ}"; 
+        echo "${RESPONSE}" | jq
         ;;
     # ............................................................
     "pending")
@@ -165,7 +170,20 @@ case "${sMode}" in
         done
 
         ph.status "Couchdb :: pending updates: $_iTotal (values below 'pending_updates' in ${REQ})"
-        echo "Reponse: of ${REQ}"; echo "${RESPONSE}" | jq
+        echo "Reponse: of ${REQ}"; 
+        echo "${RESPONSE}" | jq
+        ;;
+
+    "open_databases"|"open_os_files")
+        REQ=/_node/_local/_stats/couchdb/${sMode}
+        abortOnWrongResponse "${REQ}" '"value":'
+        # descr=$( jq '.desc'  <<< "${RESPONSE}" | tr -d '"')
+        value=$( jq '.value' <<< "${RESPONSE}" )
+        ph.perfadd "${sMode}" "$value"    "" ""
+        ph.status "Couchdb :: ${sMode} = $value"
+        # echo "$descr"
+        echo "Reponse: of ${REQ}"; 
+        echo "${RESPONSE}" | jq
         ;;
     # ............................................................
     *)
-- 
GitLab