zoukankan      html  css  js  c++  java
  • 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)
  • 相关阅读:
    codevs 3049 舞蹈家怀特先生
    洛谷P2530 [SHOI2001]化工厂装箱员
    洛谷P2736 “破锣摇滚”乐队 Raucous Rockers
    Phalanx
    Treats for the Cows
    Very Simple Problem
    Alice and Bob
    FatMouse and Cheese
    Tickets
    Piggy-Bank
  • 原文地址:https://www.cnblogs.com/stone1989/p/14648357.html
Copyright © 2011-2022 走看看