【发布时间】:2021-10-25 16:46:28
【问题描述】:
我发现 Locust UI 会从 http://my-locust-server/stats/requests 端点获取数据,并绘制图表。例如Total request per Second、Response Time 和 Number of Users。
我想将/stats/requests 数据发送到另一台服务器以进行绘图。如何在locustfile.py 中做到这一点?
以下代码不起作用,仅用于演示目的。
from locust import HttpUser, task, events
import requests
class User(HttpUser):
@task
def scenario_01(self):
self.client.get('/some_endpoint')
# ==========
# following codes won't work, will block the whole locust.
# ==========
import time
starttime = time.time()
while True:
r = requests.get('http://my-locust-server/stats/requests')
payload = r.json()
requests.post('http://another-server-for-plotting', json=payload)
time.sleep(5.0 - ((time.time() - starttime) % 5.0))
现在我能想到的是运行另一个程序来获取和报告数据。但是如何在一个locustfile.py 中做到这一点。
谢谢!
【问题讨论】: