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

Merge branch '6908_check_rearbackup' into 'master'

update check_proc_mem; add doc page; speedup 5..10 times

See merge request !226
parents b36341c2 43c3fca4
No related branches found
No related tags found
1 merge request!226update check_proc_mem; add doc page; speedup 5..10 times
...@@ -13,91 +13,118 @@ ...@@ -13,91 +13,118 @@
# 2020-03-02 v1.0 initial version # 2020-03-02 v1.0 initial 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
# 2023-02-13 v1.2 <axel.hahn@unibe.ch> some shell fixes # 2023-02-13 v1.2 <axel.hahn@unibe.ch> some shell fixes
# 2023-08-24 v1.3 <axel.hahn@unibe.ch> add help; do not use tmp file anymore # 2023-12-22 v1.3 <axel.hahn@unibe.ch> add help; do not use tmp file anymore; 5..10 times faster
# ====================================================================== # ======================================================================
. $( dirname $0 )/inc_pluginfunctions . $( dirname $0 )/inc_pluginfunctions
export self_APPVERSION=1.1 export self_APPVERSION=1.3
# --- tmp files for internal usage typeset -i iSizeMB
tmpfile=/tmp/processlist1_$$
tmpfile2=/tmp/processlist2_$$
outCritical=/tmp/processlist_critical_$$
outWarning=/tmp/processlist_warning_$$
# --- limits # --- limits
# iWarnLimit=100 typeset -i iWarnLimit=100
# iCriticalLimit=500 typeset -i iCriticalLimit=500
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
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# functions # functions
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# show help text
function showHelp(){
local _self; _self=$(basename $0)
cat <<EOF
$( ph.showImlHelpHeader )
Show processes that consume the most memory.
You get a list with processes consuming
* more than the critical limit
* between warning and critical limit
SYNTAX:
$_self [-h] [-c VALUE] [-w VALUE]
OPTIONS:
-h, --help
this help
PARAMETERS:
-c, --critical VALUE
critical level in MB (default: $iCriticalLimit)
-w. --warning VALUE
warning level in MB (default: $iWarnLimit)
EXAMPLE:
$_self
Check processes with initial memory values
$_self -w 1000 -c 2000
Check processes consuming more than 1000 MB and mark those as critical
that use more than 2000 MB.
EOF
}
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# MAIN # MAIN
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# set default / override from command line params
typeset -i iWarnLimit=$( ph.getValueWithParam 100 w "$@") # --- check param -h
typeset -i iCriticalLimit=$( ph.getValueWithParam 500 c "$@")
while [[ "$#" -gt 0 ]]; do case $1 in
-h|--help) showHelp; exit 0;;
-c|--critcal) iCriticalLimit=$2; shift ;shift;;
-w|--warning) iWarnLimit=$2; shift ;shift;;
*) echo "ERROR: Unknown parameter: $1"; showHelp; exit 1;
esac; done
# --- read processlist and create helper table # --- read processlist and create helper table
ps -yle >$tmpfile pslist=$( ps -yle )
for processname in $(cat $tmpfile | awk {'print $13'} | sort -u | grep -Fv "/") pslist2=$(
for processname in $( echo "$pslist" | awk {'print $13'} | sort -u | grep -Fv "/")
do do
#echo -n "$processname; ">>$tmpfile2 grep " ${processname}$" <<< "$pslist"| awk '
ps -ylC $processname | awk '
{x += $8;y += 1; process=$13} {x += $8;y += 1; process=$13}
END {printf "%-15s %10.3f %5s %10.3f\n", process, x/1024, y-1, x/((y-1)*1024)}' 2>/dev/null >>$tmpfile2 END {printf "%-15s %10.0f %5s %10.3f\n", process, x/1024, y, x/(y*1024)}' 2>/dev/null
done | sort -k 2 -n -r
)
done # --- generate output with most consuming processes
# --- check limits out=$(
while read line echo "$pslist2" | while read -r processname iSizeMB processcount
do do
typeset -i iSizeMB=$(echo $line | awk '{ print $2 }' | sed "s#\..*##") test $iSizeMB -lt $iWarnLimit && break
if [ $iSizeMB -ge $iWarnLimit ]; then
processname=$(echo $line | awk '{ print $1 }') test $iSizeMB -ge $iWarnLimit && status="Warning"
processcount=$(echo $line | awk '{ print $3 }') test $iSizeMB -ge $iCriticalLimit && status="Critical"
if [ $iSizeMB -ge $iCriticalLimit ]; then
iCountCritical=$iCountCritical+1 printf "%-9s %-20s %6s MB %4s %10s MB\n" $status $processname $iSizeMB $processcount
echo "Critical: $iSizeMB MB - $processname ($processcount)" >>$outCritical done
else )
iCountWarning=$iCountWarning+1
echo "Warning : $iSizeMB MB - $processname ($processcount)" >>$outWarning iCountCritical=$( grep -c "^Critical" <<< "$out" )
fi iCountWarning=$( grep -c "^Warning" <<< "$out" )
fi
done < $tmpfile2 test $iCountWarning -gt 0 && ph.setStatus "warning"
test $iCountCritical -gt 0 && ph.setStatus "critical"
# --- Status output # --- output
if [ $iCountCritical -gt 0 ]; then ph.status "Memory consuming processes - $iCountCritical processes use ${iCriticalLimit} MB+ (critical) ... $iCountWarning processes use ${iWarnLimit}..${iCriticalLimit} MB"
ph.setStatus "critical" echo "$out"
ph.status "$iCountCritical processes use $iCriticalLimit MB (critical) or more"
echo "$iCountWarning processes use $iWarnLimit MB .. $iCriticalLimit MB"
echo
cat $outCritical | sort -n -k 2 -r
cat $outWarning 2>/dev/null| sort -n -k 2 -r
elif [ $iCountWarning -gt 0 ]; then
ph.setStatus "warning"
ph.status "$iCountWarning processes use $iWarnLimit MB .. $iCriticalLimit MB"
echo
cat $outWarning | sort -n -k 2 -r
else
ph.setStatus "ok"
ph.status "all processes below warning limit $iWarnLimit MB .. (and critical limit $iCriticalLimit MB)"
fi
rm -f $tmpfile $tmpfile2 $outCritical $outWarning 2>/dev/null
ph.exit ph.exit
......
...@@ -37,7 +37,7 @@ There is one include script used by all checks: ...@@ -37,7 +37,7 @@ There is one include script used by all checks:
* [check_opencpu](check_opencpu.md) * [check_opencpu](check_opencpu.md)
* [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](check_proc_mem.md)
* check_proc_ressources * check_proc_ressources
* check_proc_zombie * check_proc_zombie
* [check_psqlserver](check_psqlserver.md) * [check_psqlserver](check_psqlserver.md)
......
# Check memory consuming processes
## Introduction
Show processes that consume the most memory.
You get a list with process name, total usage of all its processes, count of instances.
## Requirements
Nothing special.
## Syntax
```txt
______________________________________________________________________
CHECK_PROC_MEM
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_mem.html
______________________________________________________________________
Show processes that consume the most memory.
You get a list with processes consuming
* more than the critical limit
* between warning and critical limit
SYNTAX:
check_proc_mem [-h] [-c VALUE] [-w VALUE]
OPTIONS:
-h, --help
this help
PARAMETERS:
-c, --critical VALUE
critical level in MB (default: 500)
-w. --warning VALUE
warning level in MB (default: 100)
EXAMPLE:
check_proc_mem
Check processes with initial memory values
check_proc_mem -w 1000 -c 2000
Check processes consuming more than 1000 MB and mark those as critical
that use more than 2000 MB.
```
## Examples
### Default options
`./check_proc_mem` returns
```txt
CRITICAL: Memory consuming processes - 3 processes use 500 MB+ (critical) ... 1 processes use 100..500 MB
Critical mariadbd 2250 MB 1 2250.473 MB
Critical apache2 861 MB 12 71.748 MB
Critical php-fpm8.2 645 MB 37 17.444 MB
Warning icinga2 271 MB 3 90.365 MB
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment