[IDCF] A story about tweaking CloudStackAPI when building a jmeter execution environment for load testing

table of contents
My name is Teraoka, and I am an infrastructure engineer.
I was working on a project where I needed to build a jmeter runtime environment on IDCF.
I used CloudStack API during the build process, and I'd like to share some of the tricks I used.
■What did you want to do in the first place?
when I started jmeter on the server that acts as the jmeter controller,
the IP address of the server that acts as the corresponding node would be automatically recognized.
Yes, that's it.
Jmeter has a mechanism called
remote testing,
and by registering the servers (nodes) on which remote Jmeter is running
in the configuration file of the controller server, you can generate more load than the number of registered servers.
However, the number of servers to be registered changes depending on the load generated, and
it is a hassle to change the configuration file each time, so
we decided to identify only the nodes that are running and
when starting jmeter on the controller side
.
■ What specifically did you do?
To register a remote server in jmeter,
add the setting to the "remote_hosts" item in the "jmeter.properties" file.
For example, it looks like this:
remote_hosts=10.31.X.XX,10.31.X.XX,10.31.X.XX
As shown above, we will add IP addresses separated by commas, so
first we need to obtain the IP addresses of the remote servers all at once.
To do this, we used the CloudStack API.
CloudStackAPI is written in Python, so it can be installed relatively easily using pip.
The installation method is described on the official IDCF page, so please refer to that.
Getting Started | IDCF Documentation
The API reference is also summarized on the official page, so let's take a look at it
API References | IDCF Documentation
Let's get started.
Here is the command to get all the IP addresses of remote servers at once:
cloudstack-api listVirtualMachines --name "jmeter-node" --state "Running" | jq -r '.listvirtualmachinesresponse.virtualmachine[].nic[].ipaddress' | tr "\n" "," | sed -e "s/,$//g"
Here's a breakdown of what this command does:
①Get a list of virtual server information using CloudStack API
② Use the jq command to format the json data
③ Use the tr command to format the formatted JSON data into a "," separated format
①Get a list of virtual server information using CloudStack API
cloudstack-api listVirtualMachines --name "jmeter-node" --state "Running"
This part
This time, we used "listVirtualMachines" from the many methods of "CloudStackAPI".
As the name suggests, this method retrieves a list of virtual server information.
The execution result of this method is returned in JSON format as shown below.
$ cloudstack-api listVirtualMachines { "listvirtualmachinesresponse": { "count": 1, "virtualmachine": [ { "nic": [ { "ipaddress": "XXX.XXX.XXX.XXX" } ] } ] } }
*Many items other than "ipaddress" will be returned as a response, but
we have only excerpted the parts necessary for this article.
All we need to do is extract the value of the "ipaddress" item from this JSON data!
When actually executing the command, use "--name" to narrow it down to only the node servers,
and then use "--state" to narrow down to only those virtual servers whose status is Running.
This means that we are "excluding stopped nodes and extracting only information about running nodes."
② Use the jq command to format the json data
jq -r '.listvirtualmachinesresponse.virtualmachine[].nic[].ipaddress'
This part
The CloudStack API response is returned as JSON data, so
you need to format the JSON data so that you can extract only the data you want.
In this case, it's the "ipaddress" item.
You tell the jq command the data to extract from the JSON in a hierarchical structure.
③ Use the tr command to format the formatted JSON data into a "," separated format
tr "\n" "," | sed -e "s/,$//g"
This part
When you format the json data in ②, it will be in the following format
10.31.X.XX 10.31.X.XX 10.31.X.XX
...It's been carefully broken down into lines.
As it is, it cannot be embedded in the jmeter configuration file, so
you need to convert the line break code to ",".
Also, when you convert it, an extra "," is added to the end, so
delete that part with the sed command.
And then..
10.31.X.XX,10.31.X.XX,10.31.X.XX
Great, now you can embed it in the configuration file as it is. All you have to do
is edit the configuration file before starting jmeter.
Let's create a startup script.
$ vi start-controller.sh #!/bin/sh NODE=$(cloudstack-api listVirtualMachines --name "jmeter-node" --state "Running" | jq -r '.listvirtualmachinesresponse.virtualmachine[].nic[].ipaddress' | tr "\n" "," | sed -e "s/,$//g") sed -i -e "s/^remote_hosts=.*/remote_hosts=${NODE}/" /usr/local/jmeter/bin/jmeter.properties /usr/local/jmeter/bin/jmeter & $ ./start-controller.sh
Yes, now when you start Jmeter, the node will be automatically recognized.
That's all, thank you.
0