Last active
October 16, 2015 05:53
-
-
Save non7top/d9f70eccbedb6af581b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# IMPORTANT: | |
# by default outputs physical memory | |
# - Linux only | |
# - User which is running the script should have | |
# same primary group as the one running oracle, | |
# otherwise ipcs will report 0 instead of | |
# actual shared memory. Being in the same | |
# groups may be not be enough | |
MEM_TOTAL=$( free -k|awk '/Mem/ {m=$2 * 1024; printf("%d", m)}' ) | |
MEM_USED1=$( free -k|awk '/Mem/ {m=$3 * 1024; printf("%d", m)}' ) | |
BUFF_USED=$( free -k|awk '/Mem/ {m=$6 * 1024; printf("%d", m)}' ) | |
SHARED_USED=$( ipcs -m|awk '/0x/ {sum +=$5}; END {print sum}' ) | |
SHARED_USED2=$( df -P -B1 /dev/shm|tail -n1 |awk '{print $3}' ) | |
FREE=$( free -b|awk '/Mem/ {print $4}' ) | |
CACHED=$( free -b | awk '/Mem/ {print $7}' ) | |
#let MEM_USED=$MEM_USED1+$SHARED_USED+$SHARED_USED2+$BUFF_USED | |
let MEM_FREE=$FREE+$CACHED-$SHARED_USED-$SHARED_USED2 | |
let MEM_USED=$MEM_TOTAL-$MEM_FREE | |
let MEM_USED_PRC=$MEM_USED*100/$MEM_TOTAL | |
let MEM_FREE_MB=$MEM_FREE/1024/1024 | |
#let MEM_FREE_MB=($MEM_TOTAL-$MEM_USED)/1024/1024 | |
#echo "PRC=$MEM_USED_PRC FREE=$MEM_FREE_MB" | |
SWAP_TOTAL=$( free -b|awk '/Swap/ {print $2}' ) | |
SWAP_USED=$( free -b|awk '/Swap/ {print $3}' ) | |
let SWAP_USED_PRC=$SWAP_USED*100/$SWAP_TOTAL | |
let SWAP_FREE_MB=($SWAP_TOTAL-$SWAP_USED)/1024/1024 | |
let VIRT_TOTAL=$MEM_TOTAL+$SWAP_TOTAL | |
let VIRT_USED=$MEM_USED+$SWAP_USED | |
let VIRT_USED_PRC=$VIRT_USED*100/$VIRT_TOTAL | |
let VIRT_FREE=($VIRT_TOTAL-$VIRT_USED)/1024/1024 | |
case "$1" in | |
virt*) echo "$VIRT_USED_PRC $VIRT_FREE";; | |
swap) echo "$SWAP_USED_PRC $SWAP_FREE_MB";; | |
*) echo "$MEM_USED_PRC $MEM_FREE_MB";; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment