mirror of
https://github.com//cppla/ServerStatus
synced 2025-06-05 07:09:49 +08:00
根据建议换成tcp ping: 443回程
This commit is contained in:
parent
b1166a540c
commit
8ce00805c5
@ -161,47 +161,56 @@ lostRate = {
|
||||
'189': 0.0,
|
||||
'10086': 0.0
|
||||
}
|
||||
def _ping_thread(host, mark):
|
||||
output = os.popen('ping -O %s &' % host)
|
||||
lostCount = 0
|
||||
allCount = 0
|
||||
def _ping_thread(host, mark, port):
|
||||
lostPacket = 0
|
||||
allPacket = 0
|
||||
startTime = time.time()
|
||||
output.readline()
|
||||
|
||||
while True:
|
||||
buffer = output.readline()
|
||||
if len(buffer) == 0:
|
||||
return
|
||||
if 'ttl' not in buffer:
|
||||
lostCount += 1
|
||||
allCount += 1
|
||||
if allCount > 100:
|
||||
lostRate[mark] = float(lostCount) / allCount
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.settimeout(1)
|
||||
try:
|
||||
s.connect((host, port))
|
||||
except:
|
||||
lostPacket += 1
|
||||
finally:
|
||||
allPacket += 1
|
||||
s.close()
|
||||
|
||||
if allPacket > 100:
|
||||
lostRate[mark] = float(lostPacket) / allPacket
|
||||
|
||||
endTime = time.time()
|
||||
if endTime-startTime > 3600:
|
||||
lostCount = 0
|
||||
allCount = 0
|
||||
if endTime - startTime > 3600:
|
||||
lostPacket = 0
|
||||
allPacket = 0
|
||||
startTime = endTime
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
def get_packetLostRate():
|
||||
t1 = threading.Thread(
|
||||
target=_ping_thread,
|
||||
kwargs={
|
||||
'host': 'cu.tz.cloudcpp.com',
|
||||
'mark': '10010'
|
||||
'mark': '10010',
|
||||
'port': 443
|
||||
}
|
||||
)
|
||||
t2 = threading.Thread(
|
||||
target=_ping_thread,
|
||||
kwargs={
|
||||
'host': 'ct.tz.cloudcpp.com',
|
||||
'mark': '189'
|
||||
'mark': '189',
|
||||
'port': 443
|
||||
}
|
||||
)
|
||||
t3 = threading.Thread(
|
||||
target=_ping_thread,
|
||||
kwargs={
|
||||
'host': 'cm.tz.cloudcpp.com',
|
||||
'mark': '10086'
|
||||
'mark': '10086',
|
||||
'port': 443
|
||||
}
|
||||
)
|
||||
t1.setDaemon(True)
|
||||
|
@ -129,48 +129,56 @@ lostRate = {
|
||||
'189': 0.0,
|
||||
'10086': 0.0
|
||||
}
|
||||
def _ping_thread(host, mark):
|
||||
output = os.popen('ping -O %s &' % host if 'linux' in sys.platform else 'ping %s -t &' % host)
|
||||
lostCount = 0
|
||||
allCount = 0
|
||||
def _ping_thread(host, mark, port):
|
||||
lostPacket = 0
|
||||
allPacket = 0
|
||||
startTime = time.time()
|
||||
output.readline()
|
||||
output.readline()
|
||||
|
||||
while True:
|
||||
buffer = output.readline()
|
||||
if len(buffer) == 0:
|
||||
return
|
||||
if 'TTL' not in buffer.upper():
|
||||
lostCount += 1
|
||||
allCount += 1
|
||||
if allCount > 100:
|
||||
lostRate[mark] = float(lostCount) / allCount
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.settimeout(1)
|
||||
try:
|
||||
s.connect((host, port))
|
||||
except:
|
||||
lostPacket += 1
|
||||
finally:
|
||||
allPacket += 1
|
||||
s.close()
|
||||
|
||||
if allPacket > 100:
|
||||
lostRate[mark] = float(lostPacket) / allPacket
|
||||
|
||||
endTime = time.time()
|
||||
if endTime-startTime > 3600:
|
||||
lostCount = 0
|
||||
allCount = 0
|
||||
if endTime - startTime > 3600:
|
||||
lostPacket = 0
|
||||
allPacket = 0
|
||||
startTime = endTime
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
def get_packetLostRate():
|
||||
t1 = threading.Thread(
|
||||
target=_ping_thread,
|
||||
kwargs={
|
||||
'host': 'cu.tz.cloudcpp.com',
|
||||
'mark': '10010'
|
||||
'mark': '10010',
|
||||
'port': 443
|
||||
}
|
||||
)
|
||||
t2 = threading.Thread(
|
||||
target=_ping_thread,
|
||||
kwargs={
|
||||
'host': 'ct.tz.cloudcpp.com',
|
||||
'mark': '189'
|
||||
'mark': '189',
|
||||
'port': 443
|
||||
}
|
||||
)
|
||||
t3 = threading.Thread(
|
||||
target=_ping_thread,
|
||||
kwargs={
|
||||
'host': 'cm.tz.cloudcpp.com',
|
||||
'mark': '10086'
|
||||
'mark': '10086',
|
||||
'port': 443
|
||||
}
|
||||
)
|
||||
t1.setDaemon(True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user