diff --git a/check_ceph_io b/check_ceph_io index 8963f740fe84b80627bea0247059250c49a42a8d..f698704fd9a2d024e03414e13f0b16ffe17e4b6a 100755 --- a/check_ceph_io +++ b/check_ceph_io @@ -16,14 +16,16 @@ # ---------------------------------------------------------------------- # 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 # ====================================================================== . $(dirname $0)/inc_pluginfunctions self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] ) -self_APPVERSION=1.1 +self_APPVERSION=1.2 function showHelp(){ + _self=$(basename $0) cat <<EOF ______________________________________________________________________ @@ -38,10 +40,22 @@ Show cheph IO as read and written bytes per second. This check sends performance data. SYNTAX: -$(basename $0) +$_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 } @@ -55,12 +69,29 @@ case "$1" in *) esac -# --- check required tools -ph.require ceph - -CEPHIO=$( sudo ceph status 2>/dev/null | grep "client:.* rd,.* wr," | cut -f 2 -d ":" ) -# CEPHIO="8.9 KiB/s rd, 887 KiB/s wr, 138 op/s rd, 140 op/s wr" -# CEPHIO="255 B/s rd, 85 B/s wr, 0 op/s rd, 0 op/s" +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 + 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 + CEPHIO=$( sudo ceph status 2>/dev/null | grep "client:") +fi if [ -z "${CEPHIO}" ]; then @@ -70,19 +101,22 @@ if [ -z "${CEPHIO}" ]; then echo "No ceph here or no sudo permissions on ceph command?" else + 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 ${CEPHIO} | cut -f 1,2 -d " " | sed -E "s#([0-9]*) (.).(.).*#\1\2\3#g" | tr -d 's' ) - IO_WRITE=$( echo ${CEPHIO} | cut -f 4,5 -d " " | sed -E "s#([0-9]*) (.).(.).*#\1\2\3#g" | tr -d 's' ) - ph.status "$CEPHIO" + 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') - # echo "read: $IO_READ" - # echo "write: $IO_WRITE" + 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 \ No newline at end of file diff --git a/docs/20_Checks/check_ceph_io.md b/docs/20_Checks/check_ceph_io.md index 8a0c10d228cfeb9cfff7e1ce8c7b8be742dfb947..162ea29773f5307296f606d7fa8ff257eee2e3ad 100644 --- a/docs/20_Checks/check_ceph_io.md +++ b/docs/20_Checks/check_ceph_io.md @@ -11,12 +11,11 @@ It returns a single line for the status and performance data. ## Syntax -``` -$ check_ceph_io --help +```txt ______________________________________________________________________ CHECK_CEPH_IO -v1.0 +v1.2 (c) Institute for Medical Education - University of Bern Licence: GNU GPL 3 @@ -30,6 +29,19 @@ check_ceph_io 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: +check_ceph_io + no parameters; normal usage to get the ceph io data + +check_ceph_io -t + Run a few builtin tests + +check_ceph_io -t " client: 255 B/s rd, 0 op/s rd, 0 op/s wr" + Test a given string + ``` ### Parameters