Linux上使用shell指令碼查看記憶體情況(超實用),linuxshell

來源:互聯網
上載者:User

Linux上使用shell指令碼查看記憶體情況(超實用),linuxshell

#!/bin/bash
export chknum=1

#shell攪拌存放目錄(輸出記錄檔執行後也存於該目錄)
echo 3 > /wls/wls81/shell
sync
while [ $chknum -ge 0 ]
do
echo "-------------------------------------------------------" >> trace.log
mt=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '1p'`
mu=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '2p'`
mf=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '3p'`
st=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '9p'`
su=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '10p'`
sf=`free | tr [:blank:] \\\n | grep [0-9] | sed -n '11p'`
t=`expr $mt + $st`
u=`expr $mu + $su`
echo "Total Mem: $t"
echo "Used Mem: $u"
R=`expr $mu \* 100 / $mt`
echo "當前記憶體使用量率為: $R%" >>trace.log

#開始釋放記憶體(只檢測不操作可把此段斃掉)
if [ $R -gt 80 ]
then
echo "the monitor is more,please clean"

#執行記憶體>80%時清除,以下規則可自行修改
ps -ef|grep java |cut -c 9-15|xargs kill -9
fi

#釋放結束

echo "$R" >> memory.log
echo "記錄時間:" >> trace.log
echo `date` >> trace.log
echo "-------------------------------------------------------" >> trace.log
sleep 24h
done

 

 

 

 

********************我是帥氣的分割線***********************

 

指令碼搞好後、放入Jenkins設定定時任務。指定time每天跑一次就行啦。再也不怕環境每天因為記憶體問題掛掉了

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.