k6 community forum

How to know k6 server port number

If I run multiple k6 instances like this:

#!/bin/sh 
k6 run test1_spec.js &
k6 run test2_spec.js &
k6 run test3_spec.js
k6 run test4_spec.js

And want to control number of vus using k6 status how can I do it.
if I use k6 status, it shows the status of first script.
I tried using : k6 status -a localhost:6565
It shows status of first script only. How do i know the port k6 selects for running other scripts?
ps: I cannot specify the port in kr run command.

Hi,

want to control number of vus using k6 status how can I do it.

To control the number of VUs during test execution you would use the k6 scale command, not k6 status.

See this article for details.

How do i know the port k6 selects for running other scripts?

If you don’t specify --address, k6 will try to listen on the default localhost:6565, and if that fails, e.g. because the port is already used by another process, you will see the message:

WARN[0000] Error from API server  error="listen tcp 127.0.0.1:6565: bind: address already in use"

…and that k6 instance will not be accessible via the HTTP API.

So there is no fallback mechanism for trying other ports; the server simply won’t start.

You could technically specify --address localhost:0, in which case the OS will assign the next freely available port at random and the server will start for all processes, but that would make your task of finding the assigned ports even more difficult. Plus you say that you can’t use k6 run --address, so this won’t be of any help, I suppose.

ps: I cannot specify the port in kr run command.

May I ask why? :slight_smile:

k6 run --address is the only way to control which API port is assigned, and it’s meant for use cases like yours.

Perhaps k6 could output the address it started the API server on if run with --verbose, but I don’t think that would help much in your case since there is no port fallback and you’re not able to specify -a localhost:0 beforehand.