Locust Combines Prometheus and Grafana

Related Tags:1. Delete ARMS Prometheus and ACK Prometheus
2. Prometheus: The Unicorn in Metrics

Abstract: An open source performance testing tool that uses Python code to define user behavior. Use it to simulate millions of concurrent users accessing your system, which is convenient, efficient, distributed, etc.


I. Introduction to Locust



An open source performance testing tool that uses Python code to define user behavior. Use it to simulate millions of concurrent users accessing your system, which is convenient, efficient, distributed, etc.

2. tool installation


environment python3
pip install locust
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn locust



3. Introduction to locust class library



Locust Official Documentation
Httpuser class: is the operation of user behavior
Client method: send request
Task class: class of task control, weight, skip, etc.
Taskset class: test set class
On_start method: similar to setup in automation, this method will be executed before each virtual user executes
On_stop method: similar to teardown in automation, this method is executed after each virtual user execution ends
@task decorator, if the task is followed by a number, it represents the weight in the test set. The larger the parameter, the higher the probability of being executed by the virtual user each time. Defaults to 1 if not set
The between method is the sleep time: the random number in the middle of the between values ​​will be taken
There are many other classes in Locust, which I have not used for the time being. If you are interested, you can go and learn about it. It is a very good performance tool.

4.locust use



Windows
I am using cloud server 2c4g here, bandwidth: 8Mbps
Code: Log in to the vsite website to press 100 concurrent
# coding=utf-8
"""
@Project : pachong-master
@File : test001.py
@Author: gaojs
@Date: 2022/5/19 21:47
@Blogs : https://www.gaojs.com.cn
"""
from locust import HttpUser, between, task, TaskSet, tag
import os
# Force remove console InsecureRequestWarning
import urllib3
# Randomly generate UA class library
from faker import Factory
urllib3.disable_warnings()
class TaskTest(TaskSet):
def on_start(self):
"""
description: Each user will obtain random numbers and digital signatures before performing stress testing
:return:
"""
# Each user will obtain a random number and digital signature before performing the stress test
# print('======================================================')
pass
# Stress test task, it can also be @task(10) or something, this number represents the weight, the larger the value, the higher the execution frequency
@task
def stress_get(self):
"""
Login to the virtual site
:return:
"""
url = '/prx/000/http/localh/login'
data = {
"Content-Type": "application/x-www-form-urlencoded, charset=UTF-8",
'Connection': 'close',
"method": "method1",
"uname": "t",
"pwd1": None,
"pwd2": None,
"pwd": "t",
"submitbutton": "Sign In"
}
randon_ua = Factory.create()
ua = randon_ua.user_agent()
headers = {
'User-Agent': ua
}
rsp = self.client.post(url=url, headers=headers, data=data, verify=False, allow_redirects=False, name='loginVsite pressure test')
# print(rsp.status_code)
print(rsp.text)
assert rsp.status_code == 302
# Execute the actions performed after the concurrent test, such as saving the log, etc., view the report http://localhost:8089/
def on_stop(self):
pass
class UserBehavior(HttpUser):
host = '192.168.120.209'
# pause time per request
wait_time = between(3, 10)
tasks = [TaskTest]
if __name__ == "__main__":
os.system("locust -f test004.py --host=https://192.168.120.209 --web-host=127.0.0.1")
implement
100 virtual users from ten seconds
Report
charts
RPS

Analysis result:
Average response time:
Throughput: within 1000
Minimum response time:
Maximum response time:
Whether the network fluctuates:
Does bandwidth affect:

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00

phone Contact Us