一般用top監控,如果想要留記錄來比較,可能會覺得不太方便,以下是可以留一個時間跟資料內容來當成追蹤記錄
top -S -b -p $(pidof XGateway) grep -e XGateway -e average
[結果]
top - 16:13:11 up 42 days, 21:00, 4 users, load average: 1.11, 1.19, 1.17
31555 cts 15 0 227m 60m 8416 S 0.0 1.6 0:12.54 XGateway
top - 16:13:14 up 42 days, 21:00, 4 users, load average: 1.10, 1.18, 1.17
31555 cts 15 0 227m 60m 8416 S 0.0 1.6 0:12.54 XGateway
top - 16:13:17 up 42 days, 21:00, 4 users, load average: 1.41, 1.25, 1.19
31555 cts 15 0 227m 60m 8416 S 0.0 1.6 0:12.54 XGateway
top - 16:13:20 up 42 days, 21:00, 4 users, load average: 1.41, 1.25, 1.19
31555 cts 15 0 227m 60m 8416 S 0.0 1.6 0:12.54 XGateway
top - 16:13:23 up 42 days, 21:00, 4 users, load average: 1.46, 1.26, 1.20
[root@RH20 cts]# cat top.sh#!/bin/bash
pidd=$(pidof XGateway)
while [ 1 ]
do
#Solaris不適用
echo "$(date +%H:%M:%S) $(top -n1 -S -b -p $pidd | grep -e XGateway )"
usleep 500000
done
[結果]17:01:19 31555 cts 15 0 227m 60m 8416 S 0.0 1.6 0:15.84 XGateway
17:01:20 31555 cts 15 0 227m 60m 8416 S 0.0 1.6 0:15.84 XGateway
17:01:21 31555 cts 15 0 227m 60m 8416 S 0.0 1.6 0:15.84 XGateway
17:01:22 31555 cts 15 0 227m 60m 8416 S 0.0 1.6 0:15.84 XGateway
17:01:23 31555 cts 15 0 227m 60m 8416 S 0.0 1.6 0:15.84 XGateway
17:01:24 31555 cts 15 0 227m 60m 8416 S 0.0 1.6 0:15.84 XGateway
17:01:25 31555 cts 15 0 227m 60m 8416 S 0.0 1.6 0:15.84 XGateway
17:01:26 31555 cts 15 0 227m 60m 8416 S 0.0 1.6 0:15.84 XGateway
17:01:27 31555 cts 15 0 227m 60m 8416 S 0.0 1.6 0:15.84 XGateway
17:01:28 31555 cts 15 0 227m 60m 8416 S 0.0 1.6 0:15.84 XGateway
17:01:29 31555 cts 15 0 227m 60m 8416 S 0.0 1.6 0:15.84 XGateway
17:01:30 31555 cts 15 0 227m 60m 8416 S 0.0 1.6 0:15.84 XGateway
[root@RH20 cts]# cat vmstat.sh#!/bin/bash
#pidd=$(pidof XGateway)
while [ 1 ]
do
str="$(vmstat 1 2| tail -n 1)"
#在solaris這行要改成 "$(vmstat 1 2 | tail -1l)"
echo "$(date +%H:%M:%S) $str"
done
[結果][root@RH20 cts]# ./vmstat.sh
20:21:02 0 0 896 1011492 325056 2152676 0 0 0 0 1006 4532 2 3 96 0 0
20:21:03 0 0 896 1011616 325056 2152676 0 0 0 260 1059 4558 1 2 97 0 0
20:21:04 0 0 896 1011616 325056 2152684 0 0 0 0 1004 4759 1 2 97 0 0
20:21:05 2 0 896 1011616 325056 2152684 0 0 0 0 1010 2977 1 1 98 0 0
[root@RH20 cts]# cat iostat.sh
#==================================================
# you must install sysstat-* rpm for iostat
#==================================================
#iostat有不同版本,取得字串的行數就會不一樣
iostatver=$(iostat -V &> /dev/stdout | grep sysstat)
if [ "$iostatver" != "" ]; then
ntail=2
nhead=1
else
ntail=1
nhead=1
fi
if [ "$1" != "" ]; then
device="$1"
else
device="sda"
fi
while [ 1 ]
do
strdate=$(date +%H:%M:%S)
#strstr=$(iostat -x $1 $2 $3 $4 $5 1 2 | tail -n $ntail | head -n $nhead | awk 'NR==1{ printf " %s %s\n","########",$0} NR>=2{printf " %s %s\n"," ",$0}' | sed 's/########/'${strdate}'/')
strstr=$(iostat -x $device 3 2 | tail -n $ntail | head -n $nhead | awk 'NR==1{ printf " %s %s\n","########",$0} NR>=2{printf " %s %s\n"," ",$0}' | sed 's/########/'${strdate}'/')
echo "$strstr"
done
[結果]RH20 /home/cts>./iostat.sh sda
13:58:58 sda 0 1 0.0 3.0 0.0 16.0 5.3 0.0 0.0 0.0 0
13:58:59 sda 0 0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0
13:59:00 sda 0 33 0.0 12.0 0.0 192.0 16.0 0.2 18.9 2.0 2
沒有留言:
張貼留言