#!/bin/bash # ====================================================================== # # Icinga/ Nagios Check # CEPH IO (from "ceph status") # # ---------------------------------------------------------------------- # # REQUIREMENTS: # - ceph and sudo permissions on it # # SYNTAX: # - check_ceph_io # No parameter required # # ---------------------------------------------------------------------- # 2023-05-09 v1.0 <axel.hahn@unibe.ch> # 2023-05-10 v1.1 <axel.hahn@unibe.ch> fix for small transfer rates in B/s # 2023-05-10 v1.2 <axel.hahn@unibe.ch> add tests # 2023-05-11 v1.3 <axel.hahn@unibe.ch> handle ceph status without io data in output # 2023-07-27 v1.4 <axel.hahn@unibe.ch> update help page # ====================================================================== . $(dirname $0)/inc_pluginfunctions self_APPVERSION=1.4 function showHelp(){ local _self=$(basename $0) cat <<EOF $( ph.showImlHelpHeader ) Show cheph IO as read and written bytes per second. This check sends performance data. SYNTAX: $_self OPTIONS: -h or --help show this help. -t [STRING] test a value; for debugging purposes Without a string internally stored values will be tested EXAMPLE: $_self no parameters; normal usage to get the ceph io data $_self -t Run a few builtin tests $_self -t " client: 255 B/s rd, 0 op/s rd, 0 op/s wr" Test a given string EOF } # --- check param -h case "$1" in "--help"|"-h") showHelp exit 0 ;; *) esac if [ "$1" = "-t" ]; then # Snippets for testing: # TEST: client: 13 KiB/s rd, 1.1 MiB/s wr, 130 op/s rd, 137 op/s wr # TEST: client: 8.9 KiB/s rd, 887 KiB/s wr, 138 op/s rd, 140 op/s wr # TEST: client: 255 B/s rd, 85 B/s wr, 0 op/s rd, 0 op/s # TEST: client: 255 B/s rd, 0 op/s rd, 0 op/s wr # TEST: no line with client if [ -z "$2" ]; then echo; echo ">>>>>>>>>> TESTS"; echo grep '# TEST: ' $0 | grep -v grep | cut -f 2- -d ':' | while read -r teststring do echo "--- test string [$teststring]" $0 -t "$teststring" echo; echo; echo done exit 0 else CEPHIO="$2" fi else # --- check required tools ph.require ceph # --- get output of ceph if ! CEPHOUT=$( sudo ceph status 2>&1 ); then ph.setStatus "unknown" ph.status "no data" echo "There is no output from 'sudo ceph status'." echo "No ceph here or no sudo permissions on ceph command?" echo "$CEPHOUT" fi CEPHIO=$( echo "$CEPHOUT" | grep "client:") fi if [ -n "${CEPHOUT}${CEPHIO}" ]; then CEPHDATA=$( echo "${CEPHIO}" | cut -f 2 -d ':' ) SEG_R=$( echo "${CEPHDATA}" | cut -f 1 -d "," | grep "rd" | awk '{ print $1 " " $2 }') SEG_W=$( echo "${CEPHDATA}" | cut -f 2 -d "," | grep "wr" | awk '{ print $1 " " $2 }') # remark: # - the sed transforms "NN KiB/s" --> "NN KB" (cut "i") # - the tr is for small values "NN B/s" and removes "s" IO_READ=$( echo "${SEG_R}" | sed -E "s#([0-9]*) (.).(.).*#\1\2\3#g" | tr -d 's') IO_WRITE=$( echo "${SEG_W}" | sed -E "s#([0-9]*) (.).(.).*#\1\2\3#g" | tr -d 's') test -z "$CEPHIO" && CEPHIO="'ceph status' successful - but there are no io data in output." test -z "$IO_READ" && IO_READ="0" test -z "$IO_WRITE" && IO_WRITE="0" ph.status "$( echo "${CEPHIO}" | cut -f 2 -d ":" )" ph.perfadd "cephio-read" "$IO_READ" "" "" ph.perfadd "cephio-write" "$IO_WRITE" "" "" fi ph.exit