You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by _elgato <el...@gmail.com> on 2022/07/11 12:45:33 UTC

How to get Thread Group number

Hi everyone,

I am trying to get the Thread Group number of the thread group
executing a request so I can correlate it with a property (or maybe a
CSV line), but I am having a hard time getting the number alone.

I am able to get the full thread name (including the number) with
thread.getThreadName(), but I would need to isolate the number from
the name and I would like to skip that part if possible.

Methods that I have used:
ctx.getThreadGroup().getName() returns Thread Group
ctx.getThreadGroup().getThreadName() returns null for some reason
ctx.getThreadNum() returns 0 as it is the first thread to run inside
the Thread Group
ctx.getThread().getThreadName() returns Thread Group 1-1
ctx.getThread().getThreadNum() returns 0

Where can I find this information?

Thank you.
Regards.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: How to get Thread Group number

Posted by _elgato <el...@gmail.com>.
Thank you both forma tour responses. I will be using regex then.

On Mon, Jul 11, 2022, 15:50 Flavio Cysne <fl...@gmail.com> wrote:

> Hi, _elgato.
>
> AfaIk, there is no Thread Group number/sequence/index in JMeter's functions
> list.
>
> As explained by Dmitri, you could use a naming pattern on the Thread Group
> names and extract the group number using regular expressions.
>
> Kind regards,
> Flavio Gomes
>
> On Mon, Jul 11, 2022 at 8:46 AM _elgato <el...@gmail.com> wrote:
>
> > Hi everyone,
> >
> > I am trying to get the Thread Group number of the thread group
> > executing a request so I can correlate it with a property (or maybe a
> > CSV line), but I am having a hard time getting the number alone.
> >
> > I am able to get the full thread name (including the number) with
> > thread.getThreadName(), but I would need to isolate the number from
> > the name and I would like to skip that part if possible.
> >
> > Methods that I have used:
> > ctx.getThreadGroup().getName() returns Thread Group
> > ctx.getThreadGroup().getThreadName() returns null for some reason
> > ctx.getThreadNum() returns 0 as it is the first thread to run inside
> > the Thread Group
> > ctx.getThread().getThreadName() returns Thread Group 1-1
> > ctx.getThread().getThreadNum() returns 0
> >
> > Where can I find this information?
> >
> > Thank you.
> > Regards.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> > For additional commands, e-mail: user-help@jmeter.apache.org
> >
> >
>

Re: How to get Thread Group number

Posted by Flavio Cysne <fl...@gmail.com>.
Hi, _elgato.

AfaIk, there is no Thread Group number/sequence/index in JMeter's functions
list.

As explained by Dmitri, you could use a naming pattern on the Thread Group
names and extract the group number using regular expressions.

Kind regards,
Flavio Gomes

On Mon, Jul 11, 2022 at 8:46 AM _elgato <el...@gmail.com> wrote:

> Hi everyone,
>
> I am trying to get the Thread Group number of the thread group
> executing a request so I can correlate it with a property (or maybe a
> CSV line), but I am having a hard time getting the number alone.
>
> I am able to get the full thread name (including the number) with
> thread.getThreadName(), but I would need to isolate the number from
> the name and I would like to skip that part if possible.
>
> Methods that I have used:
> ctx.getThreadGroup().getName() returns Thread Group
> ctx.getThreadGroup().getThreadName() returns null for some reason
> ctx.getThreadNum() returns 0 as it is the first thread to run inside
> the Thread Group
> ctx.getThread().getThreadName() returns Thread Group 1-1
> ctx.getThread().getThreadNum() returns 0
>
> Where can I find this information?
>
> Thank you.
> Regards.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>
>

Re: How to get Thread Group number

Posted by Felix Schumacher <fe...@internetallee.de>.
As Groovy seems not to care that much about private/public/protected 
status of variables, you can access the private threadGroup variable of 
via the ctx variable in a JSR223 Sampler/Post-/Pre-Processor by

