-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlocustfile.py
48 lines (39 loc) · 1.35 KB
/
locustfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from locust import HttpUser, TaskSet, task, between
from locust.exception import StopUser
class UserBehavior(TaskSet):
def on_start(self):
""" Called when a Locust user starts running """
self.login()
def login(self):
""" Simulate a user logging in """
response = self.client.post("/login", {
"username": "admin",
"password": "adminpassword"
})
if response.status_code == 200 and "Invalid username or password" not in response.text:
print("Login successful")
else:
print("Login failed")
raise StopUser("Login failed")
@task(1)
def view_dashboard(self):
""" Simulate viewing the dashboard """
self.client.get("/")
@task(2)
def view_cpu_usage(self):
""" Simulate viewing CPU usage """
self.client.get("/cpu_usage")
@task(1)
def view_disk_usage(self):
""" Simulate viewing disk usage """
self.client.get("/disk_usage")
@task(1)
def view_memory_usage(self):
""" Simulate viewing memory usage """
self.client.get("/memory_usage")
class WebsiteUser(HttpUser):
tasks = [UserBehavior]
wait_time = between(1, 5) # Time to wait between tasks
if __name__ == "__main__":
import os
os.system("locust -f locustfile.py --host=http://localhost:5000")