从 jmeter 启动 aws cli 命令
Launch aws cli commands from jmeter
我正在尝试使用 OS Process Sampler 到 运行 JMeter 中的 aws cli
命令。
我将 运行 在 docker 上安装 JMeter 和 aws cli
。但在我这样做之前,我尝试在我的 mac 上本地 运行 但到目前为止无法将 aws 命令发送到 运行.
在我的本地终端上,例如我可以运行:
一个。 aws--版本
b. bash j.sh (aws --version)
returns aws-cli/2.0.8 Python/3.7.4 Darwin/18.7.0 botocore/2.0.0dev12
这确认 aws cli 在可全局访问的路径中可用。
然而,当我 运行 来自 OS Process sampler 的相同命令时,我尝试了以下操作:
一个。
Working Directory: /Users/tester/Downloads/apache-jmeter-5.1.1/bin
Environment: {}
Executing: bash aws --version
响应:bash: aws --version: No such file or directory
b。
Working Directory: /Users/tester
Environment: {}
Executing: bash j.sh
where j.sh just contains the aws --version command
响应:j.sh: line 1: aws: command not found
我错过了什么?
我认为您需要按如下方式配置 OS Process Sampler:
- 命令:
/bin/bash
- 参数 1:
-c
参数2:aws --version
演示:
-c
If the -c option is present, then commands are read from
the first non-option argument command_string. If there are
arguments after the command_string, the first argument is
assigned to [=14=] and any remaining arguments are assigned to
the positional parameters. The assignment to [=14=] sets the
name of the shell, which is used in warning and error
messages.
更多信息:How to Run External Commands and Programs Locally and Remotely from JMeter
JMeter 中的 运行 aws cli 命令:
- 将 OS Process Sampler 添加到您的测试计划中。
- 在
Command
字段中输入您的命令:aws
。
- 在
Command Parameters
中添加您需要的任何参数,例如这个:--version
。
将查看结果树添加到您的线程组,运行 测试并查看响应正文:
aws-cli/2.0.0 Python/3.7.5 Windows/10 botocore/2.0.0dev4
感谢 Dmitri 和 Vadim 对我的问题的答复。不幸的是,这两个示例都是针对 Windows 的,其中 OS Process sampler 的工作方式与 Mac 不同。我还使用 Mac 上的 OS Process Sampler 对其进行了一些调整:
Mac 的主要区别在于 jmeter 需要安装 aws cli 的位置
/usr/local/bin/aws
我是通过哪个命令找到的
which aws
我还决定使用 Beanshell 采样器和日志记录来执行此操作,这将使我能够编写脚本并更好地控制我的其他需求。
这是我的参考代码:
try {
Process p = Runtime.getRuntime().exec("/usr/local/bin/aws --version");
p.waitFor();
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
StringBuilder logCommandOutput = new StringBuilder();
String line;
while ((line = in.readLine()) != null) {
logCommandOutput.append(line);
} in .close();
log.info("Output: " + logCommandOutput.toString());
} catch (Exception e) {
log.error("exception" + e);
}
希望这对正在尝试做同样事情的人有所帮助。
对于那些需要从 JMeter 在 Windows 上 运行 AWS CLI v2 命令的人(我使用 10)。
以下是我的设置。
原命令为:
$ aws dynamodb list-tables
结果:
我正在尝试使用 OS Process Sampler 到 运行 JMeter 中的 aws cli
命令。
我将 运行 在 docker 上安装 JMeter 和 aws cli
。但在我这样做之前,我尝试在我的 mac 上本地 运行 但到目前为止无法将 aws 命令发送到 运行.
在我的本地终端上,例如我可以运行: 一个。 aws--版本 b. bash j.sh (aws --version) returns aws-cli/2.0.8 Python/3.7.4 Darwin/18.7.0 botocore/2.0.0dev12
这确认 aws cli 在可全局访问的路径中可用。
然而,当我 运行 来自 OS Process sampler 的相同命令时,我尝试了以下操作: 一个。
Working Directory: /Users/tester/Downloads/apache-jmeter-5.1.1/bin
Environment: {}
Executing: bash aws --version
响应:bash: aws --version: No such file or directory
b。
Working Directory: /Users/tester
Environment: {}
Executing: bash j.sh
where j.sh just contains the aws --version command
响应:j.sh: line 1: aws: command not found
我错过了什么?
我认为您需要按如下方式配置 OS Process Sampler:
- 命令:
/bin/bash
- 参数 1:
-c
参数2:
aws --version
演示:
-c
If the -c option is present, then commands are read from the first non-option argument command_string. If there are arguments after the command_string, the first argument is assigned to [=14=] and any remaining arguments are assigned to the positional parameters. The assignment to [=14=] sets the name of the shell, which is used in warning and error messages.
更多信息:How to Run External Commands and Programs Locally and Remotely from JMeter
JMeter 中的 运行 aws cli 命令:
- 将 OS Process Sampler 添加到您的测试计划中。
- 在
Command
字段中输入您的命令:aws
。 - 在
Command Parameters
中添加您需要的任何参数,例如这个:--version
。
将查看结果树添加到您的线程组,运行 测试并查看响应正文:
aws-cli/2.0.0 Python/3.7.5 Windows/10 botocore/2.0.0dev4
感谢 Dmitri 和 Vadim 对我的问题的答复。不幸的是,这两个示例都是针对 Windows 的,其中 OS Process sampler 的工作方式与 Mac 不同。我还使用 Mac 上的 OS Process Sampler 对其进行了一些调整:
Mac 的主要区别在于 jmeter 需要安装 aws cli 的位置
/usr/local/bin/aws
我是通过哪个命令找到的
which aws
我还决定使用 Beanshell 采样器和日志记录来执行此操作,这将使我能够编写脚本并更好地控制我的其他需求。 这是我的参考代码:
try {
Process p = Runtime.getRuntime().exec("/usr/local/bin/aws --version");
p.waitFor();
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
StringBuilder logCommandOutput = new StringBuilder();
String line;
while ((line = in.readLine()) != null) {
logCommandOutput.append(line);
} in .close();
log.info("Output: " + logCommandOutput.toString());
} catch (Exception e) {
log.error("exception" + e);
}
希望这对正在尝试做同样事情的人有所帮助。
对于那些需要从 JMeter 在 Windows 上 运行 AWS CLI v2 命令的人(我使用 10)。 以下是我的设置。
原命令为:
$ aws dynamodb list-tables
结果: