由 top指令得到 mysql的 CPU百分值
top -b -u mysql -n1 | grep mysqld | awk '{print $9}'
free指令取得記憶體容使用量
#!/bin/bashmemtotal=`free -m | grep "Mem:" | awk '{print $2}'`
memused=`free -m | grep "Mem:" | awk '{print $3}'`
memfree=`free -m | grep "Mem:" | awk '{print $4}'`echo $memused
echo $memfree
echo $memtotal
vi mrtg-mem.cfg
WorkDir: /var/www/mrtg/mem
Target[10.1.1.254_mem]: `/etc/mrtg/mrtg-mem.sh`
RouterUptime[10.1.1.254_mem]: [email protected]
MaxBytes[10.1.1.254_mem]: 512
Directory[10.1.1.254_mem]: 254mem
WithPeak[10.1.1.254_mem]: wmy
Options[10.1.1.254_mem]: growright, nopercent, gauge
YLegend[10.1.1.254_mem]: amount
ShortLegend[10.1.1.254_mem]: mb
Legend1[10.1.1.254_mem]: amount of used memory
Legend2[10.1.1.254_mem]: amount of free memory
Legend3[10.1.1.254_mem]: amount of total memory
Legend4[10.1.1.254_mem]: amount of ? memory
LegendI[10.1.1.254_mem]: Used:
LegendO[10.1.1.254_mem]: Free:
Title[10.1.1.254_mem]: amount of free and used memory
PageTop[10.1.1.254_mem]: <H1>amount of free and used memory[10.1.1.254] – free</H1>
netstat指令取得 httpd人數
Quote: http://linux.vbird.org/linux_security/old/04mrtg.php#online
vi mrtg-http.sh
#!/bin/bash
# 程式主要在計算有多少人以 WWW 的方式連線進主機
# 1. 計算連線的數目
echo `netstat -a | grep www|awk '{print $5}'|sort | wc -l|awk '{print$1 – 1}'`
# 底下在說明整個的列出(檢查用)
# netstat -a | grep www|awk '{print $5}'|sort| uniq
# 2. 計算連線人數:
echo `netstat -a | grep www|awk '{print $5}'|cut -d":" -f1|sort| uniq |wc -l | awk '{print $1 – 1}'`
# netstat -a | grep www|awk '{print $5}'|cut -d":" -f1|sort| uniq
# 3. 輸出時間
UPtime=`/usr/bin/uptime | awk '{print $3 " " $4 " " $5}'`
echo $UPtime
echo 10.10.1.100
留言