MySQL Monitoring script

Source: Internet
Author: User

#!/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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.