MySQL監控指令碼

來源:互聯網
上載者:User

標籤:rss   nbsp   sort   $#   types   bsp   share   dev   end   

#!/bin/bash
#
#

usage() {
echo "Usage: $0 [ types... ] [ limit ] "
echo ""
echo "Types are:"
echo "[ Size ] [ Rss ] [ Swap ] [ Private ] [ Shared ]"
echo ""
printf "%-12s%-12s\n" "[ Size ]" "程式映射的記憶體大小,非實際佔用"
printf "%-12s%-12s\n" "[ Rss ]" "實際使用記憶體大小(包括獨佔+共用)"
printf "%-12s%-12s\n" "[ Swap ]" "使用的虛擬記憶體大小"
printf "%-12s%-12s\n" "[ Private ]" "程式獨佔記憶體大小"
printf "%-12s%-12s\n" "[ Shared ]" "程式與其他進程共用記憶體大小"echo ""
echo "For example : $0 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 $2}‘`
    swapsize=`free -m |grep "Swap" |awk ‘{print $2}‘`
    size=`cat /proc/$pid/smaps |grep $1 |awk ‘{sum+=$2;} END{print sum/1024}‘`
    pro_name=`ps aux | grep -w "$pid" | grep -v grep  |awk ‘{print $11}‘`
    ratioval() {
    if [ ‘$1‘ = 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 $1 $2
fi

MySQL監控指令碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.