root / plugins / memory / memory_osx @ 0b7a005e
Historique | Voir | Annoter | Télécharger (1,67 ko)
| 1 |
#!/bin/sh |
|---|---|
| 2 |
# -*- sh -*- |
| 3 |
|
| 4 |
# shellcheck disable=SC2046 |
| 5 |
|
| 6 |
: << =cut |
| 7 |
|
| 8 |
=head1 NAME |
| 9 |
|
| 10 |
memory - Plugin to measure memory on osx. |
| 11 |
|
| 12 |
=head1 NOTES |
| 13 |
|
| 14 |
This plugin runs the top command once per interval, to discover memory usage on OSX. |
| 15 |
Contributions are welcome to collect additional memory regions, if possible, such as buffers and caches. |
| 16 |
|
| 17 |
=head1 LICENSE |
| 18 |
|
| 19 |
GPLv2 |
| 20 |
|
| 21 |
=head1 MAGIC MARKERS |
| 22 |
|
| 23 |
#%# family=auto |
| 24 |
#%# capabilities=autoconf |
| 25 |
|
| 26 |
=cut |
| 27 |
|
| 28 |
if [ "$1" = "autoconf" ]; then |
| 29 |
if [ "$(uname)" = "Darwin" ]; then |
| 30 |
echo yes |
| 31 |
exit 0 |
| 32 |
else |
| 33 |
echo "no (uname does not report 'Darwin')" |
| 34 |
exit 0 |
| 35 |
fi |
| 36 |
fi |
| 37 |
|
| 38 |
TOTALMEM=$(sysctl hw.memsize | cut -d" " -f2) |
| 39 |
graphlimit=$TOTALMEM |
| 40 |
|
| 41 |
dehumanise() {
|
| 42 |
echo "$1" | sed -e "s/K/*1024/g;s/M/*1024*1024/;s/G/*1024*1024*1024/;s/T/*1024*1024*1024*1024/" |
| 43 |
} |
| 44 |
|
| 45 |
if [ "$1" = "config" ]; then |
| 46 |
echo 'graph_title Memory' |
| 47 |
echo "graph_order used wired unused" |
| 48 |
echo "graph_args --base 1024 -r --lower-limit 0 --upper-limit $graphlimit" |
| 49 |
echo 'graph_vlabel Bytes' |
| 50 |
echo 'graph_category system' |
| 51 |
echo 'used.label used (not incl. wired)' |
| 52 |
echo 'used.draw AREA' |
| 53 |
echo 'used.min 0' |
| 54 |
echo "used.info Used memory, not including wired" |
| 55 |
echo 'wired.label wired' |
| 56 |
echo 'wired.draw STACK' |
| 57 |
echo 'wired.min 0' |
| 58 |
echo 'wired.info Wired memory' |
| 59 |
|
| 60 |
exit 0 |
| 61 |
fi |
| 62 |
|
| 63 |
TOPINFO=$(top -l 1 | grep "PhysMem: ") |
| 64 |
MEM_USED=$(echo "$TOPINFO" | awk '/PhysMem: / { print substr($2, 1, length($2)) }')
|
| 65 |
MEM_WIRED=$(echo "$TOPINFO" | awk '/PhysMem: / { print substr($4, 2, length($4)-1) }')
|
| 66 |
echo "used.value" $(( $(dehumanise "$MEM_USED") - $(dehumanise "$MEM_WIRED") )) |
| 67 |
echo "wired.value" $(( $(dehumanise "$MEM_WIRED") )) |
