亚洲视频二区_亚洲欧洲日本天天堂在线观看_日韩一区二区在线观看_中文字幕不卡一区

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.430618.com 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

近日接到人行通知,要求對金融行業IPv6規模部署情況進行專項排查,其中一項內容就是針對門戶網站連接穩定性進行監控,具體要求就是:

金融服務機構提供正式報告說明穩定性測試數據。(不少于15天時間,每隔1小時發起門戶網站連接,記錄連接失敗率),應網絡同事要求,結合自己最近學習的Python,寫了如下程序,將執行結果保存到文件中,源碼如下,僅供Python愛好者一起分析學習:

************************************************

#coding=utf-8

import requests

import csv

import datetime

import time

from requests.exceptions import RequestException

from threading import Timer

#本程序運行每間隔指定時間,產生一條數據,數據文件為csv格式,每行文件內容為:

#當前時間,聯通IPv6耗時,聯通IPv4耗時,聯通耗時結果,電信IPv6耗時,電信IPv4耗時,電信耗時結果

#是否滿足要求公式:IPv6耗時-IPv4耗時<75ms,通過sucess;IPv6耗時-IPv4耗時>75ms,不通過fail

#定義獲取時間方法

def get_time():

url1 = 'http://[xx:xx:xxxx::x]'#門戶網站聯通6,需要調整為自己的IP

url2 = 'http://xx.xx.xx.xx' #門戶網站聯通4,需要調整為自己的IP

url3 = 'http://[xx:xx:xx::x]' #門戶網站電信6,需要調整為自己的IP

url4 = 'http://xx.x.xx.xx' #門戶網站電信4,需要調整為自己的IP

destList = [url1,url2,url3,url4]

#print(destList)

now_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

timeList = []

dataList = []

#當前時間

dataList.Append(str(now_time))

timeOut = 'timeOut'

timePass = 'sucess'

timeFail = 'fail'

other = 'none'

#IPv6-IPv4耗時最低合格時間75ms

timeLimit = 75

#獲取每個請求的時間ms,超時數組則存放timeOut

for url in destList:

#print(url)

try:

reqDest = requests.get(url)

timeList.append(reqDest.elapsed.total_seconds()*1000)

except (RequestException):

timeList.append(timeOut)

#準備數據行

#聯通線路請求耗時數據

if(timeOut != timeList[0]):

dataList.append(str(round(timeList[0],3))+'ms')

else:

dataList.append(str(timeList[0]))

if(timeOut != timeList[1]):

dataList.append(str(round(timeList[1],3))+'ms')

else:

dataList.append(str(timeList[1]))

if(timeOut != timeList[0] and timeOut != timeList[1]):

ltTimeLast= timeList[0]-timeList[1]

if(ltTimeLast < timeLimit):

dataList.append(timePass)

else:

dataList.append(timeFail)

else:

dataList.append(other)

#電信請求耗時數據

if(timeOut != timeList[2]):

dataList.append(str(round(timeList[2],3))+'ms')

else:

dataList.append(str(timeList[2]))

if(timeOut != timeList[3]):

dataList.append(str(round(timeList[3],3))+'ms')

else:

dataList.append(str(timeList[3]))

if(timeOut != timeList[2] and timeOut != timeList[3]):

dxTimeLast= timeList[2]-timeList[3]

if(dxTimeLast < timeLimit):

dataList.append(timePass)

else:

dataList.append(timeFail)

else:

dataList.append(other)

return dataList

#定義寫文件title方法

def writeFileTitle():

with open('IPv6-IPv4TimeResult.csv', "a+") as file:

titleList = ['當前時間','聯通IPv6耗時','聯通IPv4耗時','聯通耗時結果','電信IPv6耗時','電信IPv4耗時','電信耗時結果']

csv_file = csv.writer(file)

csv_file.writerow(titleList)

file.close()

#定義增量寫一行數據方法

def writeReq_time():

with open('IPv6-IPv4TimeResult.csv', "a+") as file:

begin_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

print(begin_time + ' begin to request')

csv_file = csv.writer(file)

list = []

list.append(get_time())

datas = list

csv_file.writerows(datas)

end_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

print(end_time + ' end to write')

file.close()

#主程序入口

#調用文件title

writeFileTitle()

#線程延遲時間1s執行

timer_interval=1

#線程間隔3600s執行

timer_sleep = 3600

t=Timer(timer_interval,writeReq_time)

t.start()

while True:

time.sleep(timer_sleep)

writeReq_time()

*******************************

程序執行界面及結果如下:

Python小程序網絡耗時監控「原創」

程序運行界面


Python小程序網絡耗時監控「原創」

分享到:
標簽:程序 Python
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定