diff --git a/1.png b/1.png new file mode 100644 index 0000000..bedbeff Binary files /dev/null and b/1.png differ diff --git a/2.png b/2.png new file mode 100644 index 0000000..67ddb79 Binary files /dev/null and b/2.png differ diff --git a/Generate.py b/Generate.py new file mode 100644 index 0000000..0f819f0 --- /dev/null +++ b/Generate.py @@ -0,0 +1,670 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- + +import urllib +import urllib2 + + +def change_to_list(filename): + content = open(filename,"r").read().strip() + return list(content.split("\n")) + + +def traceroute_to_dict(filename): + + txtfile = open(filename,"r") + content = txtfile.read().strip().split("\n")[1:] + d=dict() + + for i in range(len(content)): + + line = content[i] + if line[1].isdigit(): + if line[4] != "*" : + ip = line.strip().split(" ")[1] + asn = line.strip().split(" ")[3] + iptest = ip.strip().split(" ")[0] + url = "http://ip-api.com/csv/" + iptest + req = urllib2.Request(url) + res_data = urllib2.urlopen(req) + res = res_data.read() + if res.strip().split(",")[0] == "success" : + isp=res.strip().split(",")[11] + asn=res.strip().split(",")[12] + else: + isp= "*" + latency=line.strip().split(" ")[2] + route = line.strip().split(" ")[4] + step = line[0:2] + else: + latency="*" + asn = "*" + route = "*" + ip = "*" + isp= "*" + step = line[0:2] + + d[int(step)]=dict() + d[int(step)]["ip"]=ip + if int(step) < 3: + d[int(step)]["ip"]="*.*.*.*(已隐藏)" + d[int(step)]["latency"]=latency + d[int(step)]["asn"]=asn + d[int(step)]["route"]=route + d[int(step)]["isp"]=isp + + return dict(d) + +def traceroute_to_table(filename): + d = traceroute_to_dict(filename) + string = "" + for i in sorted(d.keys()): + x = d[i] + template = """ + + {} + {} + {} + {} + {} + {} + + """ + string = string + template.format(i,x["ip"],x["route"],x["isp"],x["asn"],x["latency"]) + "\n" + + writefile = open(filename + "_table","w") + writefile.write(string) + writefile.close() + + +def dict_to_table(d,tab): + + table_class = "ui bottom attached tab segment" + if tab == "first": + table_class = table_class + " active" + + table_html = """ + +
+ + + + + + + + + + + """.format(table_class,tab) + + for step in sorted(d.keys()): + table_html = table_html + """ + + + + + + + + + + + """.format(step,d[step]["ip"],d[step]["route"],d[step]["isp"],d[step]["asn"],d[step]["latency"]) + table_html = table_html + """ + +
跳数IP路由ISPAS Number延迟
{0}{1}{2}{3}{4}{5}
+
+ """ + return table_html + +html = """ + + + + + + Zbench v1.0 HTML Output + + + + + + + + + +
+
+ +
+ 您正在使用的是开发中的项目。 +
+

此程序正处于开发版, 我们无法保证在运行过程中不会出错. 我们将在近期测试后放出正式版,敬请期待.

+
+
+ +
+
+
+ 测试数据准确性说明 +
+

请注意,所有的测试数据为测试时的实时数据. 我们不保证您的服务商会在日后一直使用保持完全相同的服务。数据仅供参考.

+

+
+
+ + +

+ + 系统信息 +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
项目数据
+ CPU 型号 + {0}
+ CPU 核心数 + {1}
+ CPU 主频 + {2}
+ 硬盘大小 + {3}
+ 内存大小 + {4}
+ SWAP 交换空间大小 + {5}
+ 在线时长 + {6}
+ 系统负载 + {7}
+ 系统 + {8}
+ 架构 + {9}
+ 核心 + {10}
+ 虚拟化技术 + {11}
+
+ + + + + +

+ + 硬盘 I/O +

+ +
+ + + + + + + + + + + + + + + + + + + + + +
次数速度
+ 第一次测试 + {12}
+ 第二次测试 + {13}
+ 第三次测试 + {14}
+
+ + + + + + + +

+ + 网络测试 +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
节点IP 地址下载速度延迟
CacheFly{15}{16}{17}
Linode 日本{18}{19}{20}
Linode 新加坡{21}{22}{23}
Linode 英国{24}{25}{26}
Linode 法兰克福{27}{28}{29}
Linode 加拿大{30}{31}{32}
Softlayer 达拉斯{33}{34}{35}
Softlayer 西雅图{36}{37}{38}
Softlayer 法兰克福{39}{40}{41}
Softlayer 新加坡{42}{43}{44}
Softlayer 香港{45}{46}{47}
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
节点上传速度下载速度延迟
上海电信{48}{49}{50}
成都电信{51}{52}{53}
西安电信{54}{55}{56}
上海联通{57}{58}{59}
重庆联通{60}{61}{62}
北京电信{63}{64}{65}
北京联通{66}{67}{68}
湖南电信{69}{70}{71}
+
+ + +

+ + 路由追踪 +

+ + +
+ + +""" + + +footer = """ +
+
+ +
+

CopyRight 2016-2018 Function Club. All Right Reserved. Published By 主机博客

+
+ + + + + + +""" + +info = change_to_list("/tmp/info.txt") + +speed = change_to_list("/tmp/speed.txt") + +speed_cn = change_to_list("/tmp/speed_cn.txt") + +shm = traceroute_to_dict("/tmp/shm.txt") +traceroute_to_table("/tmp/shm.txt") +shm_html = dict_to_table(shm,"first") + +sht = traceroute_to_dict("/tmp/sht.txt") +traceroute_to_table("/tmp/sht.txt") +sht_html = dict_to_table(sht,"second") + +shu = traceroute_to_dict("/tmp/shu.txt") +traceroute_to_table("/tmp/shu.txt") +shu_html = dict_to_table(shu,"third") + +gdm = traceroute_to_dict("/tmp/gdm.txt") +traceroute_to_table("/tmp/gdm.txt") +gdm_html = dict_to_table(gdm,"fourth") + +gdt = traceroute_to_dict("/tmp/gdt.txt") +traceroute_to_table("/tmp/gdt.txt") +gdt_html = dict_to_table(gdt,"fifth") + +gdu = traceroute_to_dict("/tmp/gdu.txt") +traceroute_to_table("/tmp/gdu.txt") +gdu_html = dict_to_table(gdu,"sixth") + +own = traceroute_to_dict("/tmp/own.txt") +traceroute_to_table("/tmp/own.txt") +own_html = dict_to_table(own,"seventh") + +html = html.format(info[0],info[1],info[2],info[3],info[4],info[5],info[6],info[7],info[8],info[9],info[10],info[11],info[12],info[13],info[14], \ + +speed[0],speed[1],speed[2],speed[3],speed[4],speed[5],speed[6],speed[7],speed[8],speed[9],speed[10],speed[11],speed[12],speed[13],speed[14],speed[15],\ + +speed[16],speed[17],speed[18],speed[19],speed[20],speed[21],speed[22],speed[23],speed[24],speed[25],speed[26],speed[27],speed[28],speed[29],speed[30],speed[31],speed[32],\ + +speed_cn[0],speed_cn[1],speed_cn[2],speed_cn[3],speed_cn[4],speed_cn[5],speed_cn[6],speed_cn[7],speed_cn[8],speed_cn[9],speed_cn[10],speed_cn[11],speed_cn[12],\ + +speed_cn[13],speed_cn[14],speed_cn[15],speed_cn[16],speed_cn[17],\ + +speed_cn[18],speed_cn[19],speed_cn[20],speed_cn[21],speed_cn[22],speed_cn[23]) + +html = html + shm_html + sht_html + shu_html + gdm_html + gdt_html + gdu_html + own_html + footer + +web = open("/root/report.html","w") + +web.write(html) + +web.close() diff --git a/README.md b/README.md index f0033ba..ba076f0 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,38 @@ -# Some Linux scripts -## Superspeed.sh -- Description: Test your server's network with Speedtest to China -- Intro: https://www.oldking.net/305.html -- Copyright (C) 2017 - 2017 Oldking - -```bash -Usage: - -| No. | Bash Command -|----------|--------------------------------- -| 1 | wget https://raw.githubusercontent.com/oooldking/script/master/superspeed.sh -| 2 | chmod +x superspeed.sh -| 3 | ./superspeed.sh -``` -## Superbench.sh -- Description: Auto test download & I/O speed & network to China script -- Intro: https://www.oldking.net/350.html -- Copyright (C) 2017 - 2017 Oldking - -```bash -Usage: - -| No. | Bash Command | -|----------|---------------------------------| -| 1 | wget -qO- https://raw.githubusercontent.com/oooldking/script/master/superbench.sh | bash | -| 2 | curl -Lso- https://raw.githubusercontent.com/oooldking/script/master/superbench.sh | bash | -``` - +# Zench + +又一个Linux VPS测评脚本 + +## 说明 + +平时测试VPS的时候一直是靠着 **Bench.sh** 来测试的,最近看到 **Oldking**大佬 的 **SuperBench** 也很方便。我自己把这两者的脚本结合在一起,然后加入 **Ping** 以及 **路由测试** 功能。比较懒人,简单快捷。方便VPS测评站的朋友们使用。因为会生成测评报告,可以很方便地分享给其他朋友看自己的测评数据。 + +示例(Demo):[https://www.zhujiboke.com/zbench-example.html](https://www.zhujiboke.com/zbench-example.html) + +## 脚本命令 + +如果中文版出现乱码等情况,请换成英文版。 + +中文版: + + wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/master/ZBench-CN.sh && bash ZBench-CN.sh + +英文版: + + wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/master/ZBench.sh && bash ZBench.sh + +## 效果图 + +![1.png](1.png) + + +![2.png](2.png) + +## 引用 + +* Bench.sh ( [https://teddysun.com/444.html](https://teddysun.com/444.html) ) +* SuperBench ( [https://www.oldking.net/350.html](https://www.oldking.net/350.html) ) +* python实现ping程序 ( [https://www.s0nnet.com/archives/python-icmp](https://www.s0nnet.com/archives/python-icmp) ) +* Python 设置颜色 ( [http://www.pythoner.com/357.html](http://www.pythoner.com/357.html) ) +* Kirito's Blog ( [https://www.ixh.me](https://www.ixh.me) ) + diff --git a/ZBench-CN.sh b/ZBench-CN.sh new file mode 100755 index 0000000..52127b9 --- /dev/null +++ b/ZBench-CN.sh @@ -0,0 +1,425 @@ +# Check if user is root +[ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; } + +# Check if wget installed +if [ ! -e '/usr/bin/wget' ]; then + echo "Error: wget command not found. You must be install wget command at first." + exit 1 +fi +read -p "请输入你的服务器提供商: " Provider + + +# Get IP +OwnerIP=$(who am i | awk '{print $NF}' | sed -e 's/[()]//g') +while :; do echo + read -p "请确认你所在地的IP:${OwnerIP} [y/n]: " ifOwnerIP + if [[ ! ${ifOwnerIP} =~ ^[y,n]$ ]]; then + echo "输入错误! 请确保你输入的是 'y' 或者 'n'" + else + break + fi +done +if [[ ${ifOwnerIP} == "n" ]]; then + while :; do echo + read -p "请输入你所在地的IP: " OwnerIP + if [[ ! ${OwnerIP} ]]; then + echo "输入错误!IP地址不能为空!" + else + break + fi + done +fi + + +# 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 + + +# Colors +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +SKYBLUE='\033[0;36m' +PLAIN='\033[0m' + +rm -rf /tmp/report && mkdir /tmp/report + +echo "正在安装必要的依赖,请耐心等待..." + + + +# Install Virt-what +if [ ! -e '/usr/sbin/virt-what' ]; then + echo "Installing Virt-What......" + if [ "${release}" == "centos" ]; then + yum -y install virt-what > /dev/null 2>&1 + else + apt-get update + apt-get -y install virt-what > /dev/null 2>&1 + fi +fi + +# Install uuid +echo "Installing uuid......" +if [ "${release}" == "centos" ]; then + yum -y install uuid > /dev/null 2>&1 +else + apt-get -y install uuid > /dev/null 2>&1 +fi + + +# Install curl +echo "Installing curl......" +if [ "${release}" == "centos" ]; then + yum -y install curl > /dev/null 2>&1 +else + apt-get -y install curl > /dev/null 2>&1 +fi + + +# Install Besttrace +if [ ! -e '/tmp/besttrace' ]; then + echo "Installing Besttrace......" + dir=$(pwd) + cd /tmp/ + wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/master/besttrace > /dev/null 2>&1 + cd $dir +fi +chmod a+rx /tmp/besttrace + +# Check Python +if [ ! -e '/usr/bin/python' ]; then + echo "Installing Python......" + 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 +fi + +# Install Speedtest +if [ ! -e '/tmp/speedtest.py' ]; then + echo "Installing SpeedTest......" + dir=$(pwd) + cd /tmp/ + wget -N --no-check-certificate https://raw.github.com/sivel/speedtest-cli/master/speedtest.py > /dev/null 2>&1 + cd $dir +fi +chmod a+rx /tmp/speedtest.py + + +# Install Zping-CN +if [ ! -e '/tmp/ZPing-CN.py' ]; then + echo "Installing ZPing-CN.py......" + dir=$(pwd) + cd /tmp/ + wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/master/ZPing-CN.py > /dev/null 2>&1 + cd $dir +fi +chmod a+rx /tmp/ZPing-CN.py + +#"TraceRoute to Shanghai Telecom" +/tmp/besttrace 61.129.42.6 > /tmp/sht.txt 2>&1 & +#"TraceRoute to Shanghai Mobile" +/tmp/besttrace speedtest2.sh.chinamobile.com > /tmp/shm.txt 2>&1 & +#"TraceRoute to Shanghai Unicom" +/tmp/besttrace 210.22.80.1 > /tmp/shu.txt 2>&1 & +#"TraceRoute to Guangdong Telecom" +/tmp/besttrace 121.14.220.240 > /tmp/gdt.txt 2>&1 & +#"TraceRoute to Guangdong Mobile" +/tmp/besttrace 211.136.192.6 > /tmp/gdm.txt 2>&1 & +#"TraceRoute to Guangdong Unicom" +/tmp/besttrace 221.5.88.88 > /tmp/gdu.txt 2>&1 & +#"TraceRoute to Owner's Network" +/tmp/besttrace ${OwnerIP} > /tmp/own.txt 2>&1 & + + + + +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 "%-74s\n" "-" | sed 's/\s/-/g' +} + +speed_test() { + local speedtest=$(wget -4O /dev/null -T300 $1 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}') + local ipaddress=$(ping -c1 -n `awk -F'/' '{print $3}' <<< $1` | awk -F'[()]' '{print $2;exit}') + local nodeName=$2 + local latency=$(ping $ipaddress -c 3 | grep avg | awk -F / '{print $5}')" ms" + printf "${YELLOW}%-26s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" "${nodeName}" "${ipaddress}" "${speedtest}" "${latency}" + + #Record Speed Data + echo ${ipaddress} >> /tmp/speed.txt + echo ${speedtest} >> /tmp/speed.txt + echo ${latency} >> /tmp/speed.txt +} + +speed() { + speed_test 'http://cachefly.cachefly.net/100mb.test' 'CacheFly' + speed_test 'http://speedtest.tokyo.linode.com/100MB-tokyo.bin' 'Linode, Tokyo, JP' + speed_test 'http://speedtest.singapore.linode.com/100MB-singapore.bin' 'Linode, Singapore, SG' + speed_test 'http://speedtest.london.linode.com/100MB-london.bin' 'Linode, London, UK' + speed_test 'http://speedtest.frankfurt.linode.com/100MB-frankfurt.bin' 'Linode, Frankfurt, DE' + speed_test 'http://speedtest.fremont.linode.com/100MB-fremont.bin' 'Linode, Fremont, CA' + speed_test 'http://speedtest.dal05.softlayer.com/downloads/test100.zip' 'Softlayer, Dallas, TX' + speed_test 'http://speedtest.sea01.softlayer.com/downloads/test100.zip' 'Softlayer, Seattle, WA' + speed_test 'http://speedtest.fra02.softlayer.com/downloads/test100.zip' 'Softlayer, Frankfurt, DE' + speed_test 'http://speedtest.sng01.softlayer.com/downloads/test100.zip' 'Softlayer, Singapore, SG' + speed_test 'http://speedtest.hkg02.softlayer.com/downloads/test100.zip' 'Softlayer, HongKong, CN' +} + +speed_test_cn(){ + 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}%-29s${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}%-29s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" "${nodeName}" "${reupload}" "${REDownload}" "${relatency}" + else + local cerror="ERROR" + fi + fi + + #Record Speed_cn Data + echo ${reupload} >> /tmp/speed_cn.txt + echo ${REDownload} >> /tmp/speed_cn.txt + echo ${relatency} >> /tmp/speed_cn.txt +} + +speed_cn() { + + speed_test_cn '12637' '襄阳电信' + speed_test_cn '3633' '上海电信' + speed_test_cn '4624' '成都电信' + speed_test_cn '4863' "西安电信" + speed_test_cn '5083' '上海联通' + speed_test_cn '5726' '重庆联通' + speed_test_cn '4751' "北京电信" + speed_test_cn '5145' '北京联通' + speed_test_cn '6132' '湖南电信' + + rm -rf /tmp/speedtest.py +} + + +io_test() { + (LANG=C dd if=/dev/zero of=test_$$ bs=64k count=16k 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} +} + +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[@]} ) + + +clear +next +echo -e "CPU 型号 : ${SKYBLUE}$cname${PLAIN}" +echo -e "CPU 核心数 : ${SKYBLUE}$cores${PLAIN}" +echo -e "CPU 频率 : ${SKYBLUE}$freq MHz${PLAIN}" +echo -e "总硬盘大小 : ${SKYBLUE}$disk_total_size GB ($disk_used_size GB Used)${PLAIN}" +echo -e "总内存大小 : ${SKYBLUE}$tram MB ($uram MB Used)${PLAIN}" +echo -e "SWAP大小 : ${SKYBLUE}$swap MB ($uswap MB Used)${PLAIN}" +echo -e "开机时长 : ${SKYBLUE}$up${PLAIN}" +echo -e "系统负载 : ${SKYBLUE}$load${PLAIN}" +echo -e "系统 : ${SKYBLUE}$opsy${PLAIN}" +echo -e "架构 : ${SKYBLUE}$arch ($lbit Bit)${PLAIN}" +echo -e "内核 : ${SKYBLUE}$kern${PLAIN}" +echo -ne "虚拟化平台 : " +virtua=$(virt-what) 2>/dev/null + +if [[ ${virtua} ]]; then + echo -e "${SKYBLUE}$virtua${PLAIN}" +else + echo -e "${SKYBLUE}No Virt${PLAIN}" +fi + + +next +io1=$( io_test ) +echo -e "硬盘I/O (第一次测试) : ${YELLOW}$io1${PLAIN}" +io2=$( io_test ) +echo -e "硬盘I/O (第二次测试) : ${YELLOW}$io2${PLAIN}" +io3=$( io_test ) +echo -e "硬盘I/O (第三次测试) : ${YELLOW}$io3${PLAIN}" +next + +##Record All Test data +rm -rf /tmp/info.txt +touch /tmp/info.txt +echo $cname >> /tmp/info.txt +echo $cores >> /tmp/info.txt +echo $freq MHz >> /tmp/info.txt +echo "$disk_total_size GB ($disk_used_size GB 已使用) ">> /tmp/info.txt +echo "$tram MB ($uram MB 已使用) ">> /tmp/info.txt +echo "$swap MB ($uswap MB 已使用)" >> /tmp/info.txt +echo $up >> /tmp/info.txt +echo $load >> /tmp/info.txt +echo $opsy >> /tmp/info.txt +echo "$arch ($lbit 位) ">> /tmp/info.txt +echo $kern >> /tmp/info.txt +echo $virtua >> /tmp/info.txt +echo $io1 >> /tmp/info.txt +echo $io2 >> /tmp/info.txt +echo $io3 >> /tmp/info.txt +AKEY=$( uuid ) + +printf "%-30s%-20s%-24s%-12s\n" "节点名称" "IP地址" "下载速度" "延迟" +speed && next +printf "%-30s%-22s%-24s%-12s\n" "节点名称" "上传速度" "下载速度" "延迟" +speed_cn && next +python /tmp/ZPing-CN.py +next + +NetCFspeec=$( sed -n "2p" /tmp/speed.txt ) +NetCFping=$( sed -n "3p" /tmp/speed.txt ) +NetLJPspeed=$( sed -n "5p" /tmp/speed.txt ) +NetLJPping=$( sed -n "6p" /tmp/speed.txt ) +NetLSGspeed=$( sed -n "8p" /tmp/speed.txt ) +NetLSGping=$( sed -n "9p" /tmp/speed.txt ) +NetLUKspeed=$( sed -n "11p" /tmp/speed.txt ) +NetLUKping=$( sed -n "12p" /tmp/speed.txt ) +NetLDEspeed=$( sed -n "14p" /tmp/speed.txt ) +NetLDEping=$( sed -n "15p" /tmp/speed.txt ) +NetLCAspeed=$( sed -n "17p" /tmp/speed.txt ) +NetLCAping=$( sed -n "18p" /tmp/speed.txt ) +NetSTXspeed=$( sed -n "20p" /tmp/speed.txt ) +NetSTXping=$( sed -n "21p" /tmp/speed.txt ) +NetSWAspeed=$( sed -n "23p" /tmp/speed.txt ) +NetSWAping=$( sed -n "24p" /tmp/speed.txt ) +NetSDEspeed=$( sed -n "26p" /tmp/speed.txt ) +NetSDEping=$( sed -n "27p" /tmp/speed.txt ) +NetSSGspeed=$( sed -n "29p" /tmp/speed.txt ) +NetSSGping=$( sed -n "30p" /tmp/speed.txt ) +NetSCNspeed=$( sed -n "32p" /tmp/speed.txt ) +NetSCNping=$( sed -n "33p" /tmp/speed.txt ) + + +NetUPST=$( sed -n "4p" /tmp/speed_cn.txt ) +NetDWST=$( sed -n "5p" /tmp/speed_cn.txt ) +NetPiST=$( sed -n "6p" /tmp/speed_cn.txt ) +NetUPCT=$( sed -n "7p" /tmp/speed_cn.txt ) +NetDWCT=$( sed -n "8p" /tmp/speed_cn.txt ) +NetPiCT=$( sed -n "9p" /tmp/speed_cn.txt ) +NetUPXT=$( sed -n "10p" /tmp/speed_cn.txt ) +NetDWXT=$( sed -n "11p" /tmp/speed_cn.txt ) +NetPiXT=$( sed -n "12p" /tmp/speed_cn.txt ) +NetUPSU=$( sed -n "13p" /tmp/speed_cn.txt ) +NetDWSU=$( sed -n "14p" /tmp/speed_cn.txt ) +NetPiSU=$( sed -n "15p" /tmp/speed_cn.txt ) +NetUPCU=$( sed -n "16p" /tmp/speed_cn.txt ) +NetDWCU=$( sed -n "17p" /tmp/speed_cn.txt ) +NetPiCU=$( sed -n "18p" /tmp/speed_cn.txt ) +NetUPXM=$( sed -n "19p" /tmp/speed_cn.txt ) +NetDWXM=$( sed -n "20p" /tmp/speed_cn.txt ) +NetPiXM=$( sed -n "21p" /tmp/speed_cn.txt ) +NetUPSM=$( sed -n "22p" /tmp/speed_cn.txt ) +NetDWSM=$( sed -n "23p" /tmp/speed_cn.txt ) +NetPiSM=$( sed -n "24p" /tmp/speed_cn.txt ) +NetUPCM=$( sed -n "25p" /tmp/speed_cn.txt ) +NetDWCM=$( sed -n "26p" /tmp/speed_cn.txt ) +NetPiCM=$( sed -n "27p" /tmp/speed_cn.txt ) + + +wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/master/Generate.py >> /dev/null 2>&1 +python Generate.py && rm -rf Generate.py && cp /root/report.html /tmp/report/index.html +TSM=$( cat /tmp/shm.txt_table ) +TST=$( cat /tmp/sht.txt_table ) +TSU=$( cat /tmp/shu.txt_table ) +TGM=$( cat /tmp/gdm.txt_table ) +TGT=$( cat /tmp/gdt.txt_table ) +TGU=$( cat /tmp/gdu.txt_table ) +curl 'http://api.zbench.kirito.moe/action.php' --data "CPUmodel=$cname &CPUspeed=$freq MHz &CPUcore=$cores &HDDsize=$disk_total_size GB ($disk_used_size GB 已使用) &RAMsize=$tram MB ($uram MB 已使用)&SWAPsize=$swap MB ($uswap MB 已使用)&UPtime= $up&Arch=1&systemload=$load&OS= $opsy &Arch=$arch ($lbit 位)&Kernel=$kern &Virmethod=$virtua &IOa=$io1&IOb=$io2&IOc=$io3&NetCFspeec=$NetCFspeec&NetCFping=$NetCFping&NetLJPspeed=$NetLJPspeed&NetLJPping=$NetLJPping&NetLSGspeed=$NetLSGspeed&NetLSGping=$NetLSGping&NetLUKspeed=$NetLUKspeed&NetLUKping=$NetLUKping&NetLDEspeed=$NetLDEspeed&NetLDEping=$NetLDEping&NetLCAspeed=$NetLCAspeed&NetLCAping=$NetLCAping&NetSTXspeed=$NetSTXspeed&NetSTXping=$NetSTXping&NetSWAspeed=$NetSWAspeed&NetSWAping=$NetSWAping&NetSDEspeed=$NetSDEspeed&NetSDEping=$NetSDEping&NetSSGspeed=$NetSSGspeed&NetSSGping=$NetSSGping&NetSCNspeed=$NetSCNspeed&NetSCNping=$NetSCNping&NetUPST=$NetUPST&NetDWST=$NetDWST&NetPiST=$NetPiST&NetUPCT=$NetUPCT&NetDWCT=$NetDWCT&NetPiCT=$NetPiCT&NetUPXT=$NetUPXT&NetDWXT=$NetDWXT&NetPiXT=$NetPiXT&NetUPSU=$NetUPSU&NetDWSU=$NetDWSU&NetPiSU=$NetPiSU&NetUPCU=$NetUPCU&NetDWCU=$NetDWCU&NetPiCU=$NetPiCU&NetUPXM=$NetUPXM&NetDWXM=$NetDWXM&NetPiXM=$NetPiXM&NetUPSM=$NetUPSM&NetDWSM=$NetDWSM&NetPiSM=$NetPiSM&NetUPCM=$NetUPCM&NetDWCM=$NetDWCM&NetPiCM=$NetPiCM&TSM=$TSM&TST=$TST&TSU=$TSU&TGM=$TGM&TGT=$TGT&TGU=$TGU&AKEY=$AKEY&Provider=$Provider" +IKEY=$(curl "http://api.zbench.kirito.moe/getkey.php?AKEY=$AKEY" 2>/dev/null) +echo "在线查看测评报告:https://zbench.kirito.moe/record-cn.php?IKEY=$IKEY" +echo "您的测评报告已保存在 /root/report.html" + +# If use simple http server +while :; do echo + read -p "你想现在查看您的测评报告吗? [y/n]: " ifreport + if [[ ! $ifreport =~ ^[y,n]$ ]]; then + echo "输入错误! 请确保你输入的是 'y' 或者 'n'" + else + break + fi +done + +if [[ $ifreport == 'y' ]];then + echo "" + myip=`curl -m 10 -s http://members.3322.org/dyndns/getip` + echo "访问 http://${myip}:8001/index.html 查看您的测试报告,按 Ctrl + C 退出" + cd /tmp/report + python -m SimpleHTTPServer 8001 + iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 8001 -j ACCEPT +fi diff --git a/ZBench.sh b/ZBench.sh new file mode 100755 index 0000000..5287978 --- /dev/null +++ b/ZBench.sh @@ -0,0 +1,433 @@ +# Check if user is root +[ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; } + +# Check if wget installed +if [ ! -e '/usr/bin/wget' ]; then + echo "Error: wget command not found. You must be install wget command at first." + exit 1 +fi +read -p "Please Enter Your Host Provider: " Provider + + +# Get IP +OwnerIP=$(who am i | awk '{print $NF}' | sed -e 's/[()]//g') +while :; do echo + read -p "Please Confirm Your Client IP:${OwnerIP} [y/n]: " ifOwnerIP + if [[ ! ${ifOwnerIP} =~ ^[y,n]$ ]]; then + echo "Input error! Please only input 'y' or 'n'" + else + break + fi +done +if [[ ${ifOwnerIP} == "n" ]]; then + while :; do echo + read -p "Please Enter Your Client IP: " OwnerIP + if [[ ! ${OwnerIP} ]]; then + echo "Input error! Cannot be void!" + else + break + fi + done +fi + + +# 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 + + +# Colors +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +SKYBLUE='\033[0;36m' +PLAIN='\033[0m' + +rm -rf /tmp/report && mkdir /tmp/report + +echo "Installing required packages, please wait..." + +# Install Virt-what +if [ ! -e '/usr/sbin/virt-what' ]; then + echo "Installing Virt-What......" + if [ "${release}" == "centos" ]; then + 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 uuid +echo "Installing uuid......" +if [ "${release}" == "centos" ]; then + yum -y install uuid > /dev/null 2>&1 +else + apt-get -y install uuid > /dev/null 2>&1 +fi + + +# Install curl +echo "Installing curl......" +if [ "${release}" == "centos" ]; then + yum -y install curl > /dev/null 2>&1 +else + apt-get -y install curl > /dev/null 2>&1 +fi + + +# Install Besttrace +if [ ! -e '/tmp/besttrace' ]; then + echo "Installing Besttrace......" + dir=$(pwd) + cd /tmp/ + wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/master/besttrace > /dev/null 2>&1 + cd $dir +fi +chmod a+rx /tmp/besttrace + +# Check Python +if [ ! -e '/usr/bin/python' ]; then + echo "Installing Python......" + 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 +fi + +# Install Speedtest +if [ ! -e '/tmp/speedtest.py' ]; then + echo "Installing SpeedTest......" + dir=$(pwd) + cd /tmp/ + wget -N --no-check-certificate https://raw.github.com/sivel/speedtest-cli/master/speedtest.py > /dev/null 2>&1 + cd $dir +fi +chmod a+rx /tmp/speedtest.py + + +# Install Zping +if [ ! -e '/tmp/ZPing.py' ]; then + echo "Installing ZPing.py......" + dir=$(pwd) + cd /tmp/ + wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/master/ZPing.py > /dev/null 2>&1 + cd $dir +fi +chmod a+rx /tmp/ZPing.py + +#"TraceRoute to Shanghai Telecom" +/tmp/besttrace 61.129.42.6 > /tmp/sht.txt 2>&1 & +#"TraceRoute to Shanghai Mobile" +/tmp/besttrace speedtest2.sh.chinamobile.com > /tmp/shm.txt 2>&1 & +#"TraceRoute to Shanghai Unicom" +/tmp/besttrace 210.22.80.1 > /tmp/shu.txt 2>&1 & +#"TraceRoute to Guangdong Telecom" +/tmp/besttrace 121.14.220.240 > /tmp/gdt.txt 2>&1 & +#"TraceRoute to Guangdong Mobile" +/tmp/besttrace 211.136.192.6 > /tmp/gdm.txt 2>&1 & +#"TraceRoute to Guangdong Unicom" +/tmp/besttrace 221.5.88.88 > /tmp/gdu.txt 2>&1 & +#"TraceRoute to Owner's Network" +/tmp/besttrace ${OwnerIP} > /tmp/own.txt 2>&1 & + + + + +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 "%-74s\n" "-" | sed 's/\s/-/g' +} + +speed_test() { + local speedtest=$(wget -4O /dev/null -T300 $1 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}') + local ipaddress=$(ping -c1 -n `awk -F'/' '{print $3}' <<< $1` | awk -F'[()]' '{print $2;exit}') + local nodeName=$2 + local latency=$(ping $ipaddress -c 3 | grep avg | awk -F / '{print $5}')" ms" + printf "${YELLOW}%-26s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" "${nodeName}" "${ipaddress}" "${speedtest}" "${latency}" + + #Record Speed Data + echo ${ipaddress} >> /tmp/speed.txt + echo ${speedtest} >> /tmp/speed.txt + echo ${latency} >> /tmp/speed.txt +} + +speed() { + rm -rf /tmp/speed.txt && touch /tmp/speed.txt + speed_test 'http://cachefly.cachefly.net/100mb.test' 'CacheFly' + speed_test 'http://speedtest.tokyo.linode.com/100MB-tokyo.bin' 'Linode, Tokyo, JP' + speed_test 'http://speedtest.singapore.linode.com/100MB-singapore.bin' 'Linode, Singapore, SG' + speed_test 'http://speedtest.london.linode.com/100MB-london.bin' 'Linode, London, UK' + speed_test 'http://speedtest.frankfurt.linode.com/100MB-frankfurt.bin' 'Linode, Frankfurt, DE' + speed_test 'http://speedtest.fremont.linode.com/100MB-fremont.bin' 'Linode, Fremont, CA' + speed_test 'http://speedtest.dal05.softlayer.com/downloads/test100.zip' 'Softlayer, Dallas, TX' + speed_test 'http://speedtest.sea01.softlayer.com/downloads/test100.zip' 'Softlayer, Seattle, WA' + speed_test 'http://speedtest.fra02.softlayer.com/downloads/test100.zip' 'Softlayer, Frankfurt, DE' + speed_test 'http://speedtest.sng01.softlayer.com/downloads/test100.zip' 'Softlayer, Singapore, SG' + speed_test 'http://speedtest.hkg02.softlayer.com/downloads/test100.zip' 'Softlayer, HongKong, CN' +} + +speed_test_cn(){ + 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}%-25s${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}%-25s${GREEN}%-18s${RED}%-20s${SKYBLUE}%-12s${PLAIN}\n" "${nodeName}" "${reupload}" "${REDownload}" "${relatency}" + else + local cerror="ERROR" + fi + fi + + #Record Speed_cn Data + echo ${reupload} >> /tmp/speed_cn.txt + echo ${REDownload} >> /tmp/speed_cn.txt + echo ${relatency} >> /tmp/speed_cn.txt + + +} + +speed_cn() { + rm -rf /tmp/speed_cn.txt && touch /tmp/speed_cn.txt + + speed_test_cn '12637' 'Xiangyang CT' + speed_test_cn '3633' 'Shanghai CT' + speed_test_cn '4624' 'Chengdu CT' + speed_test_cn '4863' "Xi'an CU" + speed_test_cn '5083' 'Shanghai CU' + speed_test_cn '5726' 'Chongqing CU' + speed_test_cn '5192' "Beijing CT" + speed_test_cn '4665' 'Beijing CT' + speed_test_cn '4575' 'Hunan CT' + + rm -rf /tmp/speedtest.py +} + + +io_test() { + (LANG=C dd if=/dev/zero of=test_$$ bs=64k count=16k 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} +} + +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[@]} ) + + +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 : " +virtua=$(virt-what) 2>/dev/null + +if [[ ${virtua} ]]; then + echo -e "${SKYBLUE}$virtua${PLAIN}" +else + virtua="No Virt" + echo -e "${SKYBLUE}No Virt${PLAIN}" +fi + +next +io1=$( io_test ) +echo -e "I/O speed(1st run) :${YELLOW}$io1${PLAIN}" +io2=$( io_test ) +echo -e "I/O speed(2nd run) :${YELLOW}$io2${PLAIN}" +io3=$( io_test ) +echo -e "I/O speed(3rd run) :${YELLOW}$io3${PLAIN}" +next + + +##Record All Test data +rm -rf /tmp/info.txt +touch /tmp/info.txt +echo $cname >> /tmp/info.txt +echo $cores >> /tmp/info.txt +echo $freq MHz >> /tmp/info.txt +echo "$disk_total_size GB ($disk_used_size GB 已使用) ">> /tmp/info.txt +echo "$tram MB ($uram MB 已使用) ">> /tmp/info.txt +echo "$swap MB ($uswap MB 已使用)" >> /tmp/info.txt +echo $up >> /tmp/info.txt +echo $load >> /tmp/info.txt +echo $opsy >> /tmp/info.txt +echo "$arch ($lbit 位) ">> /tmp/info.txt +echo $kern >> /tmp/info.txt +echo $virtua >> /tmp/info.txt +echo $io1 >> /tmp/info.txt +echo $io2 >> /tmp/info.txt +echo $io3 >> /tmp/info.txt +AKEY=$( uuid ) + +printf "%-26s%-18s%-20s%-12s\n" "Node Name" "IP Address" "Download Speed" "Latency" +speed && next +printf "%-26s%-18s%-20s%-12s\n" "Node Name" "Upload Speed" "Download Speed" "Latency" +speed_cn && next +python /tmp/ZPing.py +next + + + +NetCFspeec=$( sed -n "2p" /tmp/speed.txt ) +NetCFping=$( sed -n "3p" /tmp/speed.txt ) +NetLJPspeed=$( sed -n "5p" /tmp/speed.txt ) +NetLJPping=$( sed -n "6p" /tmp/speed.txt ) +NetLSGspeed=$( sed -n "8p" /tmp/speed.txt ) +NetLSGping=$( sed -n "9p" /tmp/speed.txt ) +NetLUKspeed=$( sed -n "11p" /tmp/speed.txt ) +NetLUKping=$( sed -n "12p" /tmp/speed.txt ) +NetLDEspeed=$( sed -n "14p" /tmp/speed.txt ) +NetLDEping=$( sed -n "15p" /tmp/speed.txt ) +NetLCAspeed=$( sed -n "17p" /tmp/speed.txt ) +NetLCAping=$( sed -n "18p" /tmp/speed.txt ) +NetSTXspeed=$( sed -n "20p" /tmp/speed.txt ) +NetSTXping=$( sed -n "21p" /tmp/speed.txt ) +NetSWAspeed=$( sed -n "23p" /tmp/speed.txt ) +NetSWAping=$( sed -n "24p" /tmp/speed.txt ) +NetSDEspeed=$( sed -n "26p" /tmp/speed.txt ) +NetSDEping=$( sed -n "27p" /tmp/speed.txt ) +NetSSGspeed=$( sed -n "29p" /tmp/speed.txt ) +NetSSGping=$( sed -n "30p" /tmp/speed.txt ) +NetSCNspeed=$( sed -n "32p" /tmp/speed.txt ) +NetSCNping=$( sed -n "33p" /tmp/speed.txt ) + + +NetUPST=$( sed -n "4p" /tmp/speed_cn.txt ) +NetDWST=$( sed -n "5p" /tmp/speed_cn.txt ) +NetPiST=$( sed -n "6p" /tmp/speed_cn.txt ) +NetUPCT=$( sed -n "7p" /tmp/speed_cn.txt ) +NetDWCT=$( sed -n "8p" /tmp/speed_cn.txt ) +NetPiCT=$( sed -n "9p" /tmp/speed_cn.txt ) +NetUPXT=$( sed -n "10p" /tmp/speed_cn.txt ) +NetDWXT=$( sed -n "11p" /tmp/speed_cn.txt ) +NetPiXT=$( sed -n "12p" /tmp/speed_cn.txt ) +NetUPSU=$( sed -n "13p" /tmp/speed_cn.txt ) +NetDWSU=$( sed -n "14p" /tmp/speed_cn.txt ) +NetPiSU=$( sed -n "15p" /tmp/speed_cn.txt ) +NetUPCU=$( sed -n "16p" /tmp/speed_cn.txt ) +NetDWCU=$( sed -n "17p" /tmp/speed_cn.txt ) +NetPiCU=$( sed -n "18p" /tmp/speed_cn.txt ) +NetUPXM=$( sed -n "19p" /tmp/speed_cn.txt ) +NetDWXM=$( sed -n "20p" /tmp/speed_cn.txt ) +NetPiXM=$( sed -n "21p" /tmp/speed_cn.txt ) +NetUPSM=$( sed -n "22p" /tmp/speed_cn.txt ) +NetDWSM=$( sed -n "23p" /tmp/speed_cn.txt ) +NetPiSM=$( sed -n "24p" /tmp/speed_cn.txt ) +NetUPCM=$( sed -n "25p" /tmp/speed_cn.txt ) +NetDWCM=$( sed -n "26p" /tmp/speed_cn.txt ) +NetPiCM=$( sed -n "27p" /tmp/speed_cn.txt ) + + +wget -N --no-check-certificate https://raw.githubusercontent.com/FunctionClub/ZBench/master/Generate.py >> /dev/null 2>&1 +python Generate.py && rm -rf Generate.py && cp /root/report.html /tmp/report/index.html +TSM=$( cat /tmp/shm.txt_table ) +TST=$( cat /tmp/sht.txt_table ) +TSU=$( cat /tmp/shu.txt_table ) +TGM=$( cat /tmp/gdm.txt_table ) +TGT=$( cat /tmp/gdt.txt_table ) +TGU=$( cat /tmp/gdu.txt_table ) +curl 'http://api.zbench.kirito.moe/action.php' --data "CPUmodel=$cname &CPUspeed=$freq MHz &CPUcore=$cores &HDDsize=$disk_total_size GB ($disk_used_size GB 已使用) &RAMsize=$tram MB ($uram MB 已使用)&SWAPsize=$swap MB ($uswap MB 已使用)&UPtime= $up&Arch=1&systemload=$load&OS= $opsy &Arch=$arch ($lbit 位)&Kernel=$kern &Virmethod=$virtua &IOa=$io1&IOb=$io2&IOc=$io3&NetCFspeec=$NetCFspeec&NetCFping=$NetCFping&NetLJPspeed=$NetLJPspeed&NetLJPping=$NetLJPping&NetLSGspeed=$NetLSGspeed&NetLSGping=$NetLSGping&NetLUKspeed=$NetLUKspeed&NetLUKping=$NetLUKping&NetLDEspeed=$NetLDEspeed&NetLDEping=$NetLDEping&NetLCAspeed=$NetLCAspeed&NetLCAping=$NetLCAping&NetSTXspeed=$NetSTXspeed&NetSTXping=$NetSTXping&NetSWAspeed=$NetSWAspeed&NetSWAping=$NetSWAping&NetSDEspeed=$NetSDEspeed&NetSDEping=$NetSDEping&NetSSGspeed=$NetSSGspeed&NetSSGping=$NetSSGping&NetSCNspeed=$NetSCNspeed&NetSCNping=$NetSCNping&NetUPST=$NetUPST&NetDWST=$NetDWST&NetPiST=$NetPiST&NetUPCT=$NetUPCT&NetDWCT=$NetDWCT&NetPiCT=$NetPiCT&NetUPXT=$NetUPXT&NetDWXT=$NetDWXT&NetPiXT=$NetPiXT&NetUPSU=$NetUPSU&NetDWSU=$NetDWSU&NetPiSU=$NetPiSU&NetUPCU=$NetUPCU&NetDWCU=$NetDWCU&NetPiCU=$NetPiCU&NetUPXM=$NetUPXM&NetDWXM=$NetDWXM&NetPiXM=$NetPiXM&NetUPSM=$NetUPSM&NetDWSM=$NetDWSM&NetPiSM=$NetPiSM&NetUPCM=$NetUPCM&NetDWCM=$NetDWCM&NetPiCM=$NetPiCM&TSM=$TSM&TST=$TST&TSU=$TSU&TGM=$TGM&TGT=$TGT&TGU=$TGU&AKEY=$AKEY&Provider=$Provider" + +IKEY=$(curl "http://api.zbench.kirito.moe/getkey.php?AKEY=$AKEY" 2>/dev/null) +echo "Result Address:https://zbench.kirito.moe/record.php?IKEY=$IKEY" +echo "Your bench data is saved to /root/report.html" + +# If use simple http server +while :; do echo + read -p "Do you want to check your Test Report? [y/n]: " ifreport + if [[ ! $ifreport =~ ^[y,n]$ ]]; then + echo "Input error! Please only input 'y' or 'n'" + else + break + fi +done + +if [[ $ifreport == 'y' ]];then + echo "" + myip=`curl -m 10 -s http://members.3322.org/dyndns/getip` + echo "Visit http://${myip}:8001/index.html to see your report,Press Ctrl + C to exit." + cd /tmp/report + python -m SimpleHTTPServer 8001 + iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 8001 -j ACCEPT +fi diff --git a/ZPing-CN.py b/ZPing-CN.py new file mode 100755 index 0000000..bd0d185 --- /dev/null +++ b/ZPing-CN.py @@ -0,0 +1,123 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- +''' + Author 雨落无声(Github: https://github.com/ylws-4617) + Reference: + 1. https://www.s0nnet.com/archives/python-icmp + 2. http://www.pythoner.com/357.html +''' + +import commands + +def ping(host): + cmd = "ping "+ str(host) + " -c2 -W 2" + result = commands.getoutput(cmd) + result = result.split() + result = result[-2].split("/")[0] + if result.isalpha(): + result = False + return float(result) + + +STYLE = { + 'fore': { + 'black': 30, 'red': 31, 'green': 32, 'yellow': 33, + 'blue': 34, 'purple': 35, 'cyan': 36, 'white': 37, + }, + 'back': { + 'black': 40, 'red': 41, 'green': 42, 'yellow': 43, + 'blue': 44, 'purple': 45, 'cyan': 46, 'white': 47, + }, + 'mode': { + 'bold': 1, 'underline': 4, 'blink': 5, 'invert': 7, + }, + 'default': { + 'end': 0, + } +} + + +def use_style(string, mode='', fore='', back=''): + mode = '%s' % STYLE['mode'][mode] if STYLE['mode'].has_key(mode) else '' + fore = '%s' % STYLE['fore'][fore] if STYLE['fore'].has_key(fore) else '' + back = '%s' % STYLE['back'][back] if STYLE['back'].has_key(back) else '' + style = ';'.join([s for s in [mode, fore, back] if s]) + style = '\033[%sm' % style if style else '' + end = '\033[%sm' % STYLE['default']['end'] if style else '' + return '%s%s%s' % (style, string, end) + +D = { + '郑州': '61.168.23.74', + '济南': '202.102.152.3', + '天津': '219.150.32.132', + '昌吉': '61.128.107.242', + '拉萨': '221.13.70.244', + '长春': '202.98.0.68', + '深圳': '119.147.52.35', + '兰州': 'www.lanzhouunicom.com', + '西宁': '221.207.32.94', + '合肥': '112.122.10.26', + '武汉': '113.57.249.2', + '襄阳': '202.103.44.150', + '南昌': 'speedtest2.wy.jxunicom.com', + '重庆': 'speedtest1.cqccn.com', + '上海': 'speedtest2.sh.chinamobile.com', + '呼和浩特': '222.74.1.200 ', + '乌鲁木齐': '61.128.114.133', + '杭州': '122.229.136.10', + '西安': 'xatest.wo-xa.com', + '宁波': '202.96.104.1', + '太原': 'speedtest.sxunicomjzjk.cn', + '苏州': '218.94.214.42', + '长沙': '61.234.254.5', + '哈尔滨': '202.97.224.1', + '北京': 'st1.bjtelecom.net', + '成都': 'speed.westidc.com.cn', + '沈阳': 'speedtest1.online.ln.cn', + '南京': '4gnanjing1.speedtest.jsinfo.net', + '宁夏': '221.199.9.35', + '福州': 'upload1.testspeed.kaopuyun.com' + } + + + +string =list() +d=dict() + +for x in D: + host=D[x] + result = ping(host) + + + if result == False: + latency_str = use_style(str("Fail"), fore='red') + elif float(result) <= 60: + latency_str =use_style(str(round(result,2)) + " ms",fore='green') + elif float(result) <= 130: + latency_str = use_style(str(round(result,2))+" ms",fore='yellow') + else: + latency_str = use_style(str(round(result,2))+" ms", fore='red') + + d[x] = float(result) + + string.append((x,latency_str)) + if len(string) == 3: + l1 = str(int(len(string[0][0])/3+12)) + l2 = str(int(len(string[1][0])/3+12)) + l3 = str(int(len(string[2][0])/3+12)) + mystring = "{0:"+l1+"}: {1:20}{2:"+l2+"}: {3:20}{4:"+l3+"}: {5:20}" + print(mystring.format(string[0][0],string[0][1],string[1][0],string[1][1],string[2][0],string[2][1])) + string = list() + + +if len(string) == 2: + l1 = str(int(len(string[0][0])/3+12)) + l2 = str(int(len(string[1][0])/3+12)) + mystring = "{0:"+l1+"}: {1:20}{2:"+l2+"}: {3:20}" + print(mystring.format(string[0][0],string[0][1],string[1][0],string[1][1])) + +if len(string) == 1: + l1 = str(int(len(string[0][0])/3+12)) + mystring = "{0:"+l1+"}: {1:20}" + print(mystring.format(string[0][0],string[0][1])) + diff --git a/ZPing.py b/ZPing.py new file mode 100755 index 0000000..2caff95 --- /dev/null +++ b/ZPing.py @@ -0,0 +1,111 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- +''' + Author 雨落无声(Github: https://github.com/ylws-4617) + Reference: + 1. https://www.s0nnet.com/archives/python-icmp + 2. http://www.pythoner.com/357.html +''' + +import commands + +def ping(host): + cmd = "ping "+ str(host) + " -c2 -W 2" + result = commands.getoutput(cmd) + result = result.split() + result = result[-2].split("/")[0] + if result.isalpha(): + result = False + return float(result) + +STYLE = { + 'fore': { + 'black': 30, 'red': 31, 'green': 32, 'yellow': 33, + 'blue': 34, 'purple': 35, 'cyan': 36, 'white': 37, + }, + 'back': { + 'black': 40, 'red': 41, 'green': 42, 'yellow': 43, + 'blue': 44, 'purple': 45, 'cyan': 46, 'white': 47, + }, + 'mode': { + 'bold': 1, 'underline': 4, 'blink': 5, 'invert': 7, + }, + 'default': { + 'end': 0, + } +} + + +def use_style(string, mode='', fore='', back=''): + mode = '%s' % STYLE['mode'][mode] if STYLE['mode'].has_key(mode) else '' + fore = '%s' % STYLE['fore'][fore] if STYLE['fore'].has_key(fore) else '' + back = '%s' % STYLE['back'][back] if STYLE['back'].has_key(back) else '' + style = ';'.join([s for s in [mode, fore, back] if s]) + style = '\033[%sm' % style if style else '' + end = '\033[%sm' % STYLE['default']['end'] if style else '' + return '%s%s%s' % (style, string, end) + +D = { + 'Zhengzhou': '61.168.23.74', + 'Jinan': '202.102.152.3', + 'Tianjin': '219.150.32.132', + 'Changji': '61.128.107.242', + 'Lhasa': '221.13.70.244', + 'Changchun': '202.98.0.68', + 'Shenzhen': '119.147.52.35', + 'Lanzhou': 'www.lanzhouunicom.com', + 'Xining': '221.207.32.94', + 'Hefei': '112.122.10.26', + 'Wuhan': '113.57.249.2', + 'Xiangyang': '202.103.44.150', + 'Nanchang': 'speedtest2.wy.jxunicom.com', + 'Chongqing': 'speedtest1.cqccn.com', + 'Shanghai': 'speedtest2.sh.chinamobile.com', + 'Huhehaote': '222.74.1.200', + 'Urumqi': '61.128.114.133', + 'Hangzhou': '122.229.136.10', + 'Xi an': 'xatest.wo-xa.com', + 'Ningbo': '202.96.104.1', + 'Taiyuan': 'speedtest.sxunicomjzjk.cn', + 'Suzhou': '218.94.214.42', + 'Changsha': '61.234.254.5', + 'Harbin': '202.97.224.1', + 'Beijing': 'st1.bjtelecom.net', + 'Chengdu': 'speed.westidc.com.cn', + 'Shenyang': 'speedtest1.online.ln.cn', + 'Nanjing': '4gnanjing1.speedtest.jsinfo.net', + 'Ningxia': '221.199.9.35', + 'Fuzhou': 'upload1.testspeed.kaopuyun.com' + } + + +string =list() +d=dict() + +for x in D: + host=D[x] + result = ping(host) + + + if result == False: + latency_str = use_style(str("Fail"), fore='red') + elif float(result) <= 60: + latency_str =use_style(str(round(result,2)) + " ms",fore='green') + elif float(result) <= 130: + latency_str = use_style(str(round(result,2))+" ms",fore='yellow') + else: + latency_str = use_style(str(round(result,2))+" ms", fore='red') + + d[x] = float(result) + + string.append((x,latency_str)) + if len(string) == 3: + print("{0:12}: {1:20}{2:12}: {3:20}{4:12}: {5:20}".format(string[0][0],string[0][1],string[1][0],string[1][1],string[2][0],string[2][1])) + string = list() + + +if len(string) == 2: + print("{0:12}: {1:20}{2:12}: {3:20}".format(string[0][0],string[0][1],string[1][0],string[1][1])) + +if len(string) == 1: + print("{0:12}: {1:20}".format(string[0][0],string[0][1])) diff --git a/besttrace b/besttrace new file mode 100755 index 0000000..459c009 Binary files /dev/null and b/besttrace differ diff --git a/superbench.sh b/superbench.sh deleted file mode 100644 index a110d6e..0000000 --- a/superbench.sh +++ /dev/null @@ -1,269 +0,0 @@ -#!/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 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 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 './speedtest.py' ]; then - wget https://raw.github.com/sivel/speedtest-cli/master/speedtest.py > /dev/null 2>&1 - fi - chmod a+rx speedtest.py - - speed_test '' 'Normal Node' - speed_test '12637' 'Xiangyang CT' - speed_test '3633' 'Shanghai CT' - speed_test '4624' 'Chengdu CT' - speed_test '4863' "Xi'an CU" - speed_test '5083' 'Shanghai CU' - speed_test '5726' 'Chongqing CU' - speed_test '5192' "Xi'an CM" - speed_test '4665' 'Shanghai CM' - speed_test '4575' 'Chengdu CM' - - rm -rf 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 diff --git a/superspeed.sh b/superspeed.sh deleted file mode 100644 index fb99b35..0000000 --- a/superspeed.sh +++ /dev/null @@ -1,431 +0,0 @@ -#!/usr/bin/env bash -# -# Description: Test your server's network with Speedtest to China -# -# Copyright (C) 2017 - 2017 Oldking -# -# URL: https://www.oldking.net/305.html -# - -# Colors -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[0;33m' -SKYBLUE='\033[0;36m' -PLAIN='\033[0m' - -# 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 -y install python - else - 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 -y install wget - else - apt-get -y install wget - fi - else - exit - fi -fi - - -clear -echo "#############################################################" -echo "# Description: Test your server's network with Speedtest #" -echo "# Intro: https://www.oldking.net/305.html #" -echo "# Author: Oldking #" -echo "# Github: https://github.com/oooldking #" -echo "#############################################################" -echo -echo "测试服务器到" -echo -ne "1.中国电信 2.中国联通 3.中国移动 4.本地默认 5.全面测速" - -while :; do echo - read -p "请输入数字选择: " telecom - if [[ ! $telecom =~ ^[1-5]$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi -done - -if [[ ${telecom} == 1 ]]; then - telecomName="电信" - echo -e "\n选择最靠近你的方位" - echo -ne "1.北方 2.南方" - while :; do echo - read -p "请输入数字选择: " pos - if [[ ! $pos =~ ^[1-2]$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi - done - echo -e "\n选择最靠近你的城市" - if [[ ${pos} == 1 ]]; then - echo -ne "1.郑州 2.襄阳" - while :; do echo - read -p "请输入数字选择: " city - if [[ ! $city =~ ^[1-2]$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi - done - if [[ ${city} == 1 ]]; then - num=4595 - cityName="郑州" - fi - if [[ ${city} == 2 ]]; then - num=12637 - cityName="襄阳" - fi - fi - if [[ ${pos} == 2 ]]; then - echo -ne "1.上海 2.杭州 3.南宁 4.南昌 5.长沙 6.深圳 7.重庆 8.成都" - while :; do echo - read -p "请输入数字选择: " city - if [[ ! $city =~ ^[1-8]$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi - done - if [[ ${city} == 1 ]]; then - num=3633 - cityName="上海" - fi - if [[ ${city} == 2 ]]; then - num=7509 - cityName="杭州" - fi - if [[ ${city} == 3 ]]; then - num=10305 - cityName="南宁" - fi - if [[ ${city} == 4 ]]; then - num=7230 - cityName="南昌" - fi - if [[ ${city} == 5 ]]; then - num=6132 - cityName="长沙" - fi - if [[ ${city} == 6 ]]; then - num=5081 - cityName="深圳" - fi - if [[ ${city} == 7 ]]; then - num=6592 - cityName="重庆" - fi - if [[ ${city} == 8 ]]; then - num=4624 - cityName="成都" - fi - fi -fi - -if [[ ${telecom} == 2 ]]; then - telecomName="联通" - echo -ne "\n1.北方 2.南方" - while :; do echo - read -p "请输入数字选择: " pos - if [[ ! $pos =~ ^[1-2]$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi - done - echo -e "\n选择最靠近你的城市" - if [[ ${pos} == 1 ]]; then - echo -ne "1.沈阳 2.长春 3.哈尔滨 4.天津 5.济南 6.北京 7.郑州 8.西安 9.太原 10.宁夏 11.兰州 12.西宁" - while :; do echo - read -p "请输入数字选择: " city - if [[ ! $city =~ ^(([1-9])|(1([0-2]{1})))$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi - done - if [[ ${city} == 1 ]]; then - num=5017 - cityName="沈阳" - fi - if [[ ${city} == 2 ]]; then - num=9484 - cityName="长春" - fi - if [[ ${city} == 3 ]]; then - num=5460 - cityName="哈尔滨" - fi - if [[ ${city} == 4 ]]; then - num=5475 - cityName="天津" - fi - if [[ ${city} == 5 ]]; then - num=5039 - cityName="济南" - fi - if [[ ${city} == 6 ]]; then - num=5145 - cityName="北京" - fi - if [[ ${city} == 7 ]]; then - num=5131 - cityName="郑州" - fi - if [[ ${city} == 8 ]]; then - num= 4863 - cityName="西安" - fi - if [[ ${city} == 9 ]]; then - num=12868 - cityName="太原" - fi - if [[ ${city} == 10 ]]; then - num=5509 - cityName="宁夏" - fi - if [[ ${city} == 11 ]]; then - num=4690 - cityName="兰州" - fi - if [[ ${city} == 12 ]]; then - num=5992 - cityName="西宁" - fi - fi - if [[ ${pos} == 2 ]]; then - echo -ne "1.上海 2.杭州 3.南宁 4.合肥 5.南昌 6.长沙 7.深圳 8.广州 9.重庆 10.昆明 11.成都" - while :; do echo - read -p "请输入数字选择: " city - if [[ ! $city =~ ^(([1-9])|(1([0-1]{1})))$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi - done - if [[ ${city} == 1 ]]; then - num=5083 - cityName="上海" - fi - if [[ ${city} == 2 ]]; then - num=5300 - cityName="杭州" - fi - if [[ ${city} == 3 ]]; then - num=5674 - cityName="南宁" - fi - if [[ ${city} == 4 ]]; then - num=5724 - cityName="合肥" - fi - if [[ ${city} == 5 ]]; then - num=5079 - cityName="南昌" - fi - if [[ ${city} == 6 ]]; then - num=4870 - cityName="长沙" - fi - if [[ ${city} == 7 ]]; then - num=10201 - cityName="深圳" - fi - if [[ ${city} == 8 ]]; then - num=3891 - cityName="广州" - fi - if [[ ${city} == 9 ]]; then - num=5726 - cityName="重庆" - fi - if [[ ${city} == 10 ]]; then - num=5103 - cityName="昆明" - fi - if [[ ${city} == 11 ]]; then - num=2461 - cityName="成都" - fi - fi -fi - -if [[ ${telecom} == 3 ]]; then - telecomName="移动" - echo -ne "\n1.北方 2.南方" - while :; do echo - read -p "请输入数字选择: " pos - if [[ ! $pos =~ ^[1-2]$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi - done - echo -e "\n选择最靠近你的城市" - if [[ ${pos} == 1 ]]; then - echo -ne "1.西安" - while :; do echo - read -p "请输入数字选择: " city - if [[ ! $city =~ ^[1]$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi - done - if [[ ${city} == 1 ]]; then - num=5292 - fi - fi - if [[ ${pos} == 2 ]]; then - echo -ne "1.上海 2.宁波 3.无锡 4.杭州 5.合肥 6.成都" - while :; do echo - read -p "请输入数字选择: " city - if [[ ! $city =~ ^[1-6]$ ]]; then - echo "输入错误! 请输入正确的数字!" - else - break - fi - done - if [[ ${city} == 1 ]]; then - num=4665 - cityName="上海" - fi - if [[ ${city} == 2 ]]; then - num=6715 - cityName="宁波" - fi - if [[ ${city} == 3 ]]; then - num=5122 - cityName="无锡" - fi - if [[ ${city} == 4 ]]; then - num=4647 - cityName="杭州" - fi - if [[ ${city} == 5 ]]; then - num=4377 - cityName="合肥" - fi - if [[ ${city} == 6 ]]; then - num=4575 - cityName="成都" - fi - fi -fi - -# install speedtest -if [ ! -e './speedtest.py' ]; then - wget https://raw.github.com/sivel/speedtest-cli/master/speedtest.py > /dev/null 2>&1 -fi -chmod a+rx speedtest.py - -result() { - download=`cat speed.log | awk -F ':' '/Download/{print $2}'` - upload=`cat speed.log | awk -F ':' '/Upload/{print $2}'` - hostby=`cat speed.log | awk -F ':' '/Hosted/{print $1}'` - latency=`cat speed.log | awk -F ':' '/Hosted/{print $2}'` - clear - echo "$hostby" - echo "延迟 : $latency" - echo "上传 : $upload" - echo "下载 : $download" - echo -ne "\n当前时间: " - echo $(date +%Y-%m-%d" "%H:%M:%S) -} - -speed_test(){ - 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}') - 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 -} - -if [[ ${telecom} =~ ^[1-3]$ ]]; then - python speedtest.py --server ${num} --share 2>/dev/null | tee speed.log 2>/dev/null - is_down=$(cat speed.log | grep 'Download') - - if [[ ${is_down} ]]; then - result - echo "测试到 ${cityName}${telecomName} 完成!" - rm -rf speedtest.py - rm -rf speed.log - else - echo -e "\n${RED}ERROR:${PLAIN} 当前节点不可用,请更换其他节点,或换个时间段再测试。" - fi -fi - -if [[ ${telecom} == 4 ]]; then - python speedtest.py | tee speed.log - result - echo "本地测试完成!" - rm -rf speedtest.py - rm -rf speed.log -fi - -if [[ ${telecom} == 5 ]]; then - echo "" - printf "%-14s%-18s%-20s%-12s\n" "Node Name" "Upload Speed" "Download Speed" "Latency" - start=$(date +%s) - speed_test '12637' '襄阳电信' - speed_test '5081' '深圳电信' - speed_test '3633' '上海电信' - speed_test '4624' '成都电信' - speed_test '5017' '沈阳联通' - speed_test '4863' '西安联通' - speed_test '5083' '上海联通' - speed_test '5726' '重庆联通' - speed_test '5192' '西安移动' - speed_test '4665' '上海移动' - speed_test '6715' '宁波移动' - speed_test '4575' '成都移动' - end=$(date +%s) - rm -rf speedtest.py - echo "" - time=$(( $end - $start )) - if [[ $time -gt 60 ]]; then - min=$(expr $time / 60) - sec=$(expr $time % 60) - echo -ne "花费时间:${min} 分 ${sec} 秒" - else - echo -ne "花费时间:${time} 秒" - fi - echo -ne "\n当前时间: " - echo $(date +%Y-%m-%d" "%H:%M:%S) - echo "全面测试完成!" -fi