Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
icinga-checks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
icinga-checks
Commits
4b6e20f4
Commit
4b6e20f4
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
add help; do not use tmp file anymore; 5..10 times faster
parent
cd4b66b6
No related branches found
No related tags found
1 merge request
!226
update check_proc_mem; add doc page; speedup 5..10 times
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
check_proc_mem
+92
-63
92 additions, 63 deletions
check_proc_mem
with
92 additions
and
63 deletions
check_proc_mem
+
92
−
63
View file @
4b6e20f4
...
@@ -13,91 +13,120 @@
...
@@ -13,91 +13,120 @@
# 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
-2
4
v1.3 <axel.hahn@unibe.ch> add help; do not use tmp file anymore
# 2023-
12
-2
2
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 rum.
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
-d /data/mybackups
Check iso files a given directory
$_self
-d /data/mybackups -w 14 -c 28
Check iso files a given directory and customized limits
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
=
$(
do
for
processname
in
$(
echo
"
$pslist
"
|
awk
{
'print $13'
}
|
sort
-u
|
grep
-Fv
"/"
)
#echo -n "$processname; ">>$tmpfile2
do
ps
-ylC
$processname
|
awk
'
grep
"
${
processname
}
$"
<<<
"
$pslist
"
|
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
)
# --- check limits
# --- generate output with most consuming processes
while
read
line
do
out
=
$(
typeset
-i
iSizeMB
=
$(
echo
$line
|
awk
'{ print $2 }'
|
sed
"s#
\.
.*##"
)
echo
"
$pslist2
"
|
while
read
-r
processname iSizeMB processcount
if
[
$iSizeMB
-ge
$iWarnLimit
]
;
then
do
processname
=
$(
echo
$line
|
awk
'{ print $1 }'
)
test
$iSizeMB
-lt
$iWarnLimit
&&
break
processcount
=
$(
echo
$line
|
awk
'{ print $3 }'
)
if
[
$iSizeMB
-ge
$iCriticalLimit
]
;
then
test
$iSizeMB
-ge
$iWarnLimit
&&
status
=
"Warning"
iCountCritical
=
$iCountCritical
+1
test
$iSizeMB
-ge
$iCriticalLimit
&&
status
=
"Critical"
echo
"Critical:
$iSizeMB
MB -
$processname
(
$processcount
)"
>>
$outCritical
else
printf
"%-9s %-20s %6s MB %4s %10s MB
\n
"
$status
$processname
$iSizeMB
$processcount
iCountWarning
=
$iCountWarning
+1
done
echo
"Warning :
$iSizeMB
MB -
$processname
(
$processcount
)"
>>
$outWarning
)
fi
fi
iCountCritical
=
$(
grep
-c
"^Critical"
<<<
"
$out
"
)
done
<
$tmpfile2
iCountWarning
=
$(
grep
-c
"^Warning"
<<<
"
$out
"
)
test
$iCountWarning
-gt
0
&&
ph.setStatus
"warning"
# --- Status output
test
$iCountCritical
-gt
0
&&
ph.setStatus
"critical"
if
[
$iCountCritical
-gt
0
]
;
then
# --- output
ph.setStatus
"critical"
ph.status
"
$iCountCritical
processes use
$iCriticalLimit
MB (critical) or more"
ph.status
"Memory consuming processes -
$iCountCritical
processes use
${
iCriticalLimit
}
MB+ (critical) ...
$iCountWarning
processes use
${
iWarnLimit
}
..
${
iCriticalLimit
}
MB"
echo
"
$iCountWarning
processes use
$iWarnLimit
MB ..
$iCriticalLimit
MB"
echo
"
$out
"
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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment