主機日常效能資料採集

tolilong發表於2015-08-17
對於我們日常的維護和分析來說,儲存一份主機日常效能採集的資料是非常有必要的。可以讓我們在事後檢視需要檢視的那段時間的主機資源使用情況,也可以據此,我們來做一份分析報告。

1、AIX平臺
在AIX平臺下,我們可以藉助nmon工具很方便的實現這個需求。我們需要做的就是上傳nmon工具,然後在crontab中部署一個計劃任務。
0 0 * * * cd /home/xigua ; ./nmon_aix53 -x >> nmon.log 2>&1
-x代表每隔15分鐘做一次取樣,當然如果你認為這個頻率太低,可以修改。
例如:
0 0 * * * nmon64 -ft -D -E -I 1 -s 120 -c 720 -m /aixpatch/nmon_out
改成2分鐘採集一次,每天採集720次。


2、HP-UNIX平臺
在hp-unix下面比較麻煩一點,我們需要自己來寫採集的指令碼。指令碼主要是呼叫glance來採集資料。
定義的crontab如下:
0 0 * * * cd /glance; ./glance.sh
/glance# more glance.sh
#
# This scripts use glance plus to monitor the performance .
#
#
#
#!/sbin/sh
HOST=`hostname`
DAY=`date '+%Y%m%d'`
cd /glance/
# NETWORK INTERFACE LOOP
nohup /opt/perf/bin/glance -adviser_only -nosort -iterations 288 -j 300 -syntax ./net.adviser >>./log/net_${HOS
T}_${DAY}.log &

# SYSTEM LOOP
nohup /opt/perf/bin/glance -adviser_only -nosort -iterations 288 -j 300 -syntax ./sys.adviser >>./log/sys_${HOS
T}_${DAY}.log &

#PROCESS LOOP
nohup /opt/perf/bin/glance -adviser_only -nosort -iterations 288 -j 300 -syntax ./process.adviser >>./log/proce
ss_${HOST}_${DAY}.log &

#DISK LOOP
nohup /opt/perf/bin/glance -adviser_only -nosort -iterations 288 -j 300 -syntax ./disk.adviser >>./log/disk_${H
OST}_${DAY}.log &

這個指令碼負責呼叫4個模組的資料採集,採集的頻率是5分鐘。4個模組的採集資料定義如下 :
cat sys.adviser
# This adviser script. prints the global cpu/disk/mem/swap utilization and also
# the network subsystem wait percent for the interval.

headers_printed=headers_printed


IF headers_printed == 0 THEN
{
print "                       CPU    SYS   USER   DISK       PHY_READ      PHY_WRITE    MEM     SWAP  Network"
print " Date      Time       Util   Util   Util   Util           RATE           RATE   Util     Util   Wait %"
print "------------------------------------------------------------------------------------------------------"
headers_printed=1
}

print GBL_STATDATE," ",GBL_STATTIME," ",
          GBL_CPU_TOTAL_UTIL," ",GBL_CPU_SYS_MODE_UTIL," ",GBL_CPU_USER_MODE_UTIL," ",
          GBL_DISK_UTIL_PEAK," ",GBL_DISK_PHYS_READ_BYTE_RATE,"KBs ",GBL_DISK_PHYS_WRITE_BYTE_RATE,"KBs ",
          GBL_MEM_UTIL,"   ",
          GBL_SWAP_SPACE_UTIL," ",
          GBL_NETWORK_SUBSYSTEM_WAIT_PCT

/glance# cat net.adviser
# This version will only work with hp-ux 11.x.If you want it to
# work for 10.20 you need to remove the "BYNETIF_QUEUE," string
# below as that metric is only available from 11.x glance.

# The following string variable should be changed to the interface
# of interest. For example:
# netif_to_examine = "lan0"
# If you want to see all interfaces, leave it an empty string (""):
# netif_to_examine = ""
# initialize variables:
# headers_printed=headers_printed
netif_to_examine=""

# print headers before the loop
print "                     NetIF               NetIn      NetOut        Net        Net"
print "  Date     Time       Name             bytes/s     bytes/s  COLLISION      ERROR"
print "----------------------------------------------------------------------------------"

# begin loop
netif loop
{
# print information for the selected interface or if null then all:
        IF (BYNETIF_NAME == netif_to_examine) or (netif_to_examine == "") THEN
        {
                IF BYNETIF_IN_BYTE_RATE > 0 or BYNETIF_OUT_BYTE_RATE > 0 THEN
                {
# print one line per interface reported which has byte_rate > 0:
                print GBL_STATDATE," ",GBL_STATTIME,"   ",BYNETIF_NAME," ",
                                  BYNETIF_IN_BYTE_RATE," ",BYNETIF_OUT_BYTE_RATE," ",
                                  BYNETIF_COLLISION," ",BYNETIF_ERROR
                }
# (note that some interface types do not report collisions or errors)
        }
}
print ""

/glance# cat disk.adviser
#
# This adviser is used for capture the disk infomation .
#

# print headers before the loop
print "                        Mounted           DISK RESPONSE       PHY_READ      PHY_WRITE  DISK "
print "  Date     Time      Filesystem           IOPS     TIME           RATE           RATE  Util "
print "-------------------------------------------------------------------------------------------------"
DISK LOOP
if BYDSK_DIRNAME != "Unknown" and
(BYDSK_PHYS_READ_BYTE_RATE > 0
OR BYDSK_PHYS_WRITE_BYTE_RATE > 0
OR BYDSK_UTIL > 0)then {
print
GBL_STATDATE," ",GBL_STATTIME," ",
BYDSK_DIRNAME|15|0,BYDSK_PHYS_IO_RATE,BYDSK_AVG_SERVICE_TIME,"ms ",
BYDSK_PHYS_READ_BYTE_RATE,"KBs ",BYDSK_PHYS_WRITE_BYTE_RATE,"KBs",
BYDSK_UTIL
}


/glance# cat process.adviser

#
# This adviser is used to capture the process infomation .
#

# print headers before the loop
print "                                                                   PROC  PROC  "
print "                      PORC     PROC       PROC       PROC   PROC    LOG   PHY        PHY_IO   PROC "
print "  Date     Time      OWNER       ID        MEM   MEM_HIGH    CPU   IOPS  IOPS          RATE   NAME "
print "-----------------------------------------------------------------------------------------------------"

PROCESS LOOP
if PROC_MEM_RES > 100000 then {
print
GBL_STATDATE," ",GBL_STATTIME," ",
PROC_USER_NAME,PROC_PROC_ID|7|0," ",PROC_MEM_RES," ",PROC_MEM_RES_HIGH," ",
PROC_CPU_TOTAL_TIME,
PROC_DISK_LOGL_IO_RATE,PROC_DISK_PHYS_IO_RATE,
PROC_IO_BYTE_RATE,"KBs ",
PROC_PROC_NAME
}

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-1774187/,如需轉載,請註明出處,否則將追究法律責任。

相關文章