灏忎唬鐮?--http璇锋眰淇℃伅鍐欏叆鏂囦欢
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了灏忎唬鐮?--http璇锋眰淇℃伅鍐欏叆鏂囦欢相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/arc' title='arc'>arc
__name__ ali xxxxx http end pos info daypython3鐗堟湰
import datetime
import requests
import os
import time
log_name="client-quality.log"
def appendStrToFile(filePath, string):
with open(filePath, "ab") as f:
f.write(string)
def create_log_file(filePath):
if os.path.exists(filePath):
os.remove(filePath)
f = open(filePath, 鈥榳鈥?
f.close()
if __name__ == 鈥榑_main__鈥?
create_log_file(log_name)
for i in range(10000):
time_now = datetime.datetime.now()
appendStrToFile(log_name,str.encode(time_now.strftime("%Y-%m-%d %H:%M:%S") + 鈥榎n鈥?)
time_to = (time_now+datetime.timedelta(minutes=-5)).strftime("%Y-%m-%d %H:%M:%S")
time_from = (time_now+datetime.timedelta(days=-14,minutes=-5)).strftime("%Y-%m-%d %H:%M:%S")
url1 = "http://ip/xxx/api/v1/search_info?server_zone=internal"
body_profile =鈥榹"time":["鈥? time_from +鈥?,"鈥? time_to +鈥?],"xxxxx":"memory","xxxx":[0,1,2],"xxxx":"avg"}鈥?br /> r=requests.post(url1, data=body_profile)
#print(r.text)
log=url1+": "+str(r.elapsed.total_seconds())+"
"
appendStrToFile(log_name,str.encode(log))
#print(r.elapsed.total_seconds())
以上是关于灏忎唬鐮?--http璇锋眰淇℃伅鍐欏叆鏂囦欢的主要内容,如果未能解决你的问题,请参考以下文章