Skip to content

Commit

Permalink
fix capacity bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
oooldking committed Jun 29, 2018
1 parent a82b659 commit 3270721
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 49 deletions.
54 changes: 28 additions & 26 deletions superbench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,13 @@ benchinit() {
fi
chmod a+rx speedtest.py

# install ip_info.py
if [ ! -e 'ip_info.py' ]; then
echo " Installing IP_info.py ..."
wget --no-check-certificate https://raw.githubusercontent.com/oooldking/script/master/ip_info.py > /dev/null 2>&1
fi
chmod a+rx ip_info.py

# install ipip.py
if [ ! -e 'ipip.py' ]; then
echo " Installing ipip.py ..."
wget --no-check-certificate https://raw.githubusercontent.com/oooldking/script/master/ipip.py > /dev/null 2>&1
# install tools.py
if [ ! -e 'tools.py' ]; then
echo " Installing tools.py ..."
wget --no-check-certificate https://raw.githubusercontent.com/oooldking/script/master/tools.py > /dev/null 2>&1
fi
chmod a+rx ipip.py
chmod a+rx tools.py

# install fast.com-cli
if [ ! -e 'fast_com.py' ]; then
Expand Down Expand Up @@ -373,22 +367,24 @@ ip_info3(){

ip_info4(){
echo $(curl -4 -s https://api.ip.la/en?json) > ip_json.json
country=$(python ipip.py country_name)
city=$(python ipip.py city)
isp=$(python ip_info.py isp)
as_tmp=$(python ip_info.py as)
country=$(python tools.py ipip country_name)
city=$(python tools.py ipip city)
isp=$(python tools.py geoip isp)
as_tmp=$(python tools.py geoip as)
asn=$(echo $as_tmp | awk -F ' ' '{print $1}')
org=$(python ip_info.py org)
countryCode=$(python ipip.py country_code)
region=$(python ipip.py province)
org=$(python tools.py geoip org)
countryCode=$(python tools.py ipip country_code)
region=$(python tools.py ipip province)
if [ !city ]; then
city=${region}
fi

echo -e " ASN & ISP : ${SKYBLUE}$asn, $isp${PLAIN}" | tee -a $log
echo -e " Organization : ${GREEN}$org${PLAIN}" | tee -a $log
echo -e " Location : ${SKYBLUE}$city, ${GREEN}$country / $countryCode${PLAIN}" | tee -a $log
echo -e " Organization : ${YELLOW}$org${PLAIN}" | tee -a $log
echo -e " Location : ${SKYBLUE}$city, ${YELLOW}$country / $countryCode${PLAIN}" | tee -a $log
echo -e " Region : ${SKYBLUE}$region${PLAIN}" | tee -a $log

rm -rf ip_info.py
rm -rf ipip.py
rm -rf tools.py
rm -rf ip_json.json
}

Expand All @@ -413,6 +409,8 @@ virt_check(){
virtual="OpenVZ"
elif [[ "$virtualx" == *kvm-clock* ]]; then
virtual="KVM"
elif [[ "$cname" == *KVM* ]]; then
virtual="KVM"
elif [[ "$virtualx" == *"VMware Virtual Platform"* ]]; then
virtual="VMware"
elif [[ "$virtualx" == *"Parallels Software International"* ]]; then
Expand Down Expand Up @@ -551,8 +549,13 @@ get_system_info() {
#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[@]} )
#disk_total_size=$( calc_disk ${disk_size1[@]} )
#disk_used_size=$( calc_disk ${disk_size2[@]} )
tmp=$(python tools.py disk 0)
disk_total_size=$(echo $tmp | grep -Eo '[0-9]+')
tmp=$(python tools.py disk 1)
disk_used_size=$(echo $tmp | grep -Eo '[0-9]+')

virt_check
}

Expand Down Expand Up @@ -614,8 +617,7 @@ cleanup() {
rm -f test_file_*;
rm -f speedtest.py;
rm -f fast_com*;
rm -f ip_info.py;
rm -f ipip.py;
rm -f tools.py;
rm -f ip_json.json
}

Expand Down
45 changes: 22 additions & 23 deletions superbench_git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,11 @@ benchinit() {
fi
chmod a+rx speedtest.py

if [ ! -e 'ip_info.py' ]; then
echo " Installing IP_info.py ..."
wget --no-check-certificate https://raw.githubusercontent.com/oooldking/script/master/ip_info.py > /dev/null 2>&1
if [ ! -e 'tools.py' ]; then
echo " Installing tools.py ..."
wget --no-check-certificate https://raw.githubusercontent.com/oooldking/script/master/tools.py > /dev/null 2>&1
fi
chmod a+rx ip_info.py

if [ ! -e 'ipip.py' ]; then
echo " Installing ipip.py ..."
wget --no-check-certificate https://raw.githubusercontent.com/oooldking/script/master/ipip.py > /dev/null 2>&1
fi
chmod a+rx ipip.py
chmod a+rx tools.py

if [ ! -e 'fast_com.py' ]; then
echo " Installing Fast.com-cli ..."
Expand Down Expand Up @@ -264,14 +258,14 @@ install_smart() {

ip_info4(){
echo $(curl -4 -s https://api.ip.la/en?json) > ip_json.json
country=$(python ipip.py country_name)
city=$(python ipip.py city)
isp=$(python ip_info.py isp)
as_tmp=$(python ip_info.py as)
country=$(python tools.py ipip country_name)
city=$(python tools.py ipip city)
isp=$(python tools.py geoip isp)
as_tmp=$(python tools.py geoip as)
asn=$(echo $as_tmp | awk -F ' ' '{print $1}')
org=$(python ip_info.py org)
countryCode=$(python ipip.py country_code)
region=$(python ipip.py province)
org=$(python tools.py geoip org)
countryCode=$(python tools.py ipip country_code)
region=$(python tools.py ipip province)
if [ !city ]; then
city=${region}
fi
Expand All @@ -281,8 +275,7 @@ ip_info4(){
echo -e " Location : ${SKYBLUE}$city, ${YELLOW}$country / $countryCode${PLAIN}" | tee -a $log
echo -e " Region : ${SKYBLUE}$region${PLAIN}" | tee -a $log

rm -rf ip_info.py
rm -rf ipip.py
rm -rf tools.py
rm -rf ip_json.json
}

Expand All @@ -307,6 +300,8 @@ virt_check(){
virtual="OpenVZ"
elif [[ "$virtualx" == *kvm-clock* ]]; then
virtual="KVM"
elif [[ "$cname" == *KVM* ]]; then
virtual="KVM"
elif [[ "$virtualx" == *"VMware Virtual Platform"* ]]; then
virtual="VMware"
elif [[ "$virtualx" == *"Parallels Software International"* ]]; then
Expand Down Expand Up @@ -440,8 +435,13 @@ get_system_info() {

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[@]} )
#disk_total_size=$( calc_disk ${disk_size1[@]} )
#disk_used_size=$( calc_disk ${disk_size2[@]} )
tmp=$(python tools.py disk 0)
disk_total_size=$(echo $tmp | grep -Eo '[0-9]+')
tmp=$(python tools.py disk 1)
disk_used_size=$(echo $tmp | grep -Eo '[0-9]+')

virt_check
}

Expand Down Expand Up @@ -483,8 +483,7 @@ cleanup() {
rm -f test_file_*;
rm -f speedtest.py;
rm -f fast_com*;
rm -f ip_info.py;
rm -f ipip.py;
rm -f tools.py;
rm -f ip_json.json
}

Expand Down
70 changes: 70 additions & 0 deletions tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import time,urllib2,json,sys
import shlex
import datetime
import subprocess

reload(sys)
sys.setdefaultencoding('utf-8')

def GetIpipInfo(para):
f = open("ip_json.json",'r')
ijson = json.load(f)
jjson = ijson['location']
print jjson[para.encode('utf-8')]

def GetGeoioInfo(para):
ip_api = urllib2.urlopen(r'http://ip-api.com/json')
ijson = json.loads(ip_api.read())
print ijson[para.encode('utf-8')]

def GetDiskInfo(para):
temp = ExecShell("df -h -P|grep '/'|grep -v tmpfs")[0];
temp1 = temp.split('\n');
diskInfo = [];
n = 0
cuts = ['/mnt/cdrom','/boot','/boot/efi','/dev','/dev/shm','/run/lock','/run','/run/shm','/run/user'];
for tmp in temp1:
n += 1
disk = tmp.split();
if len(disk) < 5: continue;
if disk[1].find('M') != -1: continue;
if disk[1].find('K') != -1: continue;
if len(disk[5].split('/')) > 4: continue;
if disk[5] in cuts: continue;
arr = {}
diskInfo = [disk[1],disk[2],disk[3],disk[4],disk[5]];

print(diskInfo[int(para)]);

def ExecShell(cmdstring, cwd=None, timeout=None, shell=True):

if shell:
cmdstring_list = cmdstring
else:
cmdstring_list = shlex.split(cmdstring)
if timeout:
end_time = datetime.datetime.now() + datetime.timedelta(seconds=timeout)

sub = subprocess.Popen(cmdstring_list, cwd=cwd, stdin=subprocess.PIPE,shell=shell,bufsize=4096,stdout=subprocess.PIPE,stderr=subprocess.PIPE)

while sub.poll() is None:
time.sleep(0.1)
if timeout:
if end_time <= datetime.datetime.now():
raise Exception("Timeout:%s"%cmdstring)

return sub.communicate()

if __name__ == "__main__":
type = sys.argv[1];
if type == 'disk':
GetDiskInfo(sys.argv[2])
elif type == 'geoip':
GetGeoioInfo(sys.argv[2])
elif type == 'ipip':
GetIpipInfo(sys.argv[2])
else:
print 'ERROR: Parameter error'

0 comments on commit 3270721

Please sign in to comment.