ctx.threadGroup.groupNumber

It's probably not a good idea to rely on this, since it it internal to 
JMeter and can be changed without notice, but the same can be said for 
the naming of the thread groups.

If you want to be really correct, it is probably better to initialize a 
property of your own on each ThreadGroup and save that into the JTL file.

But apart from this, use Dmitris answer :)

Felix

Am 11.07.22 um 15:46 schrieb Dmitri T:
> I think it's possible only using regular expressions 
> <https://groovy-lang.org/operators.html#_find_operator>, there is no 
> function (at least as per JMeter 5.5 
> <https://lists.apache.org/thread/k575c2oqnr0pv52fckcg399o4nkqt8c6>) 
> which returns the number of thread group.
>
> Example code you can use:
>
> defthreadGroupName=ctx.getThreadGroup().getName()
> defthreadName=ctx.getThread().getThreadName()
>
> defthreadGroupNumber=(threadName=~/$threadGroupName\s(\d+)-/)[0][1]
>
> log.info('Thread group number: '+threadGroupNumber)
>
> More information on Groovy scripting in JMeter: Apache Groovy: What Is 
> Groovy Used For? <https://www.blazemeter.com/blog/apache-groovy>
>
> On 7/11/2022 2:45 PM, _elgato wrote:
>> Hi everyone,
>>
>> I am trying to get the Thread Group number of the thread group
>> executing a request so I can correlate it with a property (or maybe a
>> CSV line), but I am having a hard time getting the number alone.
>>
>> I am able to get the full thread name (including the number) with
>> thread.getThreadName(), but I would need to isolate the number from
>> the name and I would like to skip that part if possible.
>>
>> Methods that I have used:
>> ctx.getThreadGroup().getName() returns Thread Group
>> ctx.getThreadGroup().getThreadName() returns null for some reason
>> ctx.getThreadNum() returns 0 as it is the first thread to run inside
>> the Thread Group
>> ctx.getThread().getThreadName() returns Thread Group 1-1
>> ctx.getThread().getThreadNum() returns 0
>>
>> Where can I find this information?
>>
>> Thank you.
>> Regards.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:user-unsubscribe@jmeter.apache.org
>> For additional commands, e-mail:user-help@jmeter.apache.org
>>

Re: How to get Thread Group number

Posted by Dmitri T <gl...@live.com>.
I think it's possible only using regular expressions 
<https://groovy-lang.org/operators.html#_find_operator>, there is no 
function (at least as per JMeter 5.5 
<https://lists.apache.org/thread/k575c2oqnr0pv52fckcg399o4nkqt8c6>) 
which returns the number of thread group.

Example code you can use:

defthreadGroupName=ctx.getThreadGroup().getName()
defthreadName=ctx.getThread().getThreadName()

defthreadGroupNumber=(threadName=~/$threadGroupName\s(\d+)-/)[0][1]

log.info('Thread group number: '+threadGroupNumber)

More information on Groovy scripting in JMeter: Apache Groovy: What Is 
Groovy Used For? <https://www.blazemeter.com/blog/apache-groovy>

On 7/11/2022 2:45 PM, _elgato wrote:
> Hi everyone,
>
> I am trying to get the Thread Group number of the thread group
> executing a request so I can correlate it with a property (or maybe a
> CSV line), but I am having a hard time getting the number alone.
>
> I am able to get the full thread name (including the number) with
> thread.getThreadName(), but I would need to isolate the number from
> the name and I would like to skip that part if possible.
>
> Methods that I have used:
> ctx.getThreadGroup().getName() returns Thread Group
> ctx.getThreadGroup().getThreadName() returns null for some reason
> ctx.getThreadNum() returns 0 as it is the first thread to run inside
> the Thread Group
> ctx.getThread().getThreadName() returns Thread Group 1-1
> ctx.getThread().getThreadNum() returns 0
>
> Where can I find this information?
>
> Thank you.
> Regards.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail:user-help@jmeter.apache.org
>