0
点赞
收藏
分享

微信扫一扫

Locust工具学习(三)配置信息及--help

琛彤麻麻 2022-04-15 阅读 45
python

locust --help

控制台输入 locust 帮助信息

$locust --help
Usage: locust [OPTIONS] [UserClass ...]

Common options:
  -h, --help            show this help message and exit
  -f LOCUSTFILE, --locustfile LOCUSTFILE
                        Python module to import, e.g. '../other_test.py'. Either a .py file or a package directory. Defaults to 'locustfile'
  --config CONFIG       Config file path
  -H HOST, --host HOST  Host to load test in the following format: http://10.21.32.33
  -u NUM_USERS, --users NUM_USERS
                        Peak number of concurrent Locust users. Primarily used together with --headless or --autostart. Can be changed during a test by keyboard inputs w, W (spawn 1, 10 users) and s, S (stop 1, 10 users)
  -r SPAWN_RATE, --spawn-rate SPAWN_RATE
                        Rate to spawn users at (users per second). Primarily used together with --headless or --autostart
  -t RUN_TIME, --run-time RUN_TIME
                        Stop after the specified amount of time, e.g. (300s, 20m, 3h, 1h30m, etc.). Only used together with --headless or --autostart. Defaults to run forever.
  -l, --list            Show list of possible User classes and exit

Web UI options:
  --web-host WEB_HOST   Host to bind the web interface to. Defaults to '*' (all interfaces)
  --web-port WEB_PORT, -P WEB_PORT
                        Port on which to run web host
  --headless            Disable the web interface, and start the test immediately. Use -u and -t to control user count and run time
  --autostart           Starts the test immediately (without disabling the web UI). Use -u and -t to control user count and run time
  --autoquit AUTOQUIT   Quits Locust entirely, X seconds after the run is finished. Only used together with --autostart. The default is to keep Locust running until you shut it down using CTRL+C
  --web-auth WEB_AUTH   Turn on Basic Auth for the web interface. Should be supplied in the following format: username:password
  --tls-cert TLS_CERT   Optional path to TLS certificate to use to serve over HTTPS
  --tls-key TLS_KEY     Optional path to TLS private key to use to serve over HTTPS

Master options:
  Options for running a Locust Master node when running Locust distributed. A Master node need Worker nodes that connect to it before it can run load tests.

  --master              Set locust to run in distributed mode with this process as master
  --master-bind-host MASTER_BIND_HOST
                        Interfaces (hostname, ip) that locust master should bind to. Only used when running with --master. Defaults to * (all available interfaces).
  --master-bind-port MASTER_BIND_PORT
                        Port that locust master should bind to. Only used when running with --master. Defaults to 5557.
  --expect-workers EXPECT_WORKERS
                        How many workers master should expect to connect before starting the test (only when --headless/autostart is used).
  --expect-workers-max-wait EXPECT_WORKERS_MAX_WAIT
                        How long should the master wait for workers to connect before giving up. Defaults to wait forever

Worker options:
  Options for running a Locust Worker node when running Locust distributed.
  Only the LOCUSTFILE (-f option) needs to be specified when starting a Worker, since other options such as -u, -r, -t are specified on the Master node.

  --worker              Set locust to run in distributed mode with this process as worker
  --master-host MASTER_NODE_HOST
                        Host or IP address of locust master for distributed load testing. Only used when running with --worker. Defaults to 127.0.0.1.
  --master-port MASTER_NODE_PORT
                        The port to connect to that is used by the locust master for distributed load testing. Only used when running with --worker. Defaults to 5557.

Tag options:
  Locust tasks can be tagged using the @tag decorator. These options let specify which tasks to include or exclude during a test.

  -T [TAG ...], --tags [TAG ...]
                        List of tags to include in the test, so only tasks with any matching tags will be executed
  -E [TAG ...], --exclude-tags [TAG ...]
                        List of tags to exclude from the test, so only tasks with no matching tags will be executed

