From ab95769f437005e6e1ed4a9131714bc87821554e Mon Sep 17 00:00:00 2001 From: oooldking Date: Sat, 5 May 2018 13:12:00 +0800 Subject: [PATCH] new version --- superbench.sh | 676 +++++++++++++++++++++++++++++++++++----------- superbench_git.sh | 1 + superbench_old.sh | 272 +++++++++++++++++++ 3 files changed, 785 insertions(+), 164 deletions(-) create mode 100644 superbench_old.sh diff --git a/superbench.sh b/superbench.sh index c4fc6a5..4c4de27 100644 --- a/superbench.sh +++ b/superbench.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash # -# Description: Auto test download & I/O speed & network to China script +# Description: Auto system info & I/O test & network to China script # -# Copyright (C) 2017 - 2017 Oldking +# Copyright (C) 2017 - 2018 Oldking # # Thanks: Bench.sh # @@ -16,60 +16,153 @@ YELLOW='\033[0;33m' SKYBLUE='\033[0;36m' PLAIN='\033[0m' -# check release -if [ -f /etc/redhat-release ]; then - release="centos" -elif cat /etc/issue | grep -Eqi "debian"; then - release="debian" -elif cat /etc/issue | grep -Eqi "ubuntu"; then - release="ubuntu" -elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then - release="centos" -elif cat /proc/version | grep -Eqi "debian"; then - release="debian" -elif cat /proc/version | grep -Eqi "ubuntu"; then - release="ubuntu" -elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then - release="centos" -fi +about () { + echo "" + echo " ========================================================= " + echo " \ Superbench.sh Script / " + echo " \ Basic system info, I/O test and speedtest / " + echo " \ v1.0 (24 Feb 2018) / " + echo " \ Created by Oldking / " + echo " ========================================================= " + echo "" + echo " Intro: https://www.oldking.net/350.html" + echo " Copyright (C) 2018 Oldking oooldking@gmail.com" + echo " The previous version: superbench_old.sh" + echo "" +} -# check root -[[ $EUID -ne 0 ]] && echo -e "${RED}Error:${PLAIN} This script must be run as root!" && exit 1 - -# check python -if [ ! -e '/usr/bin/python' ]; then - #echo -e - #read -p "${RED}Error:${PLAIN} python is not install. You must be install python command at first.\nDo you want to install? [y/n]" is_install - #if [[ ${is_install} == "y" || ${is_install} == "Y" ]]; then - if [ "${release}" == "centos" ]; then - yum update > /dev/null 2>&1 - yum -y install python - else - apt-get update > /dev/null 2>&1 - apt-get -y install python - fi - #else - # exit - #fi - -fi +cancel () { + echo "" + next; + cleanup; + echo " Abort ..." + echo " Cleanup ..." + exit +} -# check wget -if [ ! -e '/usr/bin/wget' ]; then - #echo -e - #read -p "${RED}Error:${PLAIN} wget is not install. You must be install wget command at first.\nDo you want to install? [y/n]" is_install - #if [[ ${is_install} == "y" || ${is_install} == "Y" ]]; then - if [ "${release}" == "centos" ]; then - yum update > /dev/null 2>&1 - yum -y install wget - else - apt-get update > /dev/null 2>&1 - apt-get -y install wget - fi - #else - # exit - #fi -fi +trap cancel SIGINT + +benchinit() { + # check release + if [ -f /etc/redhat-release ]; then + release="centos" + elif cat /etc/issue | grep -Eqi "debian"; then + release="debian" + elif cat /etc/issue | grep -Eqi "ubuntu"; then + release="ubuntu" + elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then + release="centos" + elif cat /proc/version | grep -Eqi "debian"; then + release="debian" + elif cat /proc/version | grep -Eqi "ubuntu"; then + release="ubuntu" + elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then + release="centos" + fi + + # check root + [[ $EUID -ne 0 ]] && echo -e "${RED}Error:${PLAIN} This script must be run as root!" && exit 1 + + # check python + if [ ! -e '/usr/bin/python' ]; then + #echo -e + #read -p "${RED}Error:${PLAIN} python is not install. You must be install python command at first.\nDo you want to install? [y/n]" is_install + #if [[ ${is_install} == "y" || ${is_install} == "Y" ]]; then + echo " Installing Python ..." + if [ "${release}" == "centos" ]; then + yum update > /dev/null 2>&1 + yum -y install python > /dev/null 2>&1 + else + apt-get update > /dev/null 2>&1 + apt-get -y install python > /dev/null 2>&1 + fi + #else + # exit + #fi + + fi + + # check curl + if [ ! -e '/usr/bin/curl' ]; then + #echo -e + #read -p "${RED}Error:${PLAIN} curl is not install. You must be install curl command at first.\nDo you want to install? [y/n]" is_install + #if [[ ${is_install} == "y" || ${is_install} == "Y" ]]; then + echo " Installing Curl ..." + if [ "${release}" == "centos" ]; then + yum update > /dev/null 2>&1 + yum -y install curl > /dev/null 2>&1 + else + apt-get update > /dev/null 2>&1 + apt-get -y install curl > /dev/null 2>&1 + fi + #else + # exit + #fi + fi + + # check wget + if [ ! -e '/usr/bin/wget' ]; then + #echo -e + #read -p "${RED}Error:${PLAIN} wget is not install. You must be install wget command at first.\nDo you want to install? [y/n]" is_install + #if [[ ${is_install} == "y" || ${is_install} == "Y" ]]; then + echo " Installing Wget ..." + if [ "${release}" == "centos" ]; then + yum update > /dev/null 2>&1 + yum -y install wget > /dev/null 2>&1 + else + apt-get update > /dev/null 2>&1 + apt-get -y install wget > /dev/null 2>&1 + fi + #else + # exit + #fi + fi + + # install virt-what + #if [ ! -e '/usr/sbin/virt-what' ]; then + # echo "Installing Virt-what ..." + # if [ "${release}" == "centos" ]; then + # yum update > /dev/null 2>&1 + # yum -y install virt-what > /dev/null 2>&1 + # else + # apt-get update > /dev/null 2>&1 + # apt-get -y install virt-what > /dev/null 2>&1 + # fi + #fi + + # install jq + if [ ! -e '/usr/bin/jq' ]; then + echo " Installing Jq ..." + if [ "${release}" == "centos" ]; then + yum update > /dev/null 2>&1 + yum -y install jq > /dev/null 2>&1 + else + apt-get update > /dev/null 2>&1 + apt-get -y install jq > /dev/null 2>&1 + fi + fi + + # install speedtest-cli + if [ ! -e 'speedtest.py' ]; then + echo " Installing Speedtest-cli ..." + wget --no-check-certificate https://raw.github.com/sivel/speedtest-cli/master/speedtest.py > /dev/null 2>&1 + fi + chmod a+rx speedtest.py + + # install fast.com-cli + if [ ! -e 'fast_com.py' ]; then + echo " Installing Fast.com-cli ..." + wget --no-check-certificate https://raw.githubusercontent.com/sanderjo/fast.com/master/fast_com.py > /dev/null 2>&1 + wget --no-check-certificate https://raw.githubusercontent.com/sanderjo/fast.com/master/fast_com_example_usage.py > /dev/null 2>&1 + fi + chmod a+rx fast_com.py + chmod a+rx fast_com_example_usage.py + + sleep 5 + + # start + start=$(date +%s) +} get_opsy() { [ -f /etc/redhat-release ] && awk '{print ($1,$3~/^[0-9]/?$3:$4)}' /etc/redhat-release && return @@ -78,12 +171,12 @@ get_opsy() { } next() { - printf "%-70s\n" "-" | sed 's/\s/-/g' + printf "%-70s\n" "-" | sed 's/\s/-/g' | tee -a $log } speed_test(){ if [[ $1 == '' ]]; then - temp=$(python /tmp/speedtest.py --share 2>&1) + temp=$(python speedtest.py --share 2>&1) is_down=$(echo "$temp" | grep 'Download') if [[ ${is_down} ]]; then local REDownload=$(echo "$temp" | awk -F ':' '/Download/{print $2}') @@ -91,12 +184,12 @@ speed_test(){ local relatency=$(echo "$temp" | awk -F ':' '/Hosted/{print $2}') local nodeName=$2 - printf "${YELLOW}%-17s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" "${nodeName}" "${reupload}" "${REDownload}" "${relatency}" + printf "${YELLOW}%-17s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" " ${nodeName}" "${reupload}" "${REDownload}" "${relatency}" | tee -a $log else local cerror="ERROR" fi else - temp=$(python /tmp/speedtest.py --server $1 --share 2>&1) + temp=$(python speedtest.py --server $1 --share 2>&1) is_down=$(echo "$temp" | grep 'Download') if [[ ${is_down} ]]; then local REDownload=$(echo "$temp" | awk -F ':' '/Download/{print $2}') @@ -108,40 +201,62 @@ speed_test(){ fi local nodeName=$2 - printf "${YELLOW}%-17s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" "${nodeName}" "${reupload}" "${REDownload}" "${relatency}" + printf "${YELLOW}%-17s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" " ${nodeName}" "${reupload}" "${REDownload}" "${relatency}" | tee -a $log else local cerror="ERROR" fi fi } -speed() { - # install speedtest - if [ ! -e '/tmp/speedtest.py' ]; then - wget --no-check-certificate -P /tmp https://raw.github.com/sivel/speedtest-cli/master/speedtest.py > /dev/null 2>&1 - fi - chmod a+rx /tmp/speedtest.py - - speed_test '' 'Normal Node' - speed_test '6435' 'Xiangyang CT' +print_speedtest() { + printf "%-18s%-18s%-20s%-12s\n" " Node Name" "Upload Speed" "Download Speed" "Latency" | tee -a $log + speed_test '' 'Speedtest.net' + speed_test '3633' 'Shanghai CT' speed_test '7509' 'Kunming CT' - speed_test '3633' 'Shanghai CT' speed_test '4624' 'Chengdu CT' - speed_test '5017' 'Shenyang CU' - speed_test '4863' "Xi'an CU" speed_test '5083' 'Shanghai CU' + speed_test '4863' "Xi'an CU" speed_test '5726' 'Chongqing CU' + speed_test '4665' 'Shanghai CM' speed_test '5292' "Xi'an CM" - speed_test '16314' 'Shandong CM' - speed_test '6715' 'Ningbo CM' speed_test '4575' 'Chengdu CM' - rm -rf /tmp/speedtest.py + rm -rf speedtest.py } +print_speedtest_fast() { + printf "%-18s%-18s%-20s%-12s\n" " Node Name" "Upload Speed" "Download Speed" "Latency" | tee -a $log + speed_test '' 'Speedtest.net' + speed_fast_com + speed_test '7509' 'Kunming CT' + speed_test '5083' 'Shanghai CU' + speed_test '4575' 'Chengdu CM' + + rm -rf speedtest.py +} + +speed_fast_com() { + temp=$(python fast_com_example_usage.py 2>&1) + is_down=$(echo "$temp" | grep 'Result') + if [[ ${is_down} ]]; then + temp1=$(echo "$temp" | awk -F ':' '/Result/{print $2}') + temp2=$(echo "$temp1" | awk -F ' ' '/Mbps/{print $1}') + local REDownload="$temp2 Mbit/s" + local reupload="00.00 Mbit/s" + local relatency="000.000 ms" + local nodeName="Fast.com" + + printf "${YELLOW}%-18s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" " ${nodeName}" "${reupload}" "${REDownload}" "${relatency}" | tee -a $log + else + local cerror="ERROR" + fi + rm -rf fast_com_example_usage.py + rm -rf fast_com.py + +} io_test() { - (LANG=C dd if=/dev/zero of=test_$$ bs=$1 count=$2 conv=fdatasync && rm -f test_$$ ) 2>&1 | awk -F, '{io=$NF} END { print io}' | sed 's/^[ \t]*//;s/[ \t]*$//' + (LANG=C dd if=/dev/zero of=test_file_$$ bs=512K count=$1 conv=fdatasync && rm -f test_file_$$ ) 2>&1 | awk -F, '{io=$NF} END { print io}' | sed 's/^[ \t]*//;s/[ \t]*$//' } calc_disk() { @@ -167,6 +282,7 @@ power_time() { install_smart() { # install smartctl if [ ! -e '/usr/sbin/smartctl' ]; then + echo "Installing Smartctl ..." if [ "${release}" == "centos" ]; then yum update > /dev/null 2>&1 yum -y install smartmontools > /dev/null 2>&1 @@ -177,96 +293,328 @@ install_smart() { fi } -start=$(date +%s) - -cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) -cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo ) -freq=$( awk -F: '/cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) -tram=$( free -m | awk '/Mem/ {print $2}' ) -uram=$( free -m | awk '/Mem/ {print $3}' ) -swap=$( free -m | awk '/Swap/ {print $2}' ) -uswap=$( free -m | awk '/Swap/ {print $3}' ) -up=$( awk '{a=$1/86400;b=($1%86400)/3600;c=($1%3600)/60} {printf("%d days %d hour %d min\n",a,b,c)}' /proc/uptime ) -load=$( w | head -1 | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//' ) -opsy=$( get_opsy ) -arch=$( uname -m ) -lbit=$( getconf LONG_BIT ) -kern=$( uname -r ) -ipv6=$( wget -qO- -t1 -T2 ipv6.icanhazip.com ) -disk_size1=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $2}' )) -disk_size2=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $3}' )) -disk_total_size=$( calc_disk ${disk_size1[@]} ) -disk_used_size=$( calc_disk ${disk_size2[@]} ) -ptime=$(power_time) - - -clear -next -echo -e "CPU model : ${SKYBLUE}$cname${PLAIN}" -echo -e "Number of cores : ${SKYBLUE}$cores${PLAIN}" -echo -e "CPU frequency : ${SKYBLUE}$freq MHz${PLAIN}" -echo -e "Total size of Disk : ${SKYBLUE}$disk_total_size GB ($disk_used_size GB Used)${PLAIN}" -echo -e "Total amount of Mem : ${SKYBLUE}$tram MB ($uram MB Used)${PLAIN}" -echo -e "Total amount of Swap : ${SKYBLUE}$swap MB ($uswap MB Used)${PLAIN}" -echo -e "System uptime : ${SKYBLUE}$up${PLAIN}" -echo -e "Load average : ${SKYBLUE}$load${PLAIN}" -echo -e "OS : ${SKYBLUE}$opsy${PLAIN}" -echo -e "Arch : ${SKYBLUE}$arch ($lbit Bit)${PLAIN}" -echo -e "Kernel : ${SKYBLUE}$kern${PLAIN}" -echo -ne "Virt : " - -# install virt-what -if [ ! -e '/usr/sbin/virt-what' ]; then - if [ "${release}" == "centos" ]; then - yum update > /dev/null 2>&1 - yum -y install virt-what > /dev/null 2>&1 - else - apt-get update > /dev/null 2>&1 - apt-get -y install virt-what > /dev/null 2>&1 - fi -fi -virtua=$(virt-what) 2>/dev/null +ip_info(){ + # use jq tool + result=$(curl -s 'http://ip-api.com/json') + country=$(echo $result | jq '.country' | sed 's/\"//g') + city=$(echo $result | jq '.city' | sed 's/\"//g') + isp=$(echo $result | jq '.isp' | sed 's/\"//g') + as_tmp=$(echo $result | jq '.as' | sed 's/\"//g') + asn=$(echo $as_tmp | awk -F ' ' '{print $1}') + org=$(echo $result | jq '.org' | sed 's/\"//g') + countryCode=$(echo $result | jq '.countryCode' | sed 's/\"//g') + region=$(echo $result | jq '.regionName' | sed 's/\"//g') + + echo -e " ASN & ISP : ${SKYBLUE}$asn, $isp${PLAIN}" | tee -a $log + echo -e " Organization : ${SKYBLUE}$org${PLAIN}" | tee -a $log + echo -e " Location : ${SKYBLUE}$city, $country / $countryCode${PLAIN}" | tee -a $log + echo -e " Region : ${SKYBLUE}$region${PLAIN}" | tee -a $log +} + +ip_info2(){ + # no jq + country=$(curl -s https://ipapi.co/country_name/) + city=$(curl -s https://ipapi.co/city/) + asn=$(curl -s https://ipapi.co/asn/) + org=$(curl -s https://ipapi.co/org/) + countryCode=$(curl -s https://ipapi.co/country/) + region=$(curl -s https://ipapi.co/region/) + + echo -e " ASN & ISP : ${SKYBLUE}$asn${PLAIN}" | tee -a $log + echo -e " Organization : ${SKYBLUE}$org${PLAIN}" | tee -a $log + echo -e " Location : ${SKYBLUE}$city, $country / $countryCode${PLAIN}" | tee -a $log + echo -e " Region : ${SKYBLUE}$region${PLAIN}" | tee -a $log +} + +virt_check(){ + if hash ifconfig 2>/dev/null; then + eth=$(ifconfig) + fi + + virtualx=$(dmesg) 2>/dev/null + + if grep docker /proc/1/cgroup -qa; then + virtual="Docker" + elif grep lxc /proc/1/cgroup -qa; then + virtual="Lxc" + elif [[ -f /proc/user_beancounters ]]; then + virtual="OpenVZ" + elif [[ "$virtualx" == *kvm-clock* ]]; then + virtual="KVM" + elif [[ "$virtualx" == *"VMware Virtual Platform"* ]]; then + virtual="VMware" + elif [[ "$virtualx" == *"Parallels Software International"* ]]; then + virtual="Parallels" + elif [[ "$virtualx" == *VirtualBox* ]]; then + virtual="VirtualBox" + elif [[ -e /proc/xen ]]; then + virtual="Xen" + else + virtual="Dedicated" + fi +} -if [[ ${virtua} ]]; then - echo -e "${SKYBLUE}$virtua${PLAIN}" -else - echo -e "${SKYBLUE}No Virt${PLAIN}" - echo -ne "Power time of disk : " +power_time_check(){ + echo -ne " Power time of disk : " install_smart + ptime=$(power_time) echo -e "${SKYBLUE}$ptime Hours${PLAIN}" +} + +freedisk() { + # check free space + freespace=$( df -m . | awk 'NR==2 {print $4}' ) + if [[ $freespace -gt 1024 ]]; then + printf "%s" $((1024*2)) + elif [[ $freespace -gt 512 ]]; then + printf "%s" $((512*2)) + elif [[ $freespace -gt 256 ]]; then + printf "%s" $((256*2)) + elif [[ $freespace -gt 128 ]]; then + printf "%s" $((128*2)) + else + printf 1 + fi +} + +print_io() { + if [[ $1 == "fast" ]]; then + writemb=$((128*2)) + else + writemb=$(freedisk) + fi + + writemb_size="$(( writemb / 2 ))MB" + if [[ $writemb_size == "1024MB" ]]; then + writemb_size="1.0GB" + fi + + if [[ $writemb != "1" ]]; then + echo -n " I/O Speed( $writemb_size ) : " | tee -a $log + io1=$( io_test $writemb ) + echo -e "${YELLOW}$io1${PLAIN}" | tee -a $log + echo -n " I/O Speed( $writemb_size ) : " | tee -a $log + io2=$( io_test $writemb ) + echo -e "${YELLOW}$io2${PLAIN}" | tee -a $log + echo -n " I/O Speed( $writemb_size ) : " | tee -a $log + io3=$( io_test $writemb ) + echo -e "${YELLOW}$io3${PLAIN}" | tee -a $log + ioraw1=$( echo $io1 | awk 'NR==1 {print $1}' ) + [ "`echo $io1 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw1=$( awk 'BEGIN{print '$ioraw1' * 1024}' ) + ioraw2=$( echo $io2 | awk 'NR==1 {print $1}' ) + [ "`echo $io2 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw2=$( awk 'BEGIN{print '$ioraw2' * 1024}' ) + ioraw3=$( echo $io3 | awk 'NR==1 {print $1}' ) + [ "`echo $io3 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw3=$( awk 'BEGIN{print '$ioraw3' * 1024}' ) + ioall=$( awk 'BEGIN{print '$ioraw1' + '$ioraw2' + '$ioraw3'}' ) + ioavg=$( awk 'BEGIN{printf "%.1f", '$ioall' / 3}' ) + echo -e " Average I/O Speed : ${YELLOW}$ioavg MB/s${PLAIN}" | tee -a $log + else + echo -e " ${RED}Not enough space!${PLAIN}" + fi +} + +print_system_info() { + echo -e " CPU Model : ${SKYBLUE}$cname${PLAIN}" | tee -a $log + echo -e " CPU Cores : ${SKYBLUE}$cores Cores @ $freq MHz${PLAIN}" | tee -a $log + echo -e " CPU Cache : ${SKYBLUE}$corescache${PLAIN}" | tee -a $log + echo -e " OS : ${SKYBLUE}$opsy $arch ($lbit Bit)${PLAIN}" | tee -a $log + echo -e " Kernel : ${SKYBLUE}$virtual / $kern${PLAIN}" | tee -a $log + echo -e " Total size of Disk : ${SKYBLUE}$disk_total_size GB ($disk_used_size GB Used)${PLAIN}" | tee -a $log + echo -e " Total amount of Mem : ${SKYBLUE}$tram MB ($uram MB Used)${PLAIN}" | tee -a $log + echo -e " Total amount of Swap : ${SKYBLUE}$swap MB ($uswap MB Used)${PLAIN}" | tee -a $log + echo -e " System uptime : ${SKYBLUE}$up${PLAIN}" | tee -a $log + echo -e " Load average : ${SKYBLUE}$load${PLAIN}" | tee -a $log +} + +print_end_time() { + end=$(date +%s) + time=$(( $end - $start )) + if [[ $time -gt 60 ]]; then + min=$(expr $time / 60) + sec=$(expr $time % 60) + echo -ne " Finished in : ${min} min ${sec} sec" | tee -a $log + else + echo -ne " Finished in : ${time} sec" | tee -a $log + fi + #echo -ne "\n Current time : " + #echo $(date +%Y-%m-%d" "%H:%M:%S) + printf '\n' | tee -a $log + #utc_time=$(date -u '+%F %T') + #bj_time=$(date +%Y-%m-%d" "%H:%M:%S -d '+8 hours') + bj_time=$(curl -s http://cgi.im.qq.com/cgi-bin/cgi_svrtime) + #utc_time=$(date +"$bj_time" -d '-8 hours') + + if [[ $(echo $bj_time | grep "html") ]]; then + bj_time=$(date -u +%Y-%m-%d" "%H:%M:%S -d '+8 hours') + fi + echo " Timestamp : $bj_time GMT+8" | tee -a $log + #echo " Finished!" + echo " Results : $log" +} + +get_system_info() { + cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) + cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo ) + freq=$( awk -F: '/cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) + corescache=$( awk -F: '/cache size/ {cache=$2} END {print cache}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) + tram=$( free -m | awk '/Mem/ {print $2}' ) + uram=$( free -m | awk '/Mem/ {print $3}' ) + swap=$( free -m | awk '/Swap/ {print $2}' ) + uswap=$( free -m | awk '/Swap/ {print $3}' ) + up=$( awk '{a=$1/86400;b=($1%86400)/3600;c=($1%3600)/60} {printf("%d days %d hour %d min\n",a,b,c)}' /proc/uptime ) + load=$( w | head -1 | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//' ) + opsy=$( get_opsy ) + arch=$( uname -m ) + lbit=$( getconf LONG_BIT ) + kern=$( uname -r ) + #ipv6=$( wget -qO- -t1 -T2 ipv6.icanhazip.com ) + disk_size1=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $2}' )) + disk_size2=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $3}' )) + disk_total_size=$( calc_disk ${disk_size1[@]} ) + disk_used_size=$( calc_disk ${disk_size2[@]} ) + virt_check +} + +print_intro() { + printf ' Superbench.sh v1.0 -- https://www.oldking.net/350.html\n' | tee -a $log + printf ' Mode : %s\n' $mode_name | tee -a $log + printf ' Usage : wget -qO- git.io/superbench.sh | bash\n' | tee -a $log +} + +sharetest() { + log_preupload + case $1 in + 'ubuntu') + share_link=$( curl -v --data-urlencode "content@$log_up" -d "poster=superbench.sh" -d "syntax=text" "https://paste.ubuntu.com" 2>&1 | \ + grep "Location" | awk '{print $3}' );; + 'haste' ) + share_link=$( curl -X POST -s -d "$(cat $log)" https://hastebin.com/documents | awk -F '"' '{print "https://hastebin.com/"$4}' );; + 'clbin' ) + share_link=$( curl -sF 'clbin=<-' https://clbin.com < $log );; + 'ptpb' ) + share_link=$( curl -sF c=@- https://ptpb.pw/?u=1 < $log );; + esac + + # print result info + echo " Share result:" | tee -a $log + echo " $share_link" | tee -a $log + next + echo "" + rm -f $log_up + +} + +log_preupload() { + log_up="$HOME/superbench_upload.log" + true > $log_up + $(cat superbench.log 2>&1 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" > $log_up) +} + +get_ip_whois_org_name(){ + #ip=$(curl -s ip.sb) + result=$(curl -s https://rest.db.ripe.net/search.json?query-string=$(curl -s ip.sb)) + #org_name=$(echo $result | jq '.objects.object.[1].attributes.attribute.[1].value' | sed 's/\"//g') + org_name=$(echo $result | jq '.objects.object[1].attributes.attribute[1]' | sed 's/\"//g') + echo $org_name; +} + +cleanup() { + rm -f test_file_*; + rm -f speedtest.py; + rm -f fast_com* + +} + +bench_all(){ + mode_name="standard" + about; + benchinit; + clear + next; + print_intro; + next; + get_system_info; + print_system_info; + ip_info; + next; + print_io; + next; + print_speedtest; + next; + print_end_time; + next; + cleanup; +} + +fast_bench(){ + mode_name="fast" + about; + benchinit; + clear + next; + print_intro; + next; + get_system_info; + print_system_info; + ip_info; + next; + print_io fast; + next; + print_speedtest_fast; + next; + print_end_time; + next; + cleanup; +} + + + + +log="$HOME/superbench.log" +true > $log + +case $1 in + 'info'|'-i'|'--i'|'-info'|'--info' ) + about;sleep 3;next;get_system_info;print_system_info;next;; + 'version'|'-v'|'--v'|'-version'|'--version') + next;about;next;; + 'io'|'-io'|'--io'|'-drivespeed'|'--drivespeed' ) + next;print_io;next;; + 'speed'|'-speed'|'--speed'|'-speedtest'|'--speedtest'|'-speedcheck'|'--speedcheck' ) + about;benchinit;next;print_speedtest;next;; + 'ip'|'-ip'|'--ip'|'geoip'|'-geoip'|'--geoip' ) + about;benchinit;next;ip_info;next;; + 'bench'|'-a'|'--a'|'-all'|'--all'|'-bench'|'--bench' ) + bench_all;; + 'about'|'-about'|'--about' ) + about;; + 'fast'|'-f'|'--f'|'-fast'|'--fast' ) + fast_bench;; + 'share'|'-s'|'--s'|'-share'|'--share' ) + bench_all; + is_share="share" + if [[ $2 == "" ]]; then + sharetest ubuntu; + else + sharetest $2; + fi + ;; + 'debug'|'-d'|'--d'|'-debug'|'--debug' ) + get_ip_whois_org_name;; +*) + bench_all;; +esac + + + +if [[ ! $is_share == "share" ]]; then + case $2 in + 'share'|'-s'|'--s'|'-share'|'--share' ) + if [[ $3 == '' ]]; then + sharetest ubuntu; + else + sharetest $3; + fi + ;; + esac fi -next -echo -n "I/O speed( 32M ) : " -io1=$( io_test 32k 1k ) -echo -e "${YELLOW}$io1${PLAIN}" -echo -n "I/O speed( 256M ) : " -io2=$( io_test 64k 4k ) -echo -e "${YELLOW}$io2${PLAIN}" -echo -n "I/O speed( 2G ) : " -io3=$( io_test 64k 32k ) -echo -e "${YELLOW}$io3${PLAIN}" -ioraw1=$( echo $io1 | awk 'NR==1 {print $1}' ) -[ "`echo $io1 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw1=$( awk 'BEGIN{print '$ioraw1' * 1024}' ) -ioraw2=$( echo $io2 | awk 'NR==1 {print $1}' ) -[ "`echo $io2 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw2=$( awk 'BEGIN{print '$ioraw2' * 1024}' ) -ioraw3=$( echo $io3 | awk 'NR==1 {print $1}' ) -[ "`echo $io3 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw3=$( awk 'BEGIN{print '$ioraw3' * 1024}' ) -ioall=$( awk 'BEGIN{print '$ioraw1' + '$ioraw2' + '$ioraw3'}' ) -ioavg=$( awk 'BEGIN{printf "%.1f", '$ioall' / 3}' ) -echo -e "Average I/O speed : ${YELLOW}$ioavg MB/s${PLAIN}" -next -printf "%-18s%-18s%-20s%-12s\n" "Node Name" "Upload Speed" "Download Speed" "Latency" -speed && next -end=$(date +%s) -time=$(( $end - $start )) -if [[ $time -gt 60 ]]; then - min=$(expr $time / 60) - sec=$(expr $time % 60) - echo -ne "Total time : ${min} min ${sec} sec" -else - echo -ne "Total time : ${time} sec" -fi -echo -ne "\nCurrent time : " -echo $(date +%Y-%m-%d" "%H:%M:%S) -echo "Finished!" -next \ No newline at end of file diff --git a/superbench_git.sh b/superbench_git.sh index 956f042..4c4de27 100644 --- a/superbench_git.sh +++ b/superbench_git.sh @@ -27,6 +27,7 @@ about () { echo "" echo " Intro: https://www.oldking.net/350.html" echo " Copyright (C) 2018 Oldking oooldking@gmail.com" + echo " The previous version: superbench_old.sh" echo "" } diff --git a/superbench_old.sh b/superbench_old.sh new file mode 100644 index 0000000..c4fc6a5 --- /dev/null +++ b/superbench_old.sh @@ -0,0 +1,272 @@ +#!/usr/bin/env bash +# +# Description: Auto test download & I/O speed & network to China script +# +# Copyright (C) 2017 - 2017 Oldking +# +# Thanks: Bench.sh +# +# URL: https://www.oldking.net/350.html +# + +# Colors +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +SKYBLUE='\033[0;36m' +PLAIN='\033[0m' + +# check release +if [ -f /etc/redhat-release ]; then + release="centos" +elif cat /etc/issue | grep -Eqi "debian"; then + release="debian" +elif cat /etc/issue | grep -Eqi "ubuntu"; then + release="ubuntu" +elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then + release="centos" +elif cat /proc/version | grep -Eqi "debian"; then + release="debian" +elif cat /proc/version | grep -Eqi "ubuntu"; then + release="ubuntu" +elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then + release="centos" +fi + +# check root +[[ $EUID -ne 0 ]] && echo -e "${RED}Error:${PLAIN} This script must be run as root!" && exit 1 + +# check python +if [ ! -e '/usr/bin/python' ]; then + #echo -e + #read -p "${RED}Error:${PLAIN} python is not install. You must be install python command at first.\nDo you want to install? [y/n]" is_install + #if [[ ${is_install} == "y" || ${is_install} == "Y" ]]; then + if [ "${release}" == "centos" ]; then + yum update > /dev/null 2>&1 + yum -y install python + else + apt-get update > /dev/null 2>&1 + apt-get -y install python + fi + #else + # exit + #fi + +fi + +# check wget +if [ ! -e '/usr/bin/wget' ]; then + #echo -e + #read -p "${RED}Error:${PLAIN} wget is not install. You must be install wget command at first.\nDo you want to install? [y/n]" is_install + #if [[ ${is_install} == "y" || ${is_install} == "Y" ]]; then + if [ "${release}" == "centos" ]; then + yum update > /dev/null 2>&1 + yum -y install wget + else + apt-get update > /dev/null 2>&1 + apt-get -y install wget + fi + #else + # exit + #fi +fi + +get_opsy() { + [ -f /etc/redhat-release ] && awk '{print ($1,$3~/^[0-9]/?$3:$4)}' /etc/redhat-release && return + [ -f /etc/os-release ] && awk -F'[= "]' '/PRETTY_NAME/{print $3,$4,$5}' /etc/os-release && return + [ -f /etc/lsb-release ] && awk -F'[="]+' '/DESCRIPTION/{print $2}' /etc/lsb-release && return +} + +next() { + printf "%-70s\n" "-" | sed 's/\s/-/g' +} + +speed_test(){ + if [[ $1 == '' ]]; then + temp=$(python /tmp/speedtest.py --share 2>&1) + is_down=$(echo "$temp" | grep 'Download') + if [[ ${is_down} ]]; then + local REDownload=$(echo "$temp" | awk -F ':' '/Download/{print $2}') + local reupload=$(echo "$temp" | awk -F ':' '/Upload/{print $2}') + local relatency=$(echo "$temp" | awk -F ':' '/Hosted/{print $2}') + local nodeName=$2 + + printf "${YELLOW}%-17s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" "${nodeName}" "${reupload}" "${REDownload}" "${relatency}" + else + local cerror="ERROR" + fi + else + temp=$(python /tmp/speedtest.py --server $1 --share 2>&1) + is_down=$(echo "$temp" | grep 'Download') + if [[ ${is_down} ]]; then + local REDownload=$(echo "$temp" | awk -F ':' '/Download/{print $2}') + local reupload=$(echo "$temp" | awk -F ':' '/Upload/{print $2}') + local relatency=$(echo "$temp" | awk -F ':' '/Hosted/{print $2}') + temp=$(echo "$relatency" | awk -F '.' '{print $1}') + if [[ ${temp} -gt 1000 ]]; then + relatency=" 000.000 ms" + fi + local nodeName=$2 + + printf "${YELLOW}%-17s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" "${nodeName}" "${reupload}" "${REDownload}" "${relatency}" + else + local cerror="ERROR" + fi + fi +} + +speed() { + # install speedtest + if [ ! -e '/tmp/speedtest.py' ]; then + wget --no-check-certificate -P /tmp https://raw.github.com/sivel/speedtest-cli/master/speedtest.py > /dev/null 2>&1 + fi + chmod a+rx /tmp/speedtest.py + + speed_test '' 'Normal Node' + speed_test '6435' 'Xiangyang CT' + speed_test '7509' 'Kunming CT' + speed_test '3633' 'Shanghai CT' + speed_test '4624' 'Chengdu CT' + speed_test '5017' 'Shenyang CU' + speed_test '4863' "Xi'an CU" + speed_test '5083' 'Shanghai CU' + speed_test '5726' 'Chongqing CU' + speed_test '5292' "Xi'an CM" + speed_test '16314' 'Shandong CM' + speed_test '6715' 'Ningbo CM' + speed_test '4575' 'Chengdu CM' + + rm -rf /tmp/speedtest.py +} + + +io_test() { + (LANG=C dd if=/dev/zero of=test_$$ bs=$1 count=$2 conv=fdatasync && rm -f test_$$ ) 2>&1 | awk -F, '{io=$NF} END { print io}' | sed 's/^[ \t]*//;s/[ \t]*$//' +} + +calc_disk() { + local total_size=0 + local array=$@ + for size in ${array[@]} + do + [ "${size}" == "0" ] && size_t=0 || size_t=`echo ${size:0:${#size}-1}` + [ "`echo ${size:(-1)}`" == "K" ] && size=0 + [ "`echo ${size:(-1)}`" == "M" ] && size=$( awk 'BEGIN{printf "%.1f", '$size_t' / 1024}' ) + [ "`echo ${size:(-1)}`" == "T" ] && size=$( awk 'BEGIN{printf "%.1f", '$size_t' * 1024}' ) + [ "`echo ${size:(-1)}`" == "G" ] && size=${size_t} + total_size=$( awk 'BEGIN{printf "%.1f", '$total_size' + '$size'}' ) + done + echo ${total_size} +} + +power_time() { + + result=$(smartctl -a $(result=$(cat /proc/mounts) && echo $(echo "$result" | awk '/data=ordered/{print $1}') | awk '{print $1}') 2>&1) && power_time=$(echo "$result" | awk '/Power_On/{print $10}') && echo "$power_time" +} + +install_smart() { + # install smartctl + if [ ! -e '/usr/sbin/smartctl' ]; then + if [ "${release}" == "centos" ]; then + yum update > /dev/null 2>&1 + yum -y install smartmontools > /dev/null 2>&1 + else + apt-get update > /dev/null 2>&1 + apt-get -y install smartmontools > /dev/null 2>&1 + fi + fi +} + +start=$(date +%s) + +cname=$( awk -F: '/model name/ {name=$2} END {print name}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) +cores=$( awk -F: '/model name/ {core++} END {print core}' /proc/cpuinfo ) +freq=$( awk -F: '/cpu MHz/ {freq=$2} END {print freq}' /proc/cpuinfo | sed 's/^[ \t]*//;s/[ \t]*$//' ) +tram=$( free -m | awk '/Mem/ {print $2}' ) +uram=$( free -m | awk '/Mem/ {print $3}' ) +swap=$( free -m | awk '/Swap/ {print $2}' ) +uswap=$( free -m | awk '/Swap/ {print $3}' ) +up=$( awk '{a=$1/86400;b=($1%86400)/3600;c=($1%3600)/60} {printf("%d days %d hour %d min\n",a,b,c)}' /proc/uptime ) +load=$( w | head -1 | awk -F'load average:' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//' ) +opsy=$( get_opsy ) +arch=$( uname -m ) +lbit=$( getconf LONG_BIT ) +kern=$( uname -r ) +ipv6=$( wget -qO- -t1 -T2 ipv6.icanhazip.com ) +disk_size1=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $2}' )) +disk_size2=($( LANG=C df -hPl | grep -wvE '\-|none|tmpfs|devtmpfs|by-uuid|chroot|Filesystem' | awk '{print $3}' )) +disk_total_size=$( calc_disk ${disk_size1[@]} ) +disk_used_size=$( calc_disk ${disk_size2[@]} ) +ptime=$(power_time) + + +clear +next +echo -e "CPU model : ${SKYBLUE}$cname${PLAIN}" +echo -e "Number of cores : ${SKYBLUE}$cores${PLAIN}" +echo -e "CPU frequency : ${SKYBLUE}$freq MHz${PLAIN}" +echo -e "Total size of Disk : ${SKYBLUE}$disk_total_size GB ($disk_used_size GB Used)${PLAIN}" +echo -e "Total amount of Mem : ${SKYBLUE}$tram MB ($uram MB Used)${PLAIN}" +echo -e "Total amount of Swap : ${SKYBLUE}$swap MB ($uswap MB Used)${PLAIN}" +echo -e "System uptime : ${SKYBLUE}$up${PLAIN}" +echo -e "Load average : ${SKYBLUE}$load${PLAIN}" +echo -e "OS : ${SKYBLUE}$opsy${PLAIN}" +echo -e "Arch : ${SKYBLUE}$arch ($lbit Bit)${PLAIN}" +echo -e "Kernel : ${SKYBLUE}$kern${PLAIN}" +echo -ne "Virt : " + +# install virt-what +if [ ! -e '/usr/sbin/virt-what' ]; then + if [ "${release}" == "centos" ]; then + yum update > /dev/null 2>&1 + yum -y install virt-what > /dev/null 2>&1 + else + apt-get update > /dev/null 2>&1 + apt-get -y install virt-what > /dev/null 2>&1 + fi +fi +virtua=$(virt-what) 2>/dev/null + +if [[ ${virtua} ]]; then + echo -e "${SKYBLUE}$virtua${PLAIN}" +else + echo -e "${SKYBLUE}No Virt${PLAIN}" + echo -ne "Power time of disk : " + install_smart + echo -e "${SKYBLUE}$ptime Hours${PLAIN}" +fi +next +echo -n "I/O speed( 32M ) : " +io1=$( io_test 32k 1k ) +echo -e "${YELLOW}$io1${PLAIN}" +echo -n "I/O speed( 256M ) : " +io2=$( io_test 64k 4k ) +echo -e "${YELLOW}$io2${PLAIN}" +echo -n "I/O speed( 2G ) : " +io3=$( io_test 64k 32k ) +echo -e "${YELLOW}$io3${PLAIN}" +ioraw1=$( echo $io1 | awk 'NR==1 {print $1}' ) +[ "`echo $io1 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw1=$( awk 'BEGIN{print '$ioraw1' * 1024}' ) +ioraw2=$( echo $io2 | awk 'NR==1 {print $1}' ) +[ "`echo $io2 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw2=$( awk 'BEGIN{print '$ioraw2' * 1024}' ) +ioraw3=$( echo $io3 | awk 'NR==1 {print $1}' ) +[ "`echo $io3 | awk 'NR==1 {print $2}'`" == "GB/s" ] && ioraw3=$( awk 'BEGIN{print '$ioraw3' * 1024}' ) +ioall=$( awk 'BEGIN{print '$ioraw1' + '$ioraw2' + '$ioraw3'}' ) +ioavg=$( awk 'BEGIN{printf "%.1f", '$ioall' / 3}' ) +echo -e "Average I/O speed : ${YELLOW}$ioavg MB/s${PLAIN}" +next +printf "%-18s%-18s%-20s%-12s\n" "Node Name" "Upload Speed" "Download Speed" "Latency" +speed && next +end=$(date +%s) +time=$(( $end - $start )) +if [[ $time -gt 60 ]]; then + min=$(expr $time / 60) + sec=$(expr $time % 60) + echo -ne "Total time : ${min} min ${sec} sec" +else + echo -ne "Total time : ${time} sec" +fi +echo -ne "\nCurrent time : " +echo $(date +%Y-%m-%d" "%H:%M:%S) +echo "Finished!" +next \ No newline at end of file