X7ROOT File Manager
Current Path:
/var/VMOptimizationToolsLinux
var
/
VMOptimizationToolsLinux
/
📁
..
📄
LinuxUpdate.XML
(645 B)
📄
SangforVMSTool
(3.11 KB)
📄
SangforVMSTool.service
(194 B)
📄
action_common.sh
(13.34 KB)
📄
busybox_cmd_ln.sh
(2.24 KB)
📄
collect_test_data.sh
(1.16 KB)
📄
common_config.sh
(278 B)
📄
data_test_tool.sh
(12.59 KB)
📄
debian_vmconfig.sh
(10.74 KB)
📄
guest_system_config.sh
(1.82 KB)
📄
log.sh
(1.36 KB)
📄
mod_test.sh
(3.69 KB)
📄
mod_test1.sh
(914 B)
📄
net_common.sh
(915 B)
📄
redhat_vmconfig.sh
(11.14 KB)
📄
sangfor_guest_datareport
(21.66 KB)
📄
sangfor_heartalive.sh
(2.37 KB)
📄
sangfor_module_update
(28.11 KB)
📄
sangfor_set_network.sh
(504 B)
📄
sangfor_sfping
(3.85 KB)
📄
sangfor_sshkey_gen
(1.29 KB)
📄
sangfor_update_ipc_callback
(5.29 KB)
📄
sangfor_vm_proxyd
(3.45 KB)
📄
sangfor_vm_proxyd_r
(4.4 KB)
📄
sangfor_vm_proxyd_w
(1.32 KB)
📄
sangfor_vmconfig
(2.4 KB)
📄
sangfor_vmconfig_common
(27.99 KB)
📄
sangfor_vmconfig_ipc_callback
(4.75 KB)
📄
sangfor_watchdog
(3.95 KB)
📄
sfping.c
(15.68 KB)
📄
sfping.pl
(6.15 KB)
📄
startall
(1.78 KB)
📄
stopall
(1.11 KB)
📄
suse_vmconfig.sh
(6.19 KB)
📁
tools_x64
📁
tools_x86
📄
uni_test.sh
(2.59 KB)
📄
update_common_func
(4.35 KB)
📄
update_common_header
(4.86 KB)
📄
update_config
(2.89 KB)
📄
update_install
(28.84 KB)
📄
virtio_nic_attr_set.sh
(2.42 KB)
📄
virtio_nic_compat.sh
(5.28 KB)
📄
vm_ip_recover.sh
(16.66 KB)
📄
vm_ipc.sh
(9.06 KB)
📄
vmconfig_common_func
(10.76 KB)
📄
vmconfig_common_header
(3.37 KB)
📄
vmconfig_config
(805 B)
📄
vmtools-install.sh
(31.16 KB)
📄
watch_test.sh
(313 B)
📄
watchdog.sh
(1.39 KB)
📁
x64
📁
x86
Editing: data_test_tool.sh
#!/bin/bash shell_dir=`dirname "${BASH_SOURCE[0]}"` proc_name=`basename "${BASH_SOURCE[0]}"` declare SEND_INTERVAL=5 #the interval of send packet declare GET_INFO_INTERVAL=5 #the frequency of get CPU,IO andm emory,get once five seconds declare GET_DISK_INFO_INTERVAL=60 #the frequency of get disk information,get once every minute declare GET_NETWORK_INFO_INTERVAL=600 #the frequency of get net card, get once ten minute declare CPU_IO_MEM_COUNT_TIME=0 #the first time need to get CPU,IO,MEM declare DISK_COUNT_TIME=60 #the first time need to get disk information declare NETWORK_COUNT_TIME=600 #the first time need to get netcard information declare CPU_INFO_FIRST="" #save the old information of CPU declare CPU_INFO_SECOND="" #save the new information of CPU declare IO_INFO_FIRST="" #save the old information of IO declare IO_INFO_SECOND="" #save the new information of IO declare FIRST_TIME=1 declare TITLE_PRINT=1 declare REAL=0 declare MSG_INFO_DATA="" declare CPU_USAGE=0 declare RD_IOPS=0 declare RD_BYTEPS=0 declare WR_IOPS=0 declare WR_BYTEPS=0 declare MEMTOTAL="" declare MEMUSED="" declare DISK_TOTAL="" declare DISK_USED="" declare VNETDEVS=[] declare MEM_USAGE=0 declare DISK_USAGE=0 declare TMP_DATE="" #Get the os information of virtual machine get_cpu_info() { local array=`cat /proc/stat | head -n 1 | awk '{print $2" "$3" "$4" "$5" "$6" "$7" "$8}'` echo "$array"; } #Get the information of CPU get_diskio_info() { local array=`cat /proc/diskstats | grep '[vsh]d[a-z][^1-9]' \ | awk 'BEGIN{a=0;b=0;c=0;d=0}{a=(a"+"$4);b=(b"+"$6);c=(c"+"$8);d=(d"+"$10)}END{print a" "b" "c" "d}'` echo "$array"; } #Get the information of disk IO get_mem_usage() { MEMTOTAL=`cat /proc/meminfo | grep MemTotal | awk -F" " '{print $2}'` MEMFREE=`cat /proc/meminfo | grep MemFree | awk -F" " '{print $2}'` local MEMBUFFERS=`cat /proc/meminfo | grep ^Buffers | awk -F" " '{print $2}'` local CACHED=`cat /proc/meminfo | grep ^Cached | awk -F" " '{print $2}'` MEMUSED=`expr ${MEMTOTAL} - ${MEMFREE} - ${MEMBUFFERS} - ${CACHED}` MEMTOTAL=`expr ${MEMTOTAL} \* 1024` MEMUSED=`expr ${MEMUSED} \* 1024` if [ ${MEMTOTAL} -lt ${MEMUSED} ]; then log "get_mem_usage wrong!" return 1; fi MEM_USAGE=`expr 100 \* ${MEMUSED} \/ ${MEMTOTAL}`; return 0; } #Get the usage of memory get_disk_total() { DISK_TOTAL=`cat /proc/partitions | grep [vsh]d[a-z]$ | awk 'BEGIN{a=0}{a=(a"+"$3)}END{print a}'` if [ ! "${DISK_TOTAL}" ]; then return 1; fi DISK_TOTAL=$((${DISK_TOTAL})) DISK_TOTAL=`expr ${DISK_TOTAL} \* 1024` return 0; } #Get the total size of disk get_disk_used() { #check whether the df command is exist type df >/dev/null 2>&1 if [ $? -ne 0 ]; then log "check df failed!" return 1 fi DISK_USED=`df -P | grep ^/dev | grep -E -v '(fuse|loop0|fstab|sr)' | awk 'BEGIN{a=0}{a=(a"+"$3)}END{print a}'` if [ ! "${DISK_USED}" ]; then return 1; fi DISK_USED=$((${DISK_USED})) DISK_USED=`expr ${DISK_USED} \* 1024` return 0; } #Get the count of netcard get_net_count() { local net_count=`ls /sys/class/net/ -n | grep pci | wc -l` echo ${net_count} } #Get the name of netcard get_net_name() { local net_name=`ls /sys/class/net -n | grep pci |tr "/" " "| awk '{print $NF}'` if [ ! "${net_name}" ]; then return -1; fi echo "${net_name}" return 0; } get_net_pci_by_sys() { local net_pci=`ls /sys/class/net/$1 -n |egrep -o \:[a-z0-9]{2}\:[a-z0-9]{2}\.[0-7] |tail -n 1 \ |cut -d ":" -f 2-3 | tr [:.] " "` if [ ! "${net_pci}" ]; then return 1; fi echo "${net_pci}" return 0; } get_net_pci_by_lspci() { #check whether the lspci command is exist type lspci >/dev/null 2>&1 if [ $? -ne 0 ]; then log "check lspci failed!" return 1 fi local net_pci=`lspci | grep Eth | awk '{print $1}'|sed -n "${2}p" | tr [:.] " "` if [ ! "${net_pci}" ]; then return 1; fi echo "${net_pci}" return 0; } #Get the ipaddress of netcard get_net_ip() { #check whether the ip command is exist type ip >/dev/null 2>&1 if [ $? -ne 0 ]; then log "check ip failed!" return 1 fi local ipaddrs=` ip addr ls ${1} |grep -o -E "([0-9]{1,3}\.){1,3}[0-9]{1,3}/[0-9]{1,2}" | cut -d '/' -f1 | xargs echo -n | tr ' ' ':'` echo "${ipaddrs}" } #Get the information of netcard get_net_info() { local net_count=0 net_count=`get_net_count`; #if the count of netcard is zero ,then return directly,the netcard field is set null if [ ${net_count} -eq 0 ]; then VNETDEVS=[] return 0; fi local net_name="" net_name=`get_net_name` if [ $? -eq 1 ]; then log "get_net_name failed" return 1; fi local net_num=0; local tmp_name="" local tmpstr="" #get the PCI and ipaddress of every netcard for tmp_name in ${net_name} do net_num=$(($net_num + 1)); #get pci of netcard tmpstr=`get_net_pci_by_sys ${tmp_name}` if [ $? -eq 1 ]; then tmpstr=`get_net_pci_by_lspci ${net_num}` if [ $? -eq 1 ]; then log "get_net_pci failed" return 1; fi fi #save the pci information local busNumber="" local devNumber="" local funcNumber="" local net_pci_bus=`echo "${tmpstr}" | cut -d " " -f 1` local net_pci_dev=`echo "${tmpstr}" | cut -d " " -f 2` local net_pci_func=`echo "${tmpstr}" | cut -d " " -f 3` ((busNumber=16#${net_pci_bus})) ((devNumber=16#${net_pci_dev})) ((funcNumber=16#${net_pci_func})) #get the ipaddress of netcard local ipaddrs="" ipaddrs=`get_net_ip ${tmp_name}` if [ $? -ne 0 ]; then log "get_net_ip failed!" return 1 fi if [ ${net_num} -eq 1 ]; then VNETDEVS={\"busNumber\":${busNumber},\"devNumber\":${devNumber},\"funcNumber\":${funcNumber},\"ipaddrs\":\"${ipaddrs}\"} continue; fi VNETDEVS=${VNETDEVS}",{\"busNumber\":${busNumber},\"devNumber\":${devNumber},\"funcNumber\":${funcNumber},\"ipaddrs\":\"${ipaddrs}\"}" done #finaly ,add "[]" outside the VNETDEVS VNETDEVS="["${VNETDEVS}"]" return 0; } #get the information of disk get_disk_info() { #get the information of the total size of disk get_disk_total if [ $? -eq 1 ]; then log "get_disk_total failed" return 1; fi #get the usage of disk get_disk_used if [ $? -eq 1 ]; then log "get_disk_used failed" return 1; fi if [ ${DISK_TOTAL} -lt ${DISK_USED} ]; then log "get_disk wrong!" return 1; fi DISK_USAGE=`expr 100 \* ${DISK_USED} \/ ${DISK_TOTAL}`; return 0 } #caculate the cpu usage and io caculate_cpu_io() { #caculate the usage of CPU local old_cpu_time=0 local index=1 local tmp_cpu=0 for((index=1;index<8;index++)) do tmp_cpu=`echo "${CPU_INFO_FIRST}" | cut -d " " -f $index` let " old_cpu_time = $tmp_cpu + $old_cpu_time " done local new_cpu_time=0 tmp_cpu=0 for((index=1;index<8;index++)) do tmp_cpu=`echo "${CPU_INFO_SECOND}" | cut -d " " -f $index` let " new_cpu_time = $tmp_cpu + $new_cpu_time " done local cpu_total_diff=`expr $new_cpu_time - $old_cpu_time` local cpu_arr1=`echo "${CPU_INFO_FIRST}" | awk -F' ' '{print $4}'` local cpu_arr2=`echo "${CPU_INFO_SECOND}" | awk -F' ' '{print $4}'` local idle_time_diff=`expr $cpu_arr2 - $cpu_arr1` if [ $cpu_total_diff -eq 0 ]; then CPU_USAGE=0; else CPU_USAGE=`expr 100 \* \( $cpu_total_diff - $idle_time_diff \) \/ \( $new_cpu_time - $old_cpu_time \)`; fi #caculate the Disk io local diskio1=`echo "${IO_INFO_FIRST}" | awk -F' ' '{print $1}'` diskio1=$((${diskio1})) local diskio2=`echo "${IO_INFO_SECOND}" | awk -F' ' '{print $1}'` diskio2=$((${diskio2})) RD_IOPS=`expr \( ${diskio2} - ${diskio1} \) \/ ${GET_INFO_INTERVAL}`; diskio1=`echo "${IO_INFO_FIRST}" | awk -F' ' '{print $2}'` diskio1=$((${diskio1})) diskio2=`echo "${IO_INFO_SECOND}" | awk -F' ' '{print $2}'` diskio2=$((${diskio2})) RD_BYTEPS=`expr \( ${diskio2} - ${diskio1} \) \/ ${GET_INFO_INTERVAL}`; RD_BYTEPS=$((${RD_BYTEPS}*512)) diskio1=`echo "${IO_INFO_FIRST}" | awk -F' ' '{print $3}'` diskio1=$((${diskio1})) diskio2=`echo "${IO_INFO_SECOND}" | awk -F' ' '{print $3}'` diskio2=$((${diskio2})) WR_IOPS=`expr \( ${diskio2} - ${diskio1} \) \/ ${GET_INFO_INTERVAL}`; diskio1=`echo "${IO_INFO_FIRST}" | awk -F' ' '{print $4}'` diskio1=$((${diskio1})) diskio2=`echo "${IO_INFO_SECOND}" | awk -F' ' '{print $4}'` diskio2=$((${diskio2})) WR_BYTEPS=`expr \( ${diskio2} - ${diskio1} \) \/ ${GET_INFO_INTERVAL}`; WR_BYTEPS=$((${WR_BYTEPS}*512)) return 0; } #Get the information of CPU USAGE,IO,MEMORY get_cpu_io_mem_info() { if [ ${CPU_IO_MEM_COUNT_TIME} -eq 0 ]; then CPU_INFO_FIRST=`get_cpu_info` IO_INFO_FIRST=`get_diskio_info` get_mem_usage if [ $? -ne 0 ]; then log "get_mem_usage failed" return 1 fi fi if [ ${CPU_IO_MEM_COUNT_TIME} -ge ${GET_INFO_INTERVAL} ]; then CPU_INFO_SECOND=`get_cpu_info` IO_INFO_SECOND=`get_diskio_info` get_mem_usage if [ $? -ne 0 ]; then log "get_mem_usage failed" return 1 fi caculate_cpu_io if [ $? -ne 0 ]; then log "caculate cpu io failed" return 1 fi CPU_INFO_FIRST=${CPU_INFO_SECOND} IO_INFO_FIRST=${IO_INFO_SECOND} CPU_IO_MEM_COUNT_TIME=0 fi let " CPU_IO_MEM_COUNT_TIME = ${SEND_INTERVAL} + CPU_IO_MEM_COUNT_TIME " return 0 } #Get the report data of virtual machine get_os_info() { #Get the information of CPU USAGE,IO,MEMORY get_cpu_io_mem_info if [ $? -eq 1 ]; then log "get_cpu_diskio_usage failed" return 1; fi if [ ${DISK_COUNT_TIME} -ge ${GET_DISK_INFO_INTERVAL} ]; then #get the information of the usage of disk get_disk_info if [ $? -eq 1 ]; then log "get_disk_info failed" return 1; fi DISK_COUNT_TIME=0 fi let " DISK_COUNT_TIME = ${SEND_INTERVAL} + DISK_COUNT_TIME " if [ ${NETWORK_COUNT_TIME} -ge ${GET_NETWORK_INFO_INTERVAL} ]; then #get the information of netcard get_net_info if [ $? -eq 1 ]; then log "get_net_info failed" return 1; fi NETWORK_COUNT_TIME=0 fi let " NETWORK_COUNT_TIME = ${SEND_INTERVAL} + NETWORK_COUNT_TIME " return 0; } print_to_screen() { TMP_DATE=`date +%m/%d-%H:%M:%S` # MSG_INFO_DATA="${TMP_DATE} ${CPU_USAGE} ${MEM_USAGE} ${DISK_USAGE} ${RD_BYTEPS} ${WR_BYTEPS} ${RD_IOPS} ${WR_IOPS} ${VNETDEVS}" if [ ${TITLE_PRINT} -eq 1 ]; then echo " time cpu mem disk rd_bytes wr_bytes rd_iops wr_iops ip" TITLE_PRINT=0 fi #echo ${MSG_INFO_DATA} echo "${TMP_DATE} ${CPU_USAGE} ${MEM_USAGE} ${DISK_USAGE} ${RD_BYTEPS} ${WR_BYTEPS} ${RD_IOPS} ${WR_IOPS} ${VNETDEVS}" return 0 } save_to_file() { TMP_DATE=`date +%m/%d-%H:%M:%S` # MSG_INFO_DATA="${TMP_DATE} ${CPU_USAGE} ${MEM_USAGE} ${DISK_USAGE} ${RD_BYTEPS} ${WR_BYTEPS} ${RD_IOPS} ${WR_IOPS} ${VNETDEVS}" if [ ${TITLE_PRINT} -eq 1 ]; then echo " time cpu mem disk rd_bytes wr_bytes rd_iops wr_iops ip" >> "${shell_dir}/tmp_data.txt" TITLE_PRINT=0 fi echo "${TMP_DATE} ${CPU_USAGE} ${MEM_USAGE} ${DISK_USAGE} ${RD_BYTEPS} ${WR_BYTEPS} ${RD_IOPS} ${WR_IOPS} ${VNETDEVS}" >> "${shell_dir}/tmp_data.txt" return 0 } #Get data once get_os_info_twice() { get_os_info if [ $? -eq 1 ]; then log "get_os_info failed" return 1 fi sleep ${SEND_INTERVAL} get_os_info if [ $? -eq 1 ]; then log "get_os_info failed" return 1 fi print_to_screen || return 1 return 0 } #Get data immediately and print to screen get_os_info_real() { while true do if [ ${FIRST_TIME} -eq 1 ]; then get_os_info || return 1 FIRST_TIME=0 else get_os_info || return 1 print_to_screen || return 1 fi sleep ${SEND_INTERVAL} done } #Save the data into the file,ignore the first data,is default value save_os_info() { if [ ${FIRST_TIME} -eq 1 ]; then get_os_info || return 1 FIRST_TIME=0 else get_os_info || return 1 save_to_file || return 1 fi sleep ${SEND_INTERVAL} return 0 } #print data print_os_info() { if [ $# -eq 1 ]; then #Requires two comparative data to calculate correctly get_os_info_twice || return 1 else get_os_info_real || return 1 fi return 0 } #When printing multiple data first need to be ignored, because the first part of the default data #there is to do a comparison of the data in order to calculate after main() { if [ ${REAL} -eq 1 ]; then #print immediately print_os_info || return 1 else if [ $1 -eq 1 ]; then #print once print_os_info $1 || return 1 else echo "" > "${shell_dir}/tmp_data.txt" for((i=1;i<=$1+1;i++)); do #Saved to a file several times, the first time the data is not saved save_os_info || return 1 done fi fi return 0 } if [ $# -eq 0 ] || [ x"$1" = x'-h' ]; then echo "Usage: ./${proc_name} [OPTIONS] OBJECT " echo " OBJECT := n(type the number of times, use with -c option)" echo " OPTIONS := { -h[Help] | -c[count] | -r[real time]}" elif [ $# -eq 1 ] && [ x"$1" = x'-r' ]; then REAL=1; main || echo "main failed!" elif [ $# -eq 2 ] && [ x"$1" = x'-c' ]; then main $2 || echo "main failed!" else echo "wrong parameters!" fi
Upload File
Create Folder