#!/bin/bash
#
#
Usage () {
echo "Usage: $ [types ...] [Limit] "
echo ""
echo "Types is:"
echo "[Size] [RSS] [Swap] [Private] [Shared]"
echo ""
printf "%-12s%-12s\n" "[Size]" "Program mapped memory size, not actually occupied"
printf "%-12s%-12s\n" [Rss] "actually uses memory size (including exclusive + shared)"
printf "%-12s%-12s\n" "[Swap]" "Virtual Memory size used"
printf "%-12s%-12s\n" "[Private]" "Program Exclusive Memory Size"
printf "%-12s%-12s\n" [Shared] "program shares memory size with other processes" echo "
echo "For example: $ Swap 10"
echo ""
}
Mem () {
printf "%-20s%-100s%-20s%-20s\n" "PID" "Pro_name" "SIZE (m)" "%ratio"
For PID in ' ls/proc/|grep ^[0-9] '
Do
If [${pid}-eq 1];then
Continue
Fi
Grep-q $1/proc/${pid}/smaps 2>/dev/null
If [$?-eq 0];then
Memsize= ' free-m |grep "Mem" |awk ' {print $} '
Swapsize= ' free-m |grep "Swap" |awk ' {print $} '
Size= ' cat/proc/$pid/smaps |grep $ |awk ' {sum+=$2;} End{print sum/1024} "
Pro_name= ' ps aux | Grep-w "$pid" | grep-v grep |awk ' {print $11} '
Ratioval () {
If [' $ ' = Swap];then
ratio= ' awk ' begin{print $size/$swapsize *100 \ "%\"} "'
Else
ratio= ' awk ' begin{print $size/$memsize *100 \ "%\"} "'
Fi
Echo $ratio
}
Ratioval
printf "%-20s%-100s%-20s%-20s\n" "${pid}" "${pro_name}" "${size}" "$ratio"
Fi
Done | Sort-n-r-k 3 | Head-$2
}
If [$#-eq 0]; Then
Usage
Else
MEM $
Fi
MySQL Monitoring script