Python3 多线程压测接口数据:写入到influxdb:通过grafana展示

背景:
针对接口全链路耗时展示

#!/usr/bin/python
# -*- coding: utf-8 -*-
import threading
import time
import requests
import json

from influxdb import InfluxDBClient
client = InfluxDBClient(host='127.0.0.1', port=8086, username='yace', password='yace1231', database='yace')
yace_url='http://10.1.1.1/api/rta/tx/executeTest'
headers = {
'Content-Type': 'application/json',
'host':'www.baidu.com',
}
data = {"id":"12313","siteset_id":1,"did_md5":"dawsda","is_test":"false"}
def yace():
    s = requests.session()
    response = s.post(url=yace_url, headers=headers, data=json.dumps(data))
    s.close()
    status_code=int(response.status_code)
    request_time=float(response.elapsed.microseconds/1000)
    text = [
        {
            "measurement":"rta",
            "tags":{
                "url":"www.baidu.com"
            },
            "fields":{
                "status_code":status_code,
                "request_time":request_time,
            }
        }
    ]
    client.write_points(text)
while True:
    t = threading.Thread(target=yace)
    t.start()
    time.sleep(0.01)
posted @ 2021-04-12 15:49  石Stone头  阅读(378)  评论(0编辑  收藏  举报