Request statistics options:
  --csv CSV_PREFIX      Store current request stats to files in CSV format. Setting this option will generate three files: [CSV_PREFIX]_stats.csv, [CSV_PREFIX]_stats_history.csv and [CSV_PREFIX]_failures.csv
  --csv-full-history    Store each stats entry in CSV format to _stats_history.csv file. You must also specify the '--csv' argument to enable this.
  --print-stats         Print stats in the console
  --only-summary        Only print the summary stats
  --reset-stats         Reset statistics once spawning has been completed. Should be set on both master and workers when running in distributed mode
  --html HTML_FILE      Store HTML report to file path specified

Logging options:
  --skip-log-setup      Disable Locust's logging setup. Instead, the configuration is provided by the Locust test or Python defaults.
  --loglevel LOGLEVEL, -L LOGLEVEL
                        Choose between DEBUG/INFO/WARNING/ERROR/CRITICAL. Default is INFO.
  --logfile LOGFILE     Path to log file. If not set, log will go to stderr

Other options:
  --show-task-ratio     Print table of the User classes' task execution ratio. Use this with non-zero --user option if some classes define non-zero fixed_count property.
  --show-task-ratio-json
                        Print json data of the User classes' task execution ratio. Use this with non-zero --user option if some classes define non-zero fixed_count property.
  --version, -V         Show program's version number and exit
  --exit-code-on-error EXIT_CODE_ON_ERROR
                        Sets the process exit code to use when a test result contain any failure or error
  -s STOP_TIMEOUT, --stop-timeout STOP_TIMEOUT
                        Number of seconds to wait for a simulated user to complete any executing task before exiting. Default is to terminate immediately. This parameter only needs to be specified for the master process when running Locust distributed.
  --equal-weights       Use equally distributed task weights, overriding the weights specified in the locustfile.
  --enable-rebalancing  Allow to automatically rebalance users if new workers are added or removed during a test run.

User classes:
  UserClass             Optionally specify which User classes that should be used (available User classes can be listed with -l or --list)

对应配置信息说明:

命令行

环境

配置文件

描述

-f,--locustfile

LOCUST_LOCUSTFILE

locustfile

要导入的 Python 模块,例如“../other_test.py”。.py 文件或包目录。默认为“locustfile.py”

-H,--host

LOCUST_HOST

host

主机负载host地址如下:http: //10.21.32.33

-u,--users

LOCUST_USERS

users

并发 Locust 用户的峰值数量。主要与–headless 或–autostart 一起使用。可以在测试期间通过键盘输入 w、W(生成 1、10 个用户)和 s、S(停止 1、10 个用户)更改

-r,--spawn-rate

LOCUST_SPAWN_RATE

spawn-rate

以(每秒用户数)生成用户的速率。主要与 –headless 或 –autostart 一起使用

--hatch-rate

LOCUST_HATCH_RATE

hatch-rate

==抑制==

-t,--run-time

LOCUST_RUN_TIME

run-time

在指定的时间后停止,例如(300s、20m、3h、1h30m 等)。仅与 –headless 或 –autostart 一起使用。默认永远运行。

--web-host

LOCUST_WEB_HOST

web-host

将 Web 界面绑定到的主机。默认为“*”(所有接口)

--web-port,-P

LOCUST_WEB_PORT

web-port

运行 Web 主机的端口

--headless

LOCUST_HEADLESS

headless

禁用 Web 界面,并立即开始测试。使用 -u 和 -t 控制用户数和运行时间

--autostart

LOCUST_AUTOSTART

autostart

立即开始测试(不禁用 Web UI)。使用 -u 和 -t 控制用户数和运行时间

--autoquit

LOCUST_AUTOQUIT

autoquit

在运行完成 X 秒后完全退出 Locust。仅与 –autostart 一起使用。默认设置是保持 Locust 运行,直到您使用 CTRL+C 将其关闭

--headful

LOCUST_HEADFUL

headful

==抑制==

--web-auth

LOCUST_WEB_AUTH

web-auth

为 Web 界面打开基本身份验证。应按以下格式提供:用户名:密码

--tls-cert

LOCUST_TLS_CERT

tls-cert

用于通过 HTTPS 提供服务的 TLS 证书的可选路径

--tls-key

LOCUST_TLS_KEY

tls-key

用于通过 HTTPS 提供服务的 TLS 私钥的可选路径

