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

cpu: small shell fixes

parent c2e0434d
No related branches found
No related tags found
1 merge request!55Add check requirement
......@@ -21,13 +21,14 @@
# 2022-04-14 v1.10 <axel.hahn@iml.unibe.ch> show consuming cpu processes with top and ps
# 2022-08-29 v1.11 <axel.hahn@iml.unibe.ch> replace pipe to prevent start of metrics section
# 2022-08-29 v1.12 <axel.hahn@iml.unibe.ch> fix: replace pipe
# 2023-02-13 v1.13 <axel.hahn@iml.unibe.ch> small shell fixes
# ======================================================================
. $(dirname $0)/inc_pluginfunctions
self_APPNAME=$( basename $0 | tr [:lower:] [:upper:] )
self_APPVERSION=1.12
self_APPVERSION=1.13
# ----------------------------------------------------------------------
# functions
......@@ -114,7 +115,7 @@ typeset -i iMinCpuUsageToShowProcesses=$( ph.getValueWithParam 50 p "$@")
# top -b -n 1 | head -5 | grep "^\%Cpu" >$tmpfile
# FIX read cpu from 2nd output of top
data=$( top -b -n 2 -d 0.1 | grep -i "^\%Cpu" | tail -1 | cut -f 2- -d ':' | tr ',' "\n" )
data=$( top -b -n 2 -d 0.1 | grep -i "^%Cpu" | tail -1 | cut -f 2- -d ':' | tr ',' "\n" )
cpuUser=$( echo "$data" | grep "us" | awk '{ print $1 }' )
cpuSystem=$( echo "$data" | grep "sy" | awk '{ print $1 }' )
......@@ -160,14 +161,17 @@ echo "$plist" | grep "[0-9]" >/dev/null \
&& echo "$plist" | tr '|' ':'
# v1.7: show most consuming processes if usage is > nn %
typeset -i iUsed=$( echo $cpuNonIdle | cut -f 1 -d '.' )
typeset -i iUsed
iUsed=$( echo $cpuNonIdle | cut -f 1 -d '.' )
if [ $iUsed -gt $iMinCpuUsageToShowProcesses ]; then
echo
echo "CPU usage is higher $iMinCpuUsageToShowProcesses percent ... showing most consuming processes"
echo "output of top :"
topout=$( top -b -n 1 -d 0.1 )
typeset -i iStart=$( echo "$topout" | grep -n "PID.*USER" | cut -f 1 -d ':' )
typeset -i iEnd=$iStart+5
typeset -i iStart
iStart=$( echo "$topout" | grep -n "PID.*USER" | cut -f 1 -d ':' )
typeset -i iEnd
iEnd=$iStart+5
echo "$topout" | sed -n "${iStart},${iEnd}p" | tr '|' ':'
echo
echo "output of ps:"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment