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
88521145
Commit
88521145
authored
3 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
add cli param -p
parent
ac68cb85
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
check_cpu
+33
-19
33 additions, 19 deletions
check_cpu
check_memory
+74
-31
74 additions, 31 deletions
check_memory
with
107 additions
and
50 deletions
check_cpu
+
33
−
19
View file @
88521145
...
...
@@ -16,13 +16,16 @@
# 2021-10-28 v1.5 <axel.hahn@iml.unibe.ch> Use 2nd update of top
# 2021-12-10 v1.6 <axel.hahn@iml.unibe.ch> show processes with status D to find cpu waits
# 2022-03-09 v1.7 <axel.hahn@iml.unibe.ch> show most cpu intensive processes
# 2022-03-10 v1.8 <axel.hahn@iml.unibe.ch> add cli param -p; update help
# ======================================================================
.
`
dirname
$0
`
/inc_pluginfunctions
tmpfile
=
/tmp/check_cpu_
$$
.
$(
dirname
$0
)
/inc_pluginfunctions
self_APPNAME
=
$(
basename
$0
|
tr
[
:lower:]
[
:upper:]
)
self_APPVERSION
=
1.8
iMinCpuUsageToShowProcesses
=
30
tmpfile
=
/tmp/check_cpu_
$$
# ----------------------------------------------------------------------
# functions
...
...
@@ -32,17 +35,18 @@ function showHelp(){
cat
<<
EOF
______________________________________________________________________
CHECK_CPU check cpu usage and cpu wait v1.7
$self_APPNAME
v
$self_APPVERSION
(c) Institute for Medical Education - Univerity of Bern
Licence: GNU GPL 3
______________________________________________________________________
check cpu usage and cpu wait
Cpu infos are taken from output of top command.
SYNTAX:
`
basename
$0
`
[-w WARN_LIMIT] [-c CRITICAL_LIMIT] [-i CRITICAL_IO_WAIT]
$(
basename
$0
)
[-w WARN_LIMIT] [-c CRITICAL_LIMIT] [-i CRITICAL_IO_WAIT]
[-p PROCESS_LIMIT]
OPTIONS:
...
...
@@ -51,6 +55,9 @@ OPTIONS:
-i VALUE io wait critical level (default: 50)
-p VALUE show process info with highest cpu consumption if
usage is > NN %; default: 50
-h or --help show this help.
PARAMETERS:
...
...
@@ -58,7 +65,7 @@ PARAMETERS:
None.
EXAMPLE:
`
basename
$0
`
-w 60 -c 80 -i 40
$(
basename
$0
)
-w 60 -c 80 -i 40
EOF
}
...
...
@@ -79,11 +86,15 @@ case "$1" in
*
)
esac
# ----------------------------------------------------------------------
# set default / override from command line params
typeset
-i
iWarnLimit
=
`
ph.getValueWithParam 75 w
"
$@
"
`
typeset
-i
iCriticalLimit
=
`
ph.getValueWithParam 90 c
"
$@
"
`
typeset
-i
iCriticalWait
=
`
ph.getValueWithParam 50 i
"
$@
"
`
typeset
-i
iWarnLimit
=
$(
ph.getValueWithParam 75 w
"
$@
"
)
typeset
-i
iCriticalLimit
=
$(
ph.getValueWithParam 90 c
"
$@
"
)
typeset
-i
iCriticalWait
=
$(
ph.getValueWithParam 50 i
"
$@
"
)
typeset
-i
iMinCpuUsageToShowProcesses
=
$(
ph.getValueWithParam 50 p
"
$@
"
)
# ----------------------------------------------------------------------
# get data
# get cpu status i.e.
# %Cpu(s): 33.3 us, 9.5 sy, 0.0 ni, 57.1 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
...
...
@@ -99,15 +110,15 @@ typeset -i iCriticalWait=` ph.getValueWithParam 50 i "$@"`
# FIX read cpu from 2nd output of top
top
-b
-n
2
-d
0.1 |
grep
-i
"^
\%
Cpu"
|
tail
-1
>
$tmpfile
cpuUser
=
`
awk
'{ print $2 }'
$tmpfile
`
cpuSystem
=
`
awk
'{ print $4 }'
$tmpfile
`
cpuNice
=
`
awk
'{ print $6 }'
$tmpfile
`
cpuIdle
=
`
awk
'{ print $8 }'
$tmpfile
`
cpuWait
=
`
awk
'{ print $10 }'
$tmpfile
`
cpuHi
=
`
awk
'{ print $12 }'
$tmpfile
`
cpuSi
=
`
awk
'{ print $14 }'
$tmpfile
`
cpuSt
=
`
awk
'{ print $16 }'
$tmpfile
`
cpuNonIdle
=
`
echo
100-
$cpuIdle
| bc
`
cpuUser
=
$(
awk
'{ print $2 }'
$tmpfile
)
cpuSystem
=
$(
awk
'{ print $4 }'
$tmpfile
)
cpuNice
=
$(
awk
'{ print $6 }'
$tmpfile
)
cpuIdle
=
$(
awk
'{ print $8 }'
$tmpfile
)
cpuWait
=
$(
awk
'{ print $10 }'
$tmpfile
)
cpuHi
=
$(
awk
'{ print $12 }'
$tmpfile
)
cpuSi
=
$(
awk
'{ print $14 }'
$tmpfile
)
cpuSt
=
$(
awk
'{ print $16 }'
$tmpfile
)
cpuNonIdle
=
$(
echo
100-
$cpuIdle
| bc
)
rm
-f
$tmpfile
...
...
@@ -128,6 +139,9 @@ else
fi
fi
# ----------------------------------------------------------------------
# output
# --- status output
ph.status
"CPU-USAGE [%]
${
cpuNonIdle
}
... user:
${
cpuUser
}
- system:
${
cpuSystem
}
- idle:
${
cpuIdle
}
- wait:
${
cpuWait
}
"
...
...
This diff is collapsed.
Click to expand it.
check_memory
+
74
−
31
View file @
88521145
...
...
@@ -23,12 +23,14 @@
# 2020-07-16 v1.4 <axel.hahn@iml.unibe.ch> FIX: add unit MB in the performance data (see #3939)
# 2021-03-24 v1.5 <axel.hahn@iml.unibe.ch> increase Swap critical limit 5 --> 50
# 2022-03-09 v1.6 <axel.hahn@iml.unibe.ch> show most ram intensive processes
# 2022-03-10 v1.7 <axel.hahn@iml.unibe.ch> add cli param -p; update help
# ======================================================================
.
`
dirname
$0
`
/inc_pluginfunctions
.
$(
dirname
$0
)
/inc_pluginfunctions
iMinRamUsageToShowProcesses
=
30
self_APPNAME
=
$(
basename
$0
|
tr
[
:lower:]
[
:upper:]
)
self_APPVERSION
=
1.7
# ----------------------------------------------------------------------
# FUNCTIONS
...
...
@@ -38,58 +40,96 @@ iMinRamUsageToShowProcesses=30
# /proc/meminfo conatains values in kB - it is divided by 1024
# --> return values are MB
function
getMemvalue
(){
echo
`
grep
"^
$1
:"
/proc/meminfo |
awk
'{ print $2 }'
`
/ 1024 | bc
echo
$(
grep
"^
$1
:"
/proc/meminfo |
awk
'{ print $2 }'
)
/ 1024 | bc
}
function
showHelp
(){
cat
<<
EOF
______________________________________________________________________
$self_APPNAME
v
$self_APPVERSION
(c) Institute for Medical Education - Univerity of Bern
Licence: GNU GPL 3
______________________________________________________________________
Check memory usage incl. free, used and total memory.
On higher memory usage the process table with top 5 top consumers will
be shown.
SYNTAX:
$(
basename
$0
)
[-w WARN_LIMIT] [-c CRITICAL_LIMIT] [-s SWAP_LIMIT] [-p PROCESS_LIMIT] [-h]
OPTIONS:
-w VALUE Warning level for RAM usage [%]; default: 75
-c VALUE Critical level for RAM usage; default: 90
-s VALUE Critical level for SWAP usage; default: 50
-p VALUE show process info with highest memory consumption if
usage is > NN %; default: 50
-h or --help show this help.
PARAMETERS:
none
EXAMPLE:
$(
basename
$0
)
-w 90 -c 95 -p 70
EOF
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
case
"
$1
"
in
"--help"
|
"-h"
)
showHelp
exit
0
;;
*
)
esac
# --- check required tools
ph.require bc
# --- check param -h
if
[
"
$1
"
=
"-h"
]
;
then
echo
"
usage:
$0
[ -w value -c value -h ]
-w Warning level for RAM usage [%]; default: 75
-c Critical level for RAM usage; default: 90
-s Critical level for SWAP usage; default: 50
-h this help
"
exit
0
fi
# ----------------------------------------------------------------------
# set default / override from command line params
typeset
-i
iWarnLimit
=
`
ph.getValueWithParam 75 w
"
$@
"
`
typeset
-i
iCriticalLimit
=
`
ph.getValueWithParam 90 c
"
$@
"
`
typeset
-i
iCriticalSwap
=
`
ph.getValueWithParam 50 s
"
$@
"
`
typeset
-i
iWarnLimit
=
$(
ph.getValueWithParam 75 w
"
$@
"
)
typeset
-i
iCriticalLimit
=
$(
ph.getValueWithParam 90 c
"
$@
"
)
typeset
-i
iCriticalSwap
=
$(
ph.getValueWithParam 50 s
"
$@
"
)
typeset
-i
iMinRamUsageToShowProcesses
=
$(
ph.getValueWithParam 50 p
"
$@
"
)
# ----------------------------------------------------------------------
# read values
# --- RAM
typeset
-i
ramTotal
=
`
getMemvalue MemTotal
`
typeset
-i
ramAvail
=
`
getMemvalue MemAvailable
`
typeset
-i
ramTotal
=
$(
getMemvalue MemTotal
)
typeset
-i
ramAvail
=
$(
getMemvalue MemAvailable
)
typeset
-i
ramUsed
=
$ramTotal
-
$ramAvail
typeset
-i
ramFree
=
`
getMemvalue MemFree
`
typeset
-i
ramBuffers
=
`
getMemvalue Buffers
`
typeset
-i
ramCached
=
`
getMemvalue Cached
`
typeset
-i
ramSReclaim
=
`
getMemvalue SReclaimable
`
typeset
-i
ramFree
=
$(
getMemvalue MemFree
)
typeset
-i
ramBuffers
=
$(
getMemvalue Buffers
)
typeset
-i
ramCached
=
$(
getMemvalue Cached
)
typeset
-i
ramSReclaim
=
$(
getMemvalue SReclaimable
)
typeset
-i
ramUsage
=
`
echo
"(
$ramUsed
) *100 /
$ramTotal
"
| bc
`
typeset
-i
ramUsage
=
$(
echo
"(
$ramUsed
) *100 /
$ramTotal
"
| bc
)
# --- Swap
typeset
-i
swapTotal
=
`
getMemvalue SwapTotal
`
typeset
-i
swapFree
=
`
getMemvalue SwapFree
`
typeset
-i
swapCached
=
`
getMemvalue SwapCached
`
typeset
-i
swapTotal
=
$(
getMemvalue SwapTotal
)
typeset
-i
swapFree
=
$(
getMemvalue SwapFree
)
typeset
-i
swapCached
=
$(
getMemvalue SwapCached
)
typeset
-i
swapUsage
=
0
if
[
$swapTotal
-gt
0
]
;
then
swapUsage
=
`
echo
"(
$swapCached
)*100 /
$swapTotal
"
| bc
`
swapUsage
=
$(
echo
"(
$swapCached
)*100 /
$swapTotal
"
| bc
)
fi
# --- set status
# ----------------------------------------------------------------------
# set status
ph.setStatusByLimit
$ramUsage
$iWarnLimit
$iCriticalLimit
# if [ $swapCached -gt 0 ]; then
if
[
$swapUsage
-ge
$iCriticalSwap
]
;
then
...
...
@@ -102,6 +142,9 @@ else
ph.status
"RAM usage
$ramUsage
% of
$ramTotal
MB (machine has no Swap)"
fi
# ----------------------------------------------------------------------
# output
# --- show details
echo
cat
/proc/meminfo | egrep
"^(Mem|Cache|Buffers|Swap|Slab|SReclaimable)"
...
...
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