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

ceph status: add help; no more tmpfile

parent e089a70c
Branches
No related tags found
1 merge request!121Update docs
This commit is part of merge request !121. Comments created here will be created in the context of that merge request.
...@@ -19,12 +19,15 @@ ...@@ -19,12 +19,15 @@
# 2021-03-31 v1.2 <axel.hahn@iml.unibe.ch> estimate remaining time of ceph recovery # 2021-03-31 v1.2 <axel.hahn@iml.unibe.ch> estimate remaining time of ceph recovery
# 2021-04-12 v1.3 <axel.hahn@iml.unibe.ch> if degraded items are 0 delete init file too # 2021-04-12 v1.3 <axel.hahn@iml.unibe.ch> if degraded items are 0 delete init file too
# 2023-04-24 v1.4 <axel.hahn@unibe.ch> update for newer ceph versions # 2023-04-24 v1.4 <axel.hahn@unibe.ch> update for newer ceph versions
# 2023-06-19 v1.5 <axel.hahn@unibe.ch> add help and param support; no more tmpfile
# ====================================================================== # ======================================================================
. $(dirname $0)/inc_pluginfunctions . $(dirname $0)/inc_pluginfunctions
initfile=/tmp/ceph-status-not-ok-start initfile="/tmp/ceph-status-not-ok-start-$USER"
tmpfile=/tmp/ceph-status.out_$$
self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] )
self_APPVERSION=1.5
iSleep=3 iSleep=3
doLoop=1 doLoop=1
...@@ -39,24 +42,52 @@ line="__________________________________________________________________________ ...@@ -39,24 +42,52 @@ line="__________________________________________________________________________
# FUNCTIONS # FUNCTIONS
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
function showHelp(){
_self=$(basename $0)
cat <<EOF
______________________________________________________________________
$self_APPNAME
v$self_APPVERSION
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
______________________________________________________________________
Show ceph health status.
The state of the check switches to warning if HEALTH_WARN was detected
and is error of other HEALTH values than HEALTH_WARN or HEALTH_OK.
In the output is the complete output of the command "ceph status".
If degraded objects are found it shows the progress of repair process.
SYNTAX:
$_self
OPTIONS:
-h or --help show this help.
EOF
}
function readCephStatus(){ function readCephStatus(){
sudo ceph status >$tmpfile if ! data=$( sudo /bin/ceph status 2>&1 ); then
if [ $? -ne 0 ]; then echo "$data"
rm -f $tmpfile
ph.abort "UNKNOWN: ceph is not available or no sudo permissions to execute ceph commands." ph.abort "UNKNOWN: ceph is not available or no sudo permissions to execute ceph commands."
fi fi
} }
function getCephStatus(){ function getCephStatus(){
cat $tmpfile | grep "health:" | awk '{ print $2 }' grep "health:" <<< "$data" | awk '{ print $2 }'
} }
function getTotalObjects(){ function getTotalObjects(){
cat $tmpfile | grep "pgs:.*objects degraded" | awk '{ print $2 }' | cut -f 2 -d "/" grep "pgs:.*objects degraded" <<< "$data" | awk '{ print $2 }' | cut -f 2 -d "/"
} }
function getDegraded(){ function getDegraded(){
cat $tmpfile | grep "pgs:.*objects degraded" | awk '{ print $2 }' | cut -f 1 -d "/" grep "pgs:.*objects degraded" <<< "$data" | awk '{ print $2 }' | cut -f 1 -d "/"
} }
function getMisplaced(){ function getMisplaced(){
cat $tmpfile | grep ".*objects misplaced" | awk '{ print $2 }' | cut -f 1 -d "/" grep ".*objects misplaced" <<< "$data" | awk '{ print $2 }' | cut -f 1 -d "/"
} }
...@@ -64,6 +95,14 @@ function getMisplaced(){ ...@@ -64,6 +95,14 @@ function getMisplaced(){
# MAIN # MAIN
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# --- check param -h
case "$1" in
"--help"|"-h")
showHelp
exit 0
;;
*)
esac
readCephStatus readCephStatus
if [ ! -f $initfile ]; then if [ ! -f $initfile ]; then
...@@ -95,11 +134,11 @@ fi ...@@ -95,11 +134,11 @@ fi
ph.status "Ceph status is $sCephStatus" ph.status "Ceph status is $sCephStatus"
echo echo
while [ ! "$sCephStatus" = "HEALTH_OK" -a $doLoop = 1 ]; do while [ ! "$sCephStatus" = "HEALTH_OK" ] && [ $doLoop = 1 ]; do
typeset -i iObjCount=$iDeg+$iMis typeset -i iObjCount=$iDeg+$iMis
iTsNow=`date +%s` iTsNow=$( date +%s )
typeset -i iDegNow=$(getDegraded) typeset -i iDegNow=$(getDegraded)
typeset -i iMisNow=$(getMisplaced) typeset -i iMisNow=$(getMisplaced)
...@@ -114,7 +153,7 @@ while [ ! "$sCephStatus" = "HEALTH_OK" -a $doLoop = 1 ]; do ...@@ -114,7 +153,7 @@ while [ ! "$sCephStatus" = "HEALTH_OK" -a $doLoop = 1 ]; do
# typeset -i iDeltaMis2=$iLastMis-$iMisNow # typeset -i iDeltaMis2=$iLastMis-$iMisNow
if [ $iTsDelta -gt 0 ]; then if [ $iDegNow+$iMisNow -gt 0 ] && [ $iTsDelta -gt 0 ]; then
typeset -i iDegPerMin=$iDoneDeg/$iTsDelta*60 typeset -i iDegPerMin=$iDoneDeg/$iTsDelta*60
if [ $iDegPerMin -gt 0 ]; then if [ $iDegPerMin -gt 0 ]; then
# timeByDeg=`echo $iTsDelta*$iObjCount/$iDoneDeg/60 - $iTsDelta/60 | bc` # timeByDeg=`echo $iTsDelta*$iObjCount/$iDoneDeg/60 - $iTsDelta/60 | bc`
...@@ -180,9 +219,7 @@ while [ ! "$sCephStatus" = "HEALTH_OK" -a $doLoop = 1 ]; do ...@@ -180,9 +219,7 @@ while [ ! "$sCephStatus" = "HEALTH_OK" -a $doLoop = 1 ]; do
printf "misplaced $tbl" "$iMis" "$iMisNow" "$iDoneMis" "$iMisPerMin" "$_timeByMis" printf "misplaced $tbl" "$iMis" "$iMisNow" "$iDoneMis" "$iMisPerMin" "$_timeByMis"
printf "total $tbl" $iObjCount $iNowTotal $iDoneTotal " " "$sTimeLeft" printf "total $tbl" $iObjCount $iNowTotal $iDoneTotal " " "$sTimeLeft"
echo $line echo $line
cat $tmpfile echo "$data"
rm -f $tmpfile 2>/dev/null
if [ $doSingleLoop = 1 ]; then if [ $doSingleLoop = 1 ]; then
doLoop=0 doLoop=0
...@@ -194,12 +231,10 @@ while [ ! "$sCephStatus" = "HEALTH_OK" -a $doLoop = 1 ]; do ...@@ -194,12 +231,10 @@ while [ ! "$sCephStatus" = "HEALTH_OK" -a $doLoop = 1 ]; do
done done
test $doSingleLoop = 0 -o "$sCephStatus" = "HEALTH_OK" && cat $tmpfile test $doSingleLoop = 0 -o "$sCephStatus" = "HEALTH_OK" && echo "$data"
echo echo
echo --- DONE `date` echo --- DONE $( date )
test "$sCephStatus" = "HEALTH_OK" && rm -f $initfile 2>/dev/null test "$sCephStatus" = "HEALTH_OK" && rm -f $initfile 2>/dev/null
test $iDeg -eq 0 && rm -f $initfile 2>/dev/null test $iDeg -eq 0 && rm -f $initfile 2>/dev/null
rm -f $tmpfile 2>/dev/null
ph.exit ph.exit
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment