티스토리 뷰

Linux OS는 기본적으로 /var/log/sa 이하에 sar 성능 raw 데이터를 적재하고 있다.

 

시스템의 장애시나 성능지연등의 이상징후시 해당 RAW 데이터를 활용하여 분석에 활용 가능하지만,

 

sar 커맨드나 ksar등의 특성상 전체 일자 기준이 아닌 각각의 일자 데이터를 따로 개별 확인을 해야한다.

 

아래 Script를 활용하면 /var/log/sa 이하에 적재된 sar 데이터를 기준으로 각 일자별, 시간대별 Load Average를 손쉽게 확인이 가능하다.

 

[ 기준 데이터 ]

 

[root@TestVM01 ~]#
[root@TestVM01 ~]# ls -l /var/log/sa/sa[0-9]*
-rw-r--r-- 1 root root  352752 Dec  1 23:50 /var/log/sa/sa01
-rw-r--r-- 1 root root  352752 Dec  2 23:50 /var/log/sa/sa02
-rw-r--r-- 1 root root  352752 Dec  3 23:50 /var/log/sa/sa03
-rw-r--r-- 1 root root  352752 Dec  4 23:50 /var/log/sa/sa04
-rw-r--r-- 1 root root 2044784 Dec  5 23:59 /var/log/sa/sa05
-rw-r--r-- 1 root root 3525360 Dec  6 23:59 /var/log/sa/sa06
-rw-r--r-- 1 root root 3525360 Dec  7 23:59 /var/log/sa/sa07
-rw-r--r-- 1 root root 2962320 Dec  8 20:09 /var/log/sa/sa08
[root@TestVM01 ~]#

 

물론 아래 Script 이하 sar command 부분을 개작하면 Load Average 뿐만이 아닌 CPU, I/O 수치등도 원하는데로 추출이 가능하다.

 

 

1. 사용법

 

[root@TestVM01 ~]#
[root@TestVM01 ~]# ./load_max.sh

Usage1 - ./load_max.sh[Start Time] [End Time]
ex1) - ./load_max.sh07:30:00 10:00:00

[root@TestVM01 ~]#
[root@TestVM01 ~]#
[root@TestVM01 ~]# ./load_max.sh 07:30:00 10:00:00

[ Load Average - Dec 1 - /var/log/sa/sa01 ]

TIME=07   Average=0.95   Min=0.73   Max=1.18
TIME=08   Average=5.16   Min=0.77   Max=23.78
TIME=09   Average=3.36   Min=0.77   Max=8.55

####################################################################

[ Load Average - Dec 2 - /var/log/sa/sa02 ]

TIME=07   Average=1.68   Min=0.77   Max=2.24
TIME=08   Average=5.13   Min=0.77   Max=9.62
TIME=09   Average=11.45   Min=0.77   Max=23.19

####################################################################

[ Load Average - Dec 3 - /var/log/sa/sa03 ]

TIME=07   Average=0.99   Min=0.49   Max=1.50
TIME=08   Average=1.62   Min=0.45   Max=3.67
TIME=09   Average=10.99   Min=0.45   Max=15.98

####################################################################

[ Load Average - Dec 4 - /var/log/sa/sa04 ]

TIME=07   Average=1.45   Min=0.76   Max=2.14
TIME=08   Average=5.38   Min=0.86   Max=18.08
TIME=09   Average=6.87   Min=0.86   Max=12.49

####################################################################

[ Load Average - Dec 5 - /var/log/sa/sa05 ]

TIME=07   Average=1.19   Min=0.33   Max=2.04
TIME=08   Average=1.67   Min=0.85   Max=3.43
TIME=09   Average=335.95   Min=0.85   Max=1317.05

####################################################################

[ Load Average - Dec 6 - /var/log/sa/sa06 ]

TIME=07   Average=0.71   Min=0.53   Max=2.00
TIME=08   Average=0.73   Min=0.60   Max=5.87
TIME=09   Average=1.74   Min=0.76   Max=21.01

####################################################################

[ Load Average - Dec 7 - /var/log/sa/sa07 ]

TIME=07   Average=0.59   Min=0.19   Max=1.59
TIME=08   Average=0.73   Min=0.79   Max=2.18
TIME=09   Average=0.98   Min=0.72   Max=3.52

####################################################################

[ Load Average - Dec 8 - /var/log/sa/sa08 ]

TIME=07   Average=1.07   Min=0.37   Max=3.15
TIME=08   Average=4.74   Min=0.93   Max=34.69
TIME=09   Average=11.64   Min=0.93   Max=40.03

####################################################################
[root@TestVM01 ~]#

 

 

2. Script 내용

 

[root@TestVM01 ~]#
[root@TestVM01 ~]# vi ./load_max.sh
#!/bin/bash
##By Kwang-min.choi@kt.com

 

export LANG=C
export LC_ALL=C

 

if [ $# -ne 2 ]
then
 echo
 echo "Usage1 - $0 [Start Time] [End Time]"
 echo "ex1) - $0 07:30:00 10:00:00"
 echo
 exit 0
fi

 

for SAR_LIST in `ls -1rt /var/log/sa/sa[0-9]*`
do
 SAR_NAME=`echo ${SAR_LIST} | cut -d "/" -f5`
 sar -q -f ${SAR_LIST} -s $1 -e $2 | awk '$1 ~ /^[0-9]/ && $2 ~ /^[0-9]/ {print $1, $4}' > ${SAR_NAME}.raw
 echo
 echo "[ Load Average - `ls -l ${SAR_LIST} | awk '{print $6, $7}'` - ${SAR_LIST} ]"
 echo

 RAWDATA=${SAR_NAME}.raw

 cat ./${RAWDATA} | cut -d ":" -f1 | uniq > uniq.list
 
 while read UNIQ_LIST;
 do
  TOTAL_SUM=0
  TOTAL_LIST=`cat ${RAWDATA} | sed 's#%##g' | grep "^${UNIQ_LIST}"`
  TOTAL_RAW=`cat ${RAWDATA} | sed 's#%##g' | grep "^${UNIQ_LIST}" | awk '{print $2}'`
  TOTAL_COUNT=`cat ${RAWDATA} | sed 's#%##g' | grep "^${UNIQ_LIST}" | wc -l`
  MAX=0
 
  for LIST in ${TOTAL_RAW}
  do
   export TOTAL_SUM=`echo "${TOTAL_SUM} + ${LIST}" | bc`
   export DIFF=`echo "${LIST} > ${MAX}" | bc`
   if [ "$DIFF" -eq 1 ];
   then
    MAX=${LIST}
   fi
 
   if [ -z "$MIN" -a -z "$BEFOR_LIST" ];
   then
    MIN=${LIST}
    BEFOR_LIST=${LIST}
   else
    export MIN_DIFF=`echo "${LIST} <= ${BEFOR_LIST}" | bc`
 
    if [ "$MIN_DIFF" -eq 1 ];
    then
     MIN=${LIST}
    fi
   fi 
  done
  export AVERAGE=`echo "${TOTAL_SUM} ${TOTAL_COUNT}" | awk '{printf "%.2f", $1 / $2}'`
 
  echo -e "TIME=$UNIQ_LIST \t Average=${AVERAGE} \t Min=${MIN} \t Max=${MAX}"
 done < uniq.list
echo
echo "####################################################################"

done

 

 

 

반응형
반응형
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday