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

Merge branch '6908_check_rearbackup' into 'master'

check_proc_ressources - update check; add doc page

See merge request !227
parents 308d5d5d 6707cd46
Branches
No related tags found
1 merge request!227check_proc_ressources - update check; add doc page
...@@ -15,16 +15,12 @@ ...@@ -15,16 +15,12 @@
# 2020-03-03 v1.0 inititial version # 2020-03-03 v1.0 inititial version
# 2020-03-05 v1.1 <axel.hahn@iml.unibe.ch> switch to ph.* helper functions # 2020-03-05 v1.1 <axel.hahn@iml.unibe.ch> switch to ph.* helper functions
# 2020-06-06 v1.2 <axel.hahn@iml.unibe.ch> for cpu: limits are multiplicated with count of cpu # 2020-06-06 v1.2 <axel.hahn@iml.unibe.ch> for cpu: limits are multiplicated with count of cpu
# 2023-12-22 v1.3 <axel.hahn@unibe.ch> update help; no temp files
# ====================================================================== # ======================================================================
_version="1.0" . $( dirname $0 )/inc_pluginfunctions
# --- tmp files for internal usage export self_APPVERSION=1.3
tmpfile=/tmp/processlist1_$$
tmpfile2=/tmp/processlist2_$$
outCritical=/tmp/processlist_critical_$$
outWarning=/tmp/processlist_warning_$$
# --- limits # --- limits
iWarnLimitCpu=70 iWarnLimitCpu=70
...@@ -36,37 +32,47 @@ iCriticalLimitMem=90 ...@@ -36,37 +32,47 @@ iCriticalLimitMem=90
typeset -i iCountWarning=0 typeset -i iCountWarning=0
typeset -i iCountCritical=0 typeset -i iCountCritical=0
rm -f $tmpfile $tmpfile2 $outCritical $outWarning 2>/dev/null typeset -i iCriticalLimit=0
typeset -i iWarnLimit=0
. `dirname $0`/inc_pluginfunctions typeset -i iMulti=1
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# FUNCTIONS # FUNCTIONS
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# show help
function showHelp(){ function showHelp(){
cat <<EOH cat <<EOH
______________________________________________________________________ $( ph.showImlHelpHeader )
SHOW PROCESSES USING A LOT OF CPU OR MEMORY :: v${_version}
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
______________________________________________________________________
SYNTAX: SYNTAX:
check_proc_ressources -m METHOD [-w WARNLIMIT] [-c CRITICALLIMIT] check_proc_ressources -m METHOD [-w WARNLIMIT] [-c CRITICALLIMIT]
METHOD string identify what to check; one of cpu|mem
WARNLIMIT integer optional: value in percent;
default: $iWarnLimitCpu (cpu) | $iWarnLimitMem (mem)
CRITICALLIMIT integer optional: value in percent
default: $iCriticalLimitCpu (cpu) | $iCriticalLimitMem (mem)
Remark: for cpu the given value is multiplicated with count of cpu EXAMPLE:
-h, --help
show help
-c, --critical VALUE
critical value; defaults:
* cpu $iCriticalLimitCpu
* mem $iCriticalLimitMem
-m, --mode VALUE
identify what to check; one of cpu|mem
Remark: for cpu the given limits are multiplicated with count of cpu.
-w. --warning VALUE
warning limit value; defaults:
* cpu $iWarnLimitCpu
* mem $iWarnLimitMem
EXAMPLE: EXAMPLE:
check_proc_ressources -m mem -w 50 -c 70 check_proc_ressources -m mem -w 50 -c 70
Show processes consuming more than 50% of memory; mark as critical
when using 70% and more.
EOH EOH
} }
...@@ -78,20 +84,19 @@ EOH ...@@ -78,20 +84,19 @@ EOH
# ----- check limits # ----- check limits
typeset -i iCriticalLimit=0 while [[ "$#" -gt 0 ]]; do case $1 in
typeset -i iWarnLimit=0 -h|--help) showHelp; exit 0;;
typeset -i iMulti=1 -m|--mode) sMode=$2; shift ;shift;;
-c|--critcal) iCriticalLimit=$2; shift ;shift;;
# set default / override from command line params -w|--warning) iWarnLimit=$2; shift ;shift;;
typeset -i iWarnLimit=` ph.getValueWithParam 70 w "$@"` *) echo "ERROR: Unknown parameter: $1"; showHelp; exit 1;
typeset -i iCriticalLimit=` ph.getValueWithParam 90 c "$@"` esac; done
sMode=` ph.getValueWithParam '' m "$@"`
case "${sMode}" in case "${sMode}" in
"cpu") "cpu")
scanfield="pcpu" scanfield="pcpu"
unit="CPU" unit="Cpu"
test $iWarnLimit -eq 0 && iWarnLimit=$iWarnLimitCpu test $iWarnLimit -eq 0 && iWarnLimit=$iWarnLimitCpu
test $iCriticalLimit -eq 0 && iCriticalLimit=$iCriticalLimitCpu test $iCriticalLimit -eq 0 && iCriticalLimit=$iCriticalLimitCpu
...@@ -111,7 +116,7 @@ esac ...@@ -111,7 +116,7 @@ esac
if [ "$sMode" = "cpu" ]; then if [ "$sMode" = "cpu" ]; then
typeset -i iCpucount=`cat /proc/cpuinfo | grep vendor_id | wc -l` typeset -i iCpucount=$(cat /proc/cpuinfo | grep vendor_id | wc -l)
if [ $iMulti -eq 0 ]; then if [ $iMulti -eq 0 ]; then
ph.abort "ABORT: count of CPUs was not detected." ph.abort "ABORT: count of CPUs was not detected."
fi fi
...@@ -121,36 +126,47 @@ fi ...@@ -121,36 +126,47 @@ fi
# ----- read processlist and create helper table # ----- read processlist and create helper table
for line in `ps -eo $scanfield,pid,comm | awk -v limit=$iWarnLimit '$1 > limit {print $1":"$2":"$3 }'` out+=$(
do for line in $(ps -eo ${scanfield},pid,comm | awk -v limit=$iWarnLimit '$1 > limit {print $1":"$2":"$3 }' | sort -k 1 -t ":" -n -r )
Value=`echo $line | cut -f 1 -d ':'` do
iValue=`echo $line | cut -f 1 -d ':' | sed "s#\..*##"`
iProcessId=`echo $line | cut -f 2 -d ':'` Value=$(echo $line | cut -f 1 -d ':')
processname=`echo $line | cut -f 3- -d ':'` iValue=$(echo $line | cut -f 1 -d ':' | sed "s#\..*##")
if [ $iValue -ge $iCriticalLimit ]; then iProcessId=$(echo $line | cut -f 2 -d ':')
iCountCritical=$iCountCritical+1 processname=$(echo $line | cut -f 3- -d ':')
echo "Critical: $Value % $unit by process id $iProcessId $processname" >> $outCritical
else test $iValue -lt $iCountWarning && break
iCountWarning=$iCountWarning+1
echo "Warning : $Value % $unit by process id $iProcessId $processname" >> $outWarning test $iValue -ge $iCountWarning && status="Warning"
fi test $iValue -ge $iCriticalLimit && status="Critical"
done
# echo "${status}: $Value % $unit by process id $iProcessId $processname"
printf "%-9s %5s %s %-10s %6s %s\n" ${status} $Value % $unit $iProcessId $processname
done
)
# ----- Status output # ----- Status output
iCountCritical=$( grep -c "^Critical" <<< "$out" )
iCountWarning=$( grep -c "^Warning" <<< "$out" )
if [ $iCountCritical -gt 0 ]; then if [ $iCountCritical -gt 0 ]; then
ph.setStatus "critical" ph.setStatus "critical"
ph.status "$iCountCritical processes use $iCriticalLimit % (critical) or more" ph.status "$iCountCritical processes use $iCriticalLimit % (critical) or more"
echo "$iCountWarning processes use $iWarnLimit % .. $iCriticalLimit % $unit" echo "$iCountWarning processes use $iWarnLimit % .. $iCriticalLimit % $unit"
echo echo
cat $outCritical | sort -n -k 2 -r echo "Level Usage process id process"
cat $outWarning 2>/dev/null| sort -n -k 2 -r echo "-----------------------------------------------------"
echo "$out"
elif [ $iCountWarning -gt 0 ]; then elif [ $iCountWarning -gt 0 ]; then
ph.setStatus "warning" ph.setStatus "warning"
ph.status "$iCountWarning processes use $iWarnLimit % .. $iCriticalLimit % $unit" ph.status "$iCountWarning processes use $iWarnLimit % .. $iCriticalLimit % $unit"
echo echo
cat $outWarning | sort -n -k 2 -r echo "Level Usage process id process"
echo "-----------------------------------------------------"
echo "$out"
else else
ph.setStatus "ok" ph.setStatus "ok"
ph.status "all processes below warning limit $iWarnLimit % $unit .. (and critical limit $iCriticalLimit %)" ph.status "all processes below warning limit $iWarnLimit % $unit .. (and critical limit $iCriticalLimit %)"
...@@ -161,19 +177,14 @@ fi ...@@ -161,19 +177,14 @@ fi
case "${sMode}" in case "${sMode}" in
"cpu") "cpu")
echo echo
echo Remark: $iCpucount CPUs detected echo Cpus detected: $iCpucount
;; ;;
"mem") "mem")
echo echo
egrep '^(MemTotal|MemFree|MemAvailable|Boffers|Cached):' /proc/meminfo grep -E '^(MemTotal|MemFree|MemAvailable|Boffers|Cached):' /proc/meminfo
;; ;;
esac esac
# ----- cleanup temp stuff
rm -f $tmpfile $outCritical $outWarning 2>/dev/null
ph.exit ph.exit
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -38,7 +38,7 @@ There is one include script used by all checks: ...@@ -38,7 +38,7 @@ There is one include script used by all checks:
* [check_packages2install](check_packages2install.md) * [check_packages2install](check_packages2install.md)
* [check_php-fpm-status](check_php-fpm-status.md) * [check_php-fpm-status](check_php-fpm-status.md)
* [check_proc_mem](check_proc_mem.md) * [check_proc_mem](check_proc_mem.md)
* check_proc_ressources * [check_proc_ressources](check_proc_ressources.md)
* check_proc_zombie * check_proc_zombie
* [check_psqlserver](check_psqlserver.md) * [check_psqlserver](check_psqlserver.md)
* [check_rearbackup](check_rearbackup.md) * [check_rearbackup](check_rearbackup.md)
......
# Check process resources regarding cpu and memory
## Introduction
Show processes that consume the most memory or cpu.
You get a list with usage, process id and process
## Requirements
Nothing special.
## Syntax
```txt
______________________________________________________________________
CHECK_PROC_RESSOURCES
v1.3
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
https://os-docs.iml.unibe.ch/icinga-checks/Checks/check_proc_ressources.html
______________________________________________________________________
SYNTAX:
check_proc_ressources -m METHOD [-w WARNLIMIT] [-c CRITICALLIMIT]
EXAMPLE:
-h, --help
show help
-c, --critical VALUE
critical value; defaults:
* cpu 90
* mem 90
-m, --mode VALUE
identify what to check; one of cpu|mem
Remark: for cpu the given limits are multiplicated with count of cpu.
-w. --warning VALUE
warning limit value; defaults:
* cpu 70
* mem 70
EXAMPLE:
check_proc_ressources -m mem -w 50 -c 70
Show processes consuming more than 50% of memory; mark as critical
when using 70% and more.
```
## Examples
### CPU check
`./check_proc_ressources -m cpu -w 50 -c 70` returns
```txt
OK: all processes below warning limit 200 % Cpu .. (and critical limit 280 %)
Cpus detected: 4
```
### Memory check
`./check_proc_ressources -m mem -w 10 -c 70` returns
```txt
WARNING: 1 processes use 10 % .. 70 % Memory
Level Usage process id process
-----------------------------------------------------
Warning 10.9 % Memory 3807 pamac-manager
MemTotal: 16135088 kB
MemFree: 1420576 kB
MemAvailable: 3913212 kB
Cached: 4560964 kB
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment