Commit 924baab2 by jajapi

Update checkPM.py / Rename Directory,file / Add factor

parent 132ca5ff
...@@ -458,6 +458,12 @@ function GET_SUMMARY() ...@@ -458,6 +458,12 @@ function GET_SUMMARY()
echo -e "`uname -n`, $UXEN_MAIN_VERSION, `sudo xl li | sed '1,2d' | wc -l`, $ManagementIP" echo -e "`uname -n`, $UXEN_MAIN_VERSION, `sudo xl li | sed '1,2d' | wc -l`, $ManagementIP"
} }
function CHG_FAC()
{
sed -i 's/0/1/' factor
}
function CMS_MAIN() function CMS_MAIN()
{ {
GET_DATE GET_DATE
...@@ -550,23 +556,23 @@ VAR=0 ...@@ -550,23 +556,23 @@ VAR=0
if [ -e /opt/uxen3 ]; if [ -e /opt/uxen3 ];
then then
CMS_MAIN CMS_MAIN && CHG_FAC
VAR=1 VAR=1
fi fi
if [ -e /opt/pengx3 ]; if [ -e /opt/pengx3 ];
then then
WEB_MAIN WEB_MAIN && CHG_FAC
VAR=1 VAR=1
fi fi
if [ -e /home/orchard/uxen_new ]; if [ -e /home/orchard/uxen_new ];
then then
KPF_MAIN KPF_MAIN && CHG_FAC
VAR=1 VAR=1
fi fi
if [ $VAR -eq 0 ]; if [ $VAR -eq 0 ];
then then
KPF_LOCAL_MAIN KPF_LOCAL_MAIN && CHG_FAC
fi fi
#!/bin/bash
#Hyun-gwan Seo
#Modified to Young-bin Cho [2018/11/02]
function DRAW_A_LINE()
{
echo -e "-----------------------------------------------"
}
function GET_DATE()
{
echo -e "\n------------------- date-------------------"
date
ntpq -p
}
function CHECK_MEMORY()
{
echo -e "\n-------------- Check memory --------------"
free -h
DRAW_A_LINE
}
function WEB_CHECK_PROCESS()
{
echo -e "\n-------------- Check Process --------------"
process=("nginx" "pengx" "ntp")
for ((idx=0; idx < ${#process[@]}; idx++))
do
echo "${process[$idx]}"
echo -e "`ps aux | grep ${process[$idx]}`"
echo ""
done
DRAW_A_LINE
}
function UXEN_DSTAT()
{
echo -e "\n-------------- dstat --------------"
python2 /usr/bin/dstat -lcdngy 1 10
python2 /usr/bin/dstat -nf 1 10
DRAW_A_LINE
}
function GET_VM_LIST()
{
echo -e "\n-------------- VM List Check --------------"
sudo xl li
DRAW_A_LINE
}
function DMESG_CHECK()
{
echo -e "\n-------------- Dmesg Check --------------"
dmesg -T | grep -i -E --color=yes '(ERROR|fail)' | tail
DRAW_A_LINE
}
UXEN_MAIN_VERSION=0
function WEB_UXEN_VERSION_CHECK()
{
UXEN_MAIN_VERSION=`cat /opt/pengx3/docs/VERSION`
}
function GET_XL_INFO()
{
echo -e "\n----------------- xl info(memory) --------------------"
xl info | grep -E "total_memory|free_memory"
DRAW_A_LINE
}
function VCPUS_RATIO_CHECK()
{
echo -e "\n------------ VCPUs Ration Check --------------"
cores=`sudo xl info | grep nr_cpus | awk -F ' ' '{ print $3 }'`
vcpus=`sudo xl li | sed '1d' | awk -F' ' '{ sum += $4; } END { print sum; }'`
vcpus_ratio=`echo "$vcpus $cores" | awk '{printf "%.2f \n", $1/$2}'`
echo -e "VCPUs 사용량(%) = $vcpus_ratio"
DRAW_A_LINE
}
function CHECK_BONDING()
{
echo -e "\n------------ Bonding Down Check --------------"
BONDNAME=("bond0" "bond1" "bond2" "bond3" "bond4" "bond5")
for arr_BOND in ${BONDNAME[*]}
do
echo -e "\033[41m"$arr_BOND"\033[0m"
cat /proc/net/bonding/$arr_BOND |sed 's/\(Slave Interface.*\)/\x1b[32m\1\x1b[0m/'|sed 's/\( up\)/\x1b[34m\1\x1b[0m/'|sed 's/\( down\)/\x1b[31m\1\x1b[0m/'|sed 's/\(1000\)/\x1b[36m\1\x1b[0m/'|sed 's/\(10000\)/\x1b[36m\1\x1b[0m/'
DRAW_A_LINE
done
}
function GET_BRIDGE()
{
echo -e "\n---------------- brctl show ------------------"
brctl show
DRAW_A_LINE
}
function CHECK_NFS()
{
echo -e "\n--------------- NFS Check ---------------"
nfsstat -m
DRAW_A_LINE
}
function CHECK_DF()
{
echo -e "\n---------------- df -Th ------------------"
df -Th
echo -e "\n---------------- df -i -------------------"
df -i
DRAW_A_LINE
}
LOG_HOME=/var/log
function REFINE_SYSLOG()
{
ENTIRE_SYSLOG=/tmp/entire_syslog
ls -r $LOG_HOME/syslog*.gz | xargs zcat > $ENTIRE_SYSLOG
sudo cat $LOG_HOME/syslog.1 >> $ENTIRE_SYSLOG
sudo cat $LOG_HOME/syslog >> $ENTIRE_SYSLOG
echo -e "\n\x1b[41m"SYSLOG"\x1b[0m"
echo -e "\n----------------\x1b[34m"entire syslog"\x1b[0m---------------------\n"
grep -Ev "CRON" $ENTIRE_SYSLOG | tail
echo -e "\n----------------\x1b[34m"error fail log"\x1b[0m--------------------\n"
cat $ENTIRE_SYSLOG | grep --color=yes -E "error|fail|failure"
echo -e "\n----------------\x1b[34m"detail log"\x1b[0m------------------------\n"
echo -e "\nPlease see /tmp/entire_syslog"
echo -e "\n\x1b[31m"-------------------------------------------------------------------------------------------"\x1b[0m"
}
function REFINE_MESSAGES()
{
ENTIRE_MESSAGE_LOG=/tmp/entire_messages
ls -r $LOG_HOME/messages*.gz | xargs zcat > $ENTIRE_MESSAGE_LOG
sudo cat $LOG_HOME/messages.1 >> $ENTIRE_MESSAGE_LOG
sudo cat $LOG_HOME/messages >> $ENTIRE_MESSAGE_LOG
echo -e "\n\x1b[41m"MESSAGES"\x1b[0m"
echo -e "\n----------------\x1b[34m"entire messages"\x1b[0m---------------------\n"
tail $ENTIRE_MESSAGE_LOG
echo -e "\n----------------\x1b[34m"error fail log"\x1b[0m--------------------\n"
cat $ENTIRE_MESSAGE_LOG | grep --color=yes -E "error|fail|failure"
echo -e "\n----------------\x1b[34m"detail log"\x1b[0m------------------------\n"
echo -e "\nPlease see /tmp/entire_messages"
echo -e "\n\x1b[31m"-------------------------------------------------------------------------------------------"\x1b[0m"
}
function REFINE_KERN_LOG()
{
ENTIRE_KERN_LOG=/tmp/entire_kern.log
ls -r $LOG_HOME/kern.log*.gz | xargs zcat > $ENTIRE_KERN_LOG
sudo cat $LOG_HOME/kern.log.1 >> $ENTIRE_KERN_LOG
sudo cat $LOG_HOME/kern.log >> $ENTIRE_KERN_LOG
echo -e "\n\x1b[41m"KERN"\x1b[0m"
echo -e "\n----------------\x1b[34m"entire kernlog"\x1b[0m---------------------\n"
tail $ENTIRE_KERN_LOG
echo -e "\n----------------\x1b[34m"error fail log"\x1b[0m--------------------\n"
cat $ENTIRE_KERN_LOG | grep --color=yes -E "error|fail|failure"
echo -e "\n----------------\x1b[34m"detail log"\x1b[0m------------------------\n"
echo -e "\nPlease see /tmp/entire_kern.log"
echo -e "\n\x1b[31m"-------------------------------------------------------------------------------------------"\x1b[0m"
}
function REFINE_AUTH_LOG()
{
ENTIRE_AUTH_LOG=/tmp/entire_auth.log
ls -r $LOG_HOME/auth.log*.gz | xargs zcat > $ENTIRE_AUTH_LOG
sudo cat $LOG_HOME/auth.log.1 >> $ENTIRE_AUTH_LOG
sudo cat $LOG_HOME/auth.log >> $ENTIRE_AUTH_LOG
echo -e "\n\x1b[41m"AUTH"\x1b[0m"
echo -e "\n----------------\x1b[34m"entire authlog"\x1b[0m---------------------\n"
tail $ENTIRE_AUTH_LOG
echo -e "\n----------------\x1b[34m"error fail log"\x1b[0m--------------------\n"
cat $ENTIRE_AUTH_LOG | grep --color=yes -E "error|fail|failure"
echo -e "\n----------------\x1b[34m"detail log"\x1b[0m------------------------\n"
echo -e "\nPlease see /tmp/entire_auth.log"
echo -e "\n\x1b[31m"-------------------------------------------------------------------------------------------"\x1b[0m"
}
function GET_SYSTEM_LOG()
{
REFINE_SYSLOG
REFINE_MESSAGES
REFINE_KERN_LOG
REFINE_AUTH_LOG
}
function GET_WEB_UXEN_LOG()
{
DEFAULT_UXEN3_API_LOG=/opt/pengx3/var/log/pengxapi.log* # YB web zone은 pengx3 이다.
DEFAULT_UWSGI_LOG=/opt/pengx3/var/log/uwsgi.log
ENTIRE_UXEN3_API_LOG=/tmp/entire_uxenapi.log
REFINED_UXEN3_API_LOG=/tmp/refined_uxenapi.log
REFINED_UWSGI_LOG=/tmp/uwsgi.log
ls -r $DEFAULT_UXEN3_API_LOG | xargs cat > $ENTIRE_UXEN3_API_LOG
echo -e "\n\x1b[45m"UXENAPI"\x1b[0m"
echo -e "\n----------------\x1b[34m"entire uxenapi"\x1b[0m---------------------\n"
tail $ENTIRE_UXEN3_API_LOG
echo -e "\n----------------\x1b[34m"error fail log"\x1b[0m--------------------\n"
cat $ENTIRE_UXEN3_API_LOG | grep --color=yes -E "error|fail|failure"
echo -e "\n----------------\x1b[34m"detail log"\x1b[0m------------------------\n"
echo -e "\nPlease see /tmp/entire_uxenapi.log"
echo -e "\n\x1b[31m"-------------------------------------------------------------------------------------------"\x1b[0m"
echo -e "\n\x1b[45m"UWSGI"\x1b[0m"
echo -e "\n----------------\x1b[34m"entire uwsgi"\x1b[0m---------------------\n"
tail $DEFAULT_UWSGI_LOG
echo -e "\n----------------\x1b[34m"error fail log"\x1b[0m--------------------\n"
cat $DEFAULT_UWSGI_LOG | grep --color=yes -E "1.1 400" |grep --color=yes -E "2018"|grep --color=yes "Nov"
echo -e "\n----------------\x1b[34m"detail log"\x1b[0m------------------------\n"
echo -e "\nPlease see $DEFAULT_UWSGI_LOG"
echo -e "\n\x1b[31m"-------------------------------------------------------------------------------------------"\x1b[0m"
}
function GET_SUMMARY()
{
echo -e "\n"
ManagementIP=`sudo ifconfig | grep "inet addr:192.168." | awk -F ':' '{ print $2 }' | awk -F ' ' '{ print $1 }'`
SYSTEM_MANUFACTURER=`dmidecode -s system-manufacturer`
SYSTEM_PRODUCT_NAME=`dmidecode -s system-product-name`
PROCESSOR_VERSION=`dmidecode -s processor-version`
echo -e "\n---------------- 서버 정보 ------------------"
echo -e "$SYSTEM_MANUFACTURER $SYSTEM_PRODUCT_NAME\n"
echo -e "$SYSTEM_PRODUCT_NAME\n"
echo -e "$PROCESSOR_VERSION\n"
echo -e "\n\n호스트네임, UXEN 버전, 실행 중인 VM, 사용 IP"
echo "==================================================="
echo -e "`uname -n`, $UXEN_MAIN_VERSION, `sudo xl li | sed '1,2d' | wc -l`, $ManagementIP"
}
function MAIN()
{
GET_DATE
WEB_CHECK_PROCESS
UXEN_DSTAT
GET_VM_LIST
WEB_UXEN_VERSION_CHECK
GET_XL_INFO
VCPUS_RATIO_CHECK
CHECK_BONDING
CHECK_NFS
CHECK_DF
CHECK_MEMORY
DMESG_CHECK
lastlog
GET_SYSTEM_LOG
GET_WEB_UXEN_LOG
GET_SUMMARY
}
MAIN
#!/bin/bash
#Hyun-gwan Seo
#Modified to Young-bin Cho [2018/11/02]
function DRAW_A_LINE()
{
echo -e "-----------------------------------------------"
}
function GET_DATE()
{
echo -e "\n------------------- date-------------------"
date
ntpq -p
}
function CHECK_MEMORY()
{
echo -e "\n-------------- Check memory --------------"
free -h
DRAW_A_LINE
}
function KPF_CHECK_PROCESS()
{
echo -e "\n-------------- Check Process --------------"
process=("nginx" "uxen" "ntp")
for ((idx=0; idx < ${#process[@]}; idx++))
do
echo "${process[$idx]}"
echo -e "`ps aux | grep ${process[$idx]}`"
echo ""
done
DRAW_A_LINE
}
function KPF_RUN_DSTAT()
{
echo -e "\n-------------- dstat --------------"
dstat -lcdngy 1 10
dstat -nf 1 10
DRAW_A_LINE
}
function GET_VM_LIST()
{
echo -e "\n-------------- VM List Check --------------"
sudo xl li
DRAW_A_LINE
}
function DMESG_CHECK()
{
echo -e "\n-------------- Dmesg Check --------------"
dmesg -T | grep -i -E --color=yes '(ERROR|fail)' | tail
DRAW_A_LINE
}
UXEN_MAIN_VERSION=0
function KPF_VERSION_CHECK()
{
UXEN_MAIN_VERSION=`cat /home/orchard/uxen_new/docs/VERSION`
}
# xl info 명령에서 메모리 정보를 가져오는 함수
function GET_XL_INFO()
{
echo -e "\n----------------- xl info(memory) --------------------"
xl info | grep -E "total_memory|free_memory"
DRAW_A_LINE
}
function VCPUS_RATIO_CHECK()
{
echo -e "\n------------ VCPUs Ration Check --------------"
cores=`sudo xl info | grep nr_cpus | awk -F ' ' '{ print $3 }'`
vcpus=`sudo xl li | sed '1d' | awk -F' ' '{ sum += $4; } END { print sum; }'`
#vcpus_ratio=`echo "scale=2; ($vcpus/$cores)*100" | bc`
vcpus_ratio=`echo "$vcpus $cores" | awk '{printf "%.2f \n", $1/$2}'`
echo -e "VCPUs 사용량(%) = $vcpus_ratio"
DRAW_A_LINE
}
function CHECK_BONDING()
{
echo -e "\n------------ Bonding Down Check --------------"
BONDNAME=("bond0" "bond1" "bond2" "bond3" "bond4" "bond5")
for arr_BOND in ${BONDNAME[*]}
do
echo -e "\033[41m"$arr_BOND"\033[0m"
cat /proc/net/bonding/$arr_BOND |sed 's/\(Slave Interface.*\)/\x1b[32m\1\x1b[0m/'|sed 's/\( up\)/\x1b[34m\1\x1b[0m/'|sed 's/\( down\)/\x1b[31m\1\x1b[0m/' |sed 's/\(1000\)/\x1b[36m\1\x1b[0m/'|sed 's/\(10000\)/\x1b[36m\1\x1b[0m/'
DRAW_A_LINE
done
}
function GET_BRIDGE()
{
echo -e "\n---------------- brctl show ------------------"
brctl show
DRAW_A_LINE
}
function CHECK_MULTI_PATH()
{
echo -e "\n--------------- Multi Path Check --------------"
sudo multipath -ll |sed 's/\(active\)/\x1b[34m\1\x1b[0m/'
DRAW_A_LINE
}
function CHECK_OCFS2()
{
echo -e "\n-------------- OCFS2 Check ---------------"
/etc/init.d/ocfs2 status
/etc/init.d/o2cb status |sed 's/\(Online\)/\x1b[34m\1\x1b[0m/'|sed 's/\(Active\)/\x1b[34m\1\x1b[0m/'
DRAW_A_LINE
}
function CHECK_DF()
{
echo -e "\n---------------- df -Th ------------------"
df -Th
echo -e "\n---------------- df -i -------------------"
df -i
DRAW_A_LINE
}
LOG_HOME=/var/log
# /var/log/syslog* 파일을 하나로 합치고 불필요한 로그를 삭제함.
function REFINE_SYSLOG()
{
ENTIRE_SYSLOG=/tmp/entire_syslog
ls -r $LOG_HOME/syslog*.gz | xargs zcat > $ENTIRE_SYSLOG
sudo cat $LOG_HOME/syslog.1 >> $ENTIRE_SYSLOG
sudo cat $LOG_HOME/syslog >> $ENTIRE_SYSLOG
echo -e "\n\x1b[41m"SYSLOG"\x1b[0m"
echo -e "\n----------------\x1b[34m"entire syslog"\x1b[0m---------------------\n"
grep -Ev "CRON" $ENTIRE_SYSLOG |tail
echo -e "\n----------------\x1b[34m"error fail log"\x1b[0m--------------------\n"
cat $ENTIRE_SYSLOG | grep --color=yes -E "error|fail|failure"
echo -e "\n----------------\x1b[34m"detail log"\x1b[0m------------------------\n"
echo -e "\nPlease see /tmp/entire_syslog"
echo -e "\n\x1b[31m"-------------------------------------------------------------------------------------------"\x1b[0m"
}
# /var/log/message* 파일을 하나로 합치고 불필요한 로그를 삭제함.
function REFINE_MESSAGES()
{
ENTIRE_MESSAGE_LOG=/tmp/entire_messages
ls -r $LOG_HOME/messages*.gz | xargs zcat > $ENTIRE_MESSAGE_LOG
sudo cat $LOG_HOME/messages.1 >> $ENTIRE_MESSAGE_LOG
sudo cat $LOG_HOME/messages >> $ENTIRE_MESSAGE_LOG
echo -e "\n\x1b[41m"MESSAGES"\x1b[0m"
echo -e "\n----------------\x1b[34m"entire messages"\x1b[0m---------------------\n"
tail $ENTIRE_MESSAGE_LOG
echo -e "\n----------------\x1b[34m"error fail log"\x1b[0m--------------------\n"
cat $ENTIRE_MESSAGE_LOG | grep --color=yes -E "error|fail|failure"
echo -e "\n----------------\x1b[34m"detail log"\x1b[0m------------------------\n"
echo -e "\nPlease see /tmp/entire_messages"
echo -e "\n\x1b[31m"-------------------------------------------------------------------------------------------"\x1b[0m"
}
# /var/log/kern.log* 파일을 하나로 합치고 불필요한 로그를 삭제함.
function REFINE_KERN_LOG()
{
ENTIRE_KERN_LOG=/tmp/entire_kern.log
ls -r $LOG_HOME/kern.log*.gz | xargs zcat > $ENTIRE_KERN_LOG
sudo cat $LOG_HOME/kern.log.1 >> $ENTIRE_KERN_LOG
sudo cat $LOG_HOME/kern.log >> $ENTIRE_KERN_LOG
echo -e "\n\x1b[41m"KERN"\x1b[0m"
echo -e "\n----------------\x1b[34m"entire kernlog"\x1b[0m---------------------\n"
tail $ENTIRE_KERN_LOG
echo -e "\n----------------\x1b[34m"error fail log"\x1b[0m--------------------\n"
cat $ENTIRE_KERN_LOG | grep --color=yes -E "error|fail|failure"
echo -e "\n----------------\x1b[34m"detail log"\x1b[0m------------------------\n"
echo -e "\nPlease see /tmp/entire_kern.log"
echo -e "\n\x1b[31m"-------------------------------------------------------------------------------------------"\x1b[0m"
}
# /var/log/auth.log 파일을 하나로 합치고 불필요한 로그를 삭제함.
function REFINE_AUTH_LOG()
{
ENTIRE_AUTH_LOG=/tmp/entire_auth.log
ls -r $LOG_HOME/auth.log*.gz | xargs zcat > $ENTIRE_AUTH_LOG
sudo cat $LOG_HOME/auth.log.1 >> $ENTIRE_AUTH_LOG
sudo cat $LOG_HOME/auth.log >> $ENTIRE_AUTH_LOG
echo -e "\n\x1b[41m"AUTH"\x1b[0m"
echo -e "\n----------------\x1b[34m"entire authlog"\x1b[0m---------------------\n"
tail $ENTIRE_AUTH_LOG
echo -e "\n----------------\x1b[34m"error fail log"\x1b[0m--------------------\n"
cat $ENTIRE_AUTH_LOG | grep --color=yes -E "error|fail|failure"
echo -e "\n----------------\x1b[34m"detail log"\x1b[0m------------------------\n"
echo -e "\nPlease see /tmp/entire_auth.log"
echo -e "\n\x1b[31m"-------------------------------------------------------------------------------------------"\x1b[0m"
}
function GET_SYSTEM_LOG()
{
REFINE_SYSLOG
REFINE_MESSAGES
REFINE_KERN_LOG
REFINE_AUTH_LOG
}
function KPF_UXEN_LOG()
{
SECOND_UXEN2_API_LOG=/var/www/uxen/var/log/uxenapi.log*
SECOND_GUNICORN_LOG=/var/www/uxen/var/log/gunicorn-uxen-error.log
ENTIRE_UXEN2_API_LOG=/tmp/entire_uxenapi.log # ENTIRE_UXEN2_API_LOG와 ENTIRE_UXEN3_API_LOG의 경로는 같지만 직관적으로 이해하기 쉽도록 변수를 별도로 선언함
REFINED_UXEN2_API_LOG=/tmp/refined_uxenapi.log # REFINED_UXEN2_API_LOG와 REFINED_UXEN3_API_LOG의 경로는 같지만 직관적으로 이해하기 쉽도록 변수를 별도로 선언함
REFINED_GUNICORN_LOG=/tmp/refined_gunicorn-uxen-error.log
ls -r $SECOND_UXEN2_API_LOG | xargs cat > $ENTIRE_UXEN2_API_LOG
cat $ENTIRE_UXEN2_API_LOG | grep -E "error|fail|failure"
echo -e "\n---------------- Refine $SECOND_GUNICORN_LOG ------------------"
cat $SECOND_GUNICORN_LOG | grep -Ev " Starting|worker|Listening"
echo -e "Please see $REFINED_GUNICORN_LOG"
echo -e "\n\x1b[45m"UXENAPI"\x1b[0m"
echo -e "\n----------------\x1b[34m"entire uxenapi"\x1b[0m---------------------\n"
tail $ENTIRE_UXEN2_API_LOG
echo -e "\n----------------\x1b[34m"error fail log"\x1b[0m--------------------\n"
cat $ENTIRE_UXEN2_API_LOG | grep -E "error|fail|failure"
echo -e "\n----------------\x1b[34m"detail log"\x1b[0m------------------------\n"
echo -e "\nPlease see /tmp/entire_uxenapi.log"
echo -e "\n\x1b[31m"-------------------------------------------------------------------------------------------"\x1b[0m"
echo -e "\n\x1b[45m"GUNICORN"\x1b[0m"
echo -e "\n----------------\x1b[34m"entire gunicorn"\x1b[0m---------------------\n"
tail $SECOND_GUNICORN_LOG
echo -e "\n----------------\x1b[34m"error fail log"\x1b[0m--------------------\n"
cat $SECOND_GUNICORN_LOG | grep -Ev " Starting|worker|Listening"
echo -e "\n----------------\x1b[34m"detail log"\x1b[0m------------------------\n"
echo -e "\nPlease see /tmp/refined_gunicorn-uxen-error.log"
echo -e "\n\x1b[31m"-------------------------------------------------------------------------------------------"\x1b[0m"
}
function GET_UXEN_LOG()
{
KPF_UXEN_LOG # REFINE_UXEN_LOG 함수에서 UXEN_MAIN_VERSION 변수를 사용함.
}
function GET_SUMMARY()
{
echo -e "\n"
ManagementIP=`sudo ifconfig | grep "inet addr:192.168." | awk -F ':' '{ print $2 }' | awk -F ' ' '{ print $1 }'`
SYSTEM_MANUFACTURER=`dmidecode -s system-manufacturer`
SYSTEM_PRODUCT_NAME=`dmidecode -s system-product-name`
PROCESSOR_VERSION=`dmidecode -s processor-version`
echo -e "\n---------------- 서버 정보 ------------------"
echo -e "$SYSTEM_MANUFACTURER $SYSTEM_PRODUCT_NAME\n"
echo -e "$SYSTEM_PRODUCT_NAME\n"
echo -e "$PROCESSOR_VERSION\n"
echo -e "\n\n호스트네임, UXEN 버전, 실행 중인 VM, 관리 IP"
echo "==================================================="
echo -e "`uname -n`, $UXEN_MAIN_VERSION, `sudo xl li | sed '1,2d' | wc -l`, $ManagementIP"
}
function MAIN()
{
GET_DATE
KPF_CHECK_PROCESS
KPF_RUN_DSTAT
GET_VM_LIST
KPF_VERSION_CHECK
GET_XL_INFO
VCPUS_RATIO_CHECK
CHECK_BONDING
CHECK_MULTI_PATH
CHECK_OCFS2
CHECK_DF
CHECK_MEMORY
DMESG_CHECK
lastlog
GET_SYSTEM_LOG
GET_UXEN_LOG
GET_SUMMARY
}
MAIN
#!/bin/bash
#Hyun-gwan Seo
#Modified to Young-bin Cho [2018/11/02]
function DRAW_A_LINE()
{
echo -e "-----------------------------------------------"
}
function GET_DATE()
{
echo -e "\n------------------- date-------------------"
date
ntpq -p
}
function CHECK_MEMORY()
{
echo -e "\n-------------- Check memory --------------"
free -h
DRAW_A_LINE
}
function KPF_CHECK_PROCESS()
{
echo -e "\n-------------- Check Process --------------"
process=("nginx" "uxen" "ntp")
for ((idx=0; idx < ${#process[@]}; idx++))
do
echo "${process[$idx]}"
echo -e "`ps aux | grep ${process[$idx]}`"
echo ""
done
DRAW_A_LINE
}
function KPF_RUN_DSTAT()
{
echo -e "\n-------------- dstat --------------"
dstat -lcdngy 1 10
dstat -nf 1 10
DRAW_A_LINE
}
function GET_VM_LIST()
{
echo -e "\n-------------- VM List Check --------------"
sudo xl li
DRAW_A_LINE
}
function DMESG_CHECK()
{
echo -e "\n-------------- Dmesg Check --------------"
dmesg -T | grep -i -E --color=yes '(ERROR|fail)' | tail
DRAW_A_LINE
}
UXEN_MAIN_VERSION=0
function KPF_LOCAL_VERSION_CHECK()
{
UXEN_MAIN_VERSION=`cat /home/orchard/uxen/docs/VERSION`
}
# xl info 명령에서 메모리 정보를 가져오는 함수
function GET_XL_INFO()
{
echo -e "\n----------------- xl info(memory) --------------------"
xl info | grep -E "total_memory|free_memory"
DRAW_A_LINE
}
function VCPUS_RATIO_CHECK()
{
echo -e "\n------------ VCPUs Ration Check --------------"
cores=`sudo xl info | grep nr_cpus | awk -F ' ' '{ print $3 }'`
vcpus=`sudo xl li | sed '1d' | awk -F' ' '{ sum += $4; } END { print sum; }'`
vcpus_ratio=`echo "$vcpus $cores" | awk '{printf "%.2f \n", $1/$2}'`
echo -e "VCPUs 사용량(%) = $vcpus_ratio"
DRAW_A_LINE
}
function CHECK_BONDING()
{
echo -e "\n------------ Bonding Down Check --------------"
BONDNAME=("bond0" "bond1" "bond2" "bond3" "bond4" "bond5")
for arr_BOND in ${BONDNAME[*]}
do
echo -e "\033[41m"$arr_BOND"\033[0m"
cat /proc/net/bonding/$arr_BOND |sed 's/\(Slave Interface.*\)/\x1b[32m\1\x1b[0m/'|sed 's/\( up\)/\x1b[34m\1\x1b[0m/'|sed 's/\( down\)/\x1b[31m\1\x1b[0m/' |sed 's/\(1000\)/\x1b[36m\1\x1b[0m/'|sed 's/\(10000\)/\x1b[36m\1\x1b[0m/'
DRAW_A_LINE
done
}
function GET_BRIDGE()
{
echo -e "\n---------------- brctl show ------------------"
brctl show
DRAW_A_LINE
}
function CHECK_DF()
{
echo -e "\n---------------- df -Th ------------------"
df -Th
echo -e "\n---------------- df -i -------------------"
df -i
DRAW_A_LINE
}
LOG_HOME=/var/log
# /var/log/syslog* 파일을 하나로 합치고 불필요한 로그를 삭제함.
function REFINE_SYSLOG()
{
ENTIRE_SYSLOG=/tmp/entire_syslog
ls -r $LOG_HOME/syslog*.gz | xargs zcat > $ENTIRE_SYSLOG
sudo cat $LOG_HOME/syslog.1 >> $ENTIRE_SYSLOG
sudo cat $LOG_HOME/syslog >> $ENTIRE_SYSLOG
echo -e "\n\x1b[41m"SYSLOG"\x1b[0m"
echo -e "\n----------------\x1b[34m"entire syslog"\x1b[0m---------------------\n"
grep -Ev "CRON" $ENTIRE_SYSLOG |tail
echo -e "\n----------------\x1b[34m"error fail log"\x1b[0m--------------------\n"
cat $ENTIRE_SYSLOG | grep --color=yes -E "error|fail|failure"
echo -e "\n----------------\x1b[34m"detail log"\x1b[0m------------------------\n"
echo -e "\nPlease see /tmp/entire_syslog"
echo -e "\n\x1b[31m"-------------------------------------------------------------------------------------------"\x1b[0m"
}
# /var/log/message* 파일을 하나로 합치고 불필요한 로그를 삭제함.
function REFINE_MESSAGES()
{
ENTIRE_MESSAGE_LOG=/tmp/entire_messages
ls -r $LOG_HOME/messages*.gz | xargs zcat > $ENTIRE_MESSAGE_LOG
sudo cat $LOG_HOME/messages.1 >> $ENTIRE_MESSAGE_LOG
sudo cat $LOG_HOME/messages >> $ENTIRE_MESSAGE_LOG
echo -e "\n\x1b[41m"MESSAGES"\x1b[0m"
echo -e "\n----------------\x1b[34m"entire messages"\x1b[0m---------------------\n"
tail $ENTIRE_MESSAGE_LOG
echo -e "\n----------------\x1b[34m"error fail log"\x1b[0m--------------------\n"
cat $ENTIRE_MESSAGE_LOG | grep --color=yes -E "error|fail|failure"
echo -e "\n----------------\x1b[34m"detail log"\x1b[0m------------------------\n"
echo -e "\nPlease see /tmp/entire_messages"
echo -e "\n\x1b[31m"-------------------------------------------------------------------------------------------"\x1b[0m"
}
# /var/log/kern.log* 파일을 하나로 합치고 불필요한 로그를 삭제함.
function REFINE_KERN_LOG()
{
ENTIRE_KERN_LOG=/tmp/entire_kern.log
ls -r $LOG_HOME/kern.log*.gz | xargs zcat > $ENTIRE_KERN_LOG
sudo cat $LOG_HOME/kern.log.1 >> $ENTIRE_KERN_LOG
sudo cat $LOG_HOME/kern.log >> $ENTIRE_KERN_LOG
echo -e "\n\x1b[41m"KERN"\x1b[0m"
echo -e "\n----------------\x1b[34m"entire kernlog"\x1b[0m---------------------\n"
tail $ENTIRE_KERN_LOG
echo -e "\n----------------\x1b[34m"error fail log"\x1b[0m--------------------\n"
cat $ENTIRE_KERN_LOG | grep --color=yes -E "error|fail|failure"
echo -e "\n----------------\x1b[34m"detail log"\x1b[0m------------------------\n"
echo -e "\nPlease see /tmp/entire_kern.log"
echo -e "\n\x1b[31m"-------------------------------------------------------------------------------------------"\x1b[0m"
}
# /var/log/auth.log 파일을 하나로 합치고 불필요한 로그를 삭제함.
function REFINE_AUTH_LOG()
{
ENTIRE_AUTH_LOG=/tmp/entire_auth.log
ls -r $LOG_HOME/auth.log*.gz | xargs zcat > $ENTIRE_AUTH_LOG
sudo cat $LOG_HOME/auth.log.1 >> $ENTIRE_AUTH_LOG
sudo cat $LOG_HOME/auth.log >> $ENTIRE_AUTH_LOG
echo -e "\n\x1b[41m"AUTH"\x1b[0m"
echo -e "\n----------------\x1b[34m"entire authlog"\x1b[0m---------------------\n"
tail $ENTIRE_AUTH_LOG
echo -e "\n----------------\x1b[34m"error fail log"\x1b[0m--------------------\n"
cat $ENTIRE_AUTH_LOG | grep --color=yes -E "error|fail|failure"
echo -e "\n----------------\x1b[34m"detail log"\x1b[0m------------------------\n"
echo -e "\nPlease see /tmp/entire_auth.log"
echo -e "\n\x1b[31m"-------------------------------------------------------------------------------------------"\x1b[0m"
}
function GET_SYSTEM_LOG()
{
REFINE_SYSLOG
REFINE_MESSAGES
REFINE_KERN_LOG
REFINE_AUTH_LOG
}
function KPF_LOCAL_UXEN_LOG()
{
SECOND_UXEN2_API_LOG=/home/orchard/uxen/var/log/uxenapi.log*
SECOND_GUNICORN_LOG=/home/orchard/uxen/var/log/gunicorn-uxen-error.log
ENTIRE_UXEN2_API_LOG=/tmp/entire_uxenapi.log # ENTIRE_UXEN2_API_LOG와 ENTIRE_UXEN3_API_LOG의 경로는 같지만 직관적으로 이해하기 쉽도록 변수를 별도로 선언함
REFINED_UXEN2_API_LOG=/tmp/refined_uxenapi.log # REFINED_UXEN2_API_LOG와 REFINED_UXEN3_API_LOG의 경로는 같지만 직관적으로 이해하기 쉽도록 변수를 별도로 선언함
REFINED_GUNICORN_LOG=/tmp/refined_gunicorn-uxen-error.log
ls -r $SECOND_UXEN2_API_LOG | xargs cat > $ENTIRE_UXEN2_API_LOG
cat $ENTIRE_UXEN2_API_LOG | grep -E "error|fail|failure"
echo -e "\n---------------- Refine $SECOND_GUNICORN_LOG ------------------"
cat $SECOND_GUNICORN_LOG | grep -Ev " Starting|worker|Listening"
echo -e "Please see $REFINED_GUNICORN_LOG"
echo -e "\n\x1b[45m"UXENAPI"\x1b[0m"
echo -e "\n----------------\x1b[34m"entire uxenapi"\x1b[0m---------------------\n"
tail $ENTIRE_UXEN2_API_LOG
echo -e "\n----------------\x1b[34m"error fail log"\x1b[0m--------------------\n"
cat $ENTIRE_UXEN2_API_LOG | grep -E "error|fail|failure"
echo -e "\n----------------\x1b[34m"detail log"\x1b[0m------------------------\n"
echo -e "\nPlease see /tmp/entire_uxenapi.log"
echo -e "\n\x1b[31m"-------------------------------------------------------------------------------------------"\x1b[0m"
echo -e "\n\x1b[45m"GUNICORN"\x1b[0m"
echo -e "\n----------------\x1b[34m"entire gunicorn"\x1b[0m---------------------\n"
tail $SECOND_GUNICORN_LOG
echo -e "\n----------------\x1b[34m"error fail log"\x1b[0m--------------------\n"
cat $SECOND_GUNICORN_LOG | grep -Ev " Starting|worker|Listening"
echo -e "\n----------------\x1b[34m"detail log"\x1b[0m------------------------\n"
echo -e "\nPlease see /tmp/refined_gunicorn-uxen-error.log"
echo -e "\n\x1b[31m"-------------------------------------------------------------------------------------------"\x1b[0m"
}
function GET_UXEN_LOG()
{
KPF_LOCAL_UXEN_LOG # REFINE_UXEN_LOG 함수에서 UXEN_MAIN_VERSION 변수를 사용함.
}
function GET_SUMMARY()
{
echo -e "\n"
ManagementIP=`sudo ifconfig | grep "inet addr:192.168." | awk -F ':' '{ print $2 }' | awk -F ' ' '{ print $1 }'`
SYSTEM_MANUFACTURER=`dmidecode -s system-manufacturer`
SYSTEM_PRODUCT_NAME=`dmidecode -s system-product-name`
PROCESSOR_VERSION=`dmidecode -s processor-version`
echo -e "\n---------------- 서버 정보 ------------------"
echo -e "$SYSTEM_MANUFACTURER $SYSTEM_PRODUCT_NAME\n"
echo -e "$SYSTEM_PRODUCT_NAME\n"
echo -e "$PROCESSOR_VERSION\n"
echo -e "\n\n호스트네임, UXEN 버전, 실행 중인 VM, 관리 IP"
echo "==================================================="
echo -e "`uname -n`, $UXEN_MAIN_VERSION, `sudo xl li | sed '1,2d' | wc -l`, $ManagementIP"
}
function MAIN()
{
GET_DATE
KPF_CHECK_PROCESS
KPF_RUN_DSTAT
GET_VM_LIST
KPF_LOCAL_VERSION_CHECK
GET_XL_INFO
VCPUS_RATIO_CHECK
CHECK_BONDING
CHECK_DF
CHECK_MEMORY
DMESG_CHECK
lastlog
GET_SYSTEM_LOG
GET_UXEN_LOG
GET_SUMMARY
}
MAIN
#!/usr/bin/env python
import paramiko
import getpass
import time
import os
import subprocess
### initialize factor value
fac = subprocess.check_output ('cat factor',shell=True)
fac2 = subprocess.check_output ('cat factor',shell=True)
### read serverlists
serverlist = open("cms_serverlist.txt", 'r')
serverhost = serverlist.readlines()
### input password
password = getpass.getpass("orchard password :")
### static value
username = "orchard"
port = 22
### check.sh
for svrhost in serverhost:
host = svrhost.strip()
### ssh 접속, 명령어 실행,접속종료
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host,username=username,password='%s' %(password))
ssh.exec_command('./Seocho_uxen_check.sh > %s' % (host))
ssh.close()
print("%s check.sh excution"%(host))
### sftp 접속
transport = paramiko.Transport((host,port))
transport.connect(username=username, password=password)
sftp=paramiko.SFTPClient.from_transport(transport)
### 인자값 비교해서 달라질때 까지 반복
while fac == fac2:
time.sleep(1)
filepath = ('/home/orchard/factor')
localpath = ('/home/orchard/CSCS/MgmtPM/CMSmgmt/factor')
sftp.get(filepath,localpath)
fac =subprocess.check_output ('cat factor',shell=True)
### 인자값이 달라지면 실행할 sftp
filepath = ('/home/orchard/%s' %(host))
localpath = ('/home/orchard/result/%s'%(host))
sftp.get(filepath,localpath)
print("%s Successful copy" % host)
### 인자값 초기화
os.system('sed -i "s/1/0/" factor')
filepath = ('/home/orchard/factor')
localpath = ('/home/orchard/CSCS/Mgmt/CMSmgmt/factor')
sftp.put(localpath,filepath)
### sftp 접속종료
sftp.close()
transport.close()
cms-p-pm02
cms-p-pm03
cms-p-pm04
cms-p-spm01
cms-t-pm01
cms-t-pm02
cms-t-spm01
web-p-pm01
web-p-pm02
web-p-pm03
web-p-spm01
web-p-pm04
web-p-pm05
web-t-pm01
web-t-pm02
#!/usr/bin/env python
import paramiko
import getpass
### read serverlists
serverlist = open("cms_serverlist.txt", 'r')
serverhost = serverlist.readlines()
### input password
password = getpass.getpass("orchard password :")
### static value
username = "orchard"
port = 22
### update check.sh
for svrhost in serverhost:
host = svrhost.strip()
transport = paramiko.Transport((host,port))
transport.connect(username=username, password=password)
sftp=paramiko.SFTPClient.from_transport(transport)
filepath = '/home/orchard/Seocho_uxen_check.sh'
localpath = '/home/orchard/CSCS/GuestPM/Integration/Seocho_uxen_check.sh'
sftp.put(localpath,filepath)
filepath = '/home/orchard/factor'
localpath = '/home/orchard/CSCS/GuestPM/Integration/factor'
sftp.put(localpath,filepath)
print("%s Successful updates" % host)
sftp.close()
transport.close()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment