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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
icinga-checks
Commits
0d63d839
Commit
0d63d839
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
proc_resources update help; no temp files
parent
43c3fca4
No related branches found
No related tags found
1 merge request
!227
check_proc_ressources - update check; add doc page
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
check_proc_ressources
+68
-57
68 additions, 57 deletions
check_proc_ressources
with
68 additions
and
57 deletions
check_proc_ressources
+
68
−
57
View file @
0d63d839
...
@@ -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
=
"C
PU
"
unit
=
"C
pu
"
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+
=
$(
for
line
in
$(
ps
-eo
${
scanfield
}
,pid,comm |
awk
-v
limit
=
$iWarnLimit
'$1 > limit {print $1":"$2":"$3 }'
|
sort
-k
1
-t
":"
-n
-r
)
do
do
Value
=
`
echo
$line
|
cut
-f
1
-d
':'
`
iValue
=
`
echo
$line
|
cut
-f
1
-d
':'
|
sed
"s#
\.
.*##"
`
Value
=
$(
echo
$line
|
cut
-f
1
-d
':'
)
iProcessId
=
`
echo
$line
|
cut
-f
2
-d
':'
`
iValue
=
$(
echo
$line
|
cut
-f
1
-d
':'
|
sed
"s#
\.
.*##"
)
processname
=
`
echo
$line
|
cut
-f
3-
-d
':'
`
iProcessId
=
$(
echo
$line
|
cut
-f
2
-d
':'
)
if
[
$iValue
-ge
$iCriticalLimit
]
;
then
processname
=
$(
echo
$line
|
cut
-f
3-
-d
':'
)
iCountCritical
=
$iCountCritical
+1
echo
"Critical:
$Value
%
$unit
by process id
$iProcessId
$processname
"
>>
$outCritical
test
$iValue
-lt
$iCountWarning
&&
break
else
iCountWarning
=
$iCountWarning
+1
test
$iValue
-ge
$iCountWarning
&&
status
=
"Warning"
echo
"Warning :
$Value
%
$unit
by process id
$iProcessId
$processname
"
>>
$outWarning
test
$iValue
-ge
$iCriticalLimit
&&
status
=
"Critical"
fi
# echo "${status}: $Value % $unit by process id $iProcessId $processname"
printf
"%-9s %5s %s %-10s %6s %s
\n
"
${
status
}
$Value
%
$unit
$iProcessId
$processname
done
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
e
grep
'^(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
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
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