-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcheck_mem
executable file
·64 lines (59 loc) · 1.42 KB
/
check_mem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
#
# Check for high memory usage on an Illumos
# based machine
#
# Not typically a problem in itself, but can
# indicate future problems
#
# Author: Dave Eddy <dave@voxer.com>
# Creation Date: 9/14/2012
# 01/10/2014 Added check for global zone (Napsty)
# License: MIT
rss_and_cap() {
local name value
if [[ $(zonename) == 'global' ]]; then
local pagesize=$(pagesize)
while read name value; do
IFS=: read _ _ _ name <<< "$name"
local "$name"
read "$name" <<< "$value"
done < <(kstat -p unix::system_pages:{availrmem,freemem,physmem})
echo "$(((availrmem - freemem) * pagesize)) $((physmem * pagesize))"
else
while read name value; do
IFS=: read _ _ _ name <<< "$name"
local "$name"
read "$name" <<< "$value"
done < <(kstat -pc zone_memory_cap :::rss :::physcap)
echo "$rss $physcap"
fi
}
warning=90
critical=95
perfdata=true
while getopts 'nw:c:' option; do
case "$option" in
n) perfdata=false;;
w) warning=$OPTARG;;
c) critical=$OPTARG;;
esac
done
read rss cap < <(rss_and_cap)
perc_used=$((rss * 100 / cap))
if [[ -z $perc_used ]]; then
echo 'unknown: error retrieving data'
exit 3
elif ((perc_used >= critical)); then
echo -n 'critical: '
ret=2
elif ((perc_used >= warning)); then
echo -n 'warning: '
ret=1
else
echo -n 'ok: '
ret=0
fi
echo -n "$perc_used% used (warning=$warning%, critical=$critical%)"
$perfdata && echo "|mem_used=$rss;mem_cap=$cap" || echo
exit "$ret"