--master

LOCUST_MODE_MASTER

master

设置 locust 以分布式模式运行,此进程作为主进程

--master-bind-host

LOCUST_MASTER_BIND_HOST

master-bind-host

locust master 应该绑定的接口(主机名、ip)。仅在使用 –master 运行时使用。默认为 *(所有可用接口)。

--master-bind-port

LOCUST_MASTER_BIND_PORT

master-bind-port

locust master 应该绑定的端口。仅在使用 –master 运行时使用。默认为 5557。

--expect-workers

LOCUST_EXPECT_WORKERS

expect-workers

在开始测试之前,master 应该期望连接多少个worker(仅当使用–headless/autostart 时)。

--expect-workers-max-wait

LOCUST_EXPECT_WORKERS_MAX_WAIT

expect-workers-max-wait

主人在放弃之前应该等待工人连接多长时间。默认为永远等待

--worker

LOCUST_MODE_WORKER

worker

设置 locust 以分布式模式运行,此进程作为 worker

--master-host

LOCUST_MASTER_NODE_HOST

master-host

用于分布式负载测试的 locust master 的主机或 IP 地址。仅在使用 –worker 运行时使用。默认为 127.0.0.1。

--master-port

LOCUST_MASTER_NODE_PORT

master-port

locust master 使用要连接的端口进行分布式负载测试。仅在使用 –worker 运行时使用。默认为 5557。

-T,--tags

LOCUST_TAGS

tags

要包含在测试中的标签列表,因此只有具有任何匹配标签的任务才会被执行

-E,--exclude-tags

LOCUST_EXCLUDE_TAGS

exclude-tags

要从测试中排除的标签列表,因此只会执行没有匹配标签的任务

--csv

LOCUST_CSV

csv

以 CSV 格式将当前请求统计信息存储到文件中。设置此选项将生成三个文件:[CSV_PREFIX]_stats.csv、[CSV_PREFIX]_stats_history.csv 和 [CSV_PREFIX]_failures.csv

--csv-full-history

LOCUST_CSV_FULL_HISTORY

csv-full-history

将每个统计信息条目以 CSV 格式存储到 _stats_history.csv 文件中。您还必须指定“–csv”参数才能启用此功能。

--print-stats

LOCUST_PRINT_STATS

print-stats

在控制台中打印统计信息

--only-summary

LOCUST_ONLY_SUMMARY

only-summary

仅打印摘要统计信息

--reset-stats

LOCUST_RESET_STATS

reset-stats

产卵完成后重置统计信息。在分布式模式下运行时,应在 master 和 worker 上都设置

--html

LOCUST_HTML

html

将 HTML 报告存储到指定的文件路径

--skip-log-setup

LOCUST_SKIP_LOG_SETUP

skip-log-setup

禁用 Locust 的日志记录设置。相反,配置由 Locust 测试或 Python 默认值提供。

--loglevel,-L

LOCUST_LOGLEVEL

loglevel

在调试/信息/警告/错误/关键之间进行选择。默认为信息。

--logfile

LOCUST_LOGFILE

logfile

日志文件的路径。如果未设置,日志将转到 stderr

--exit-code-on-error

LOCUST_EXIT_CODE_ON_ERROR

exit-code-on-error

设置当测试结果包含任何失败或错误时使用的进程退出代码

-s,--stop-timeout

LOCUST_STOP_TIMEOUT

stop-timeout

在退出之前等待模拟用户完成任何正在执行的任务的秒数。默认是立即终止。该参数只需要在运行 Locust 分布式时为主进程指定。

 

环境变量

大多数可以通过命令行参数设置的选项也可以通过环境变量设置。例子:

$LOCUST_LOCUSTFILE=custom_locustfile.py locust

配置文件

 配置文件默认为:locust.conf

可使用--config指定附加的配置文件

例子:

locustfile = locust_files/my_locust_file.py
headless = true
master = true
expect-workers = 5
host = http://target-system
users = 100
spawn-rate = 10
run-time = 10m
$locust --config=master.conf

当多个地方均有配置时,配置信息按以下顺序取值

举报

相关推荐

0 条评论