jmeter-prometheus-plugin icon indicating copy to clipboard operation
jmeter-prometheus-plugin copied to clipboard

Collect thread group as a label

Open johrstrom opened this issue 5 years ago • 7 comments

Currently we only collect threads with the state label. This ticket is to add the group label to indicate what thread group a given thread is in.

johrstrom avatar Oct 02 '19 13:10 johrstrom

Hey sorry to get back to you so late @antplant, in the interum while I get to this, here's how you can implement this with a JSR223 Sampler and the Prometheus config element. Once this does get implemented, it will require a Prometheus Listener in every thread group so that the listener can get the thread group information from the context (that first group = line there), so that'll be kinda weird and have to be specified for this to work as expected.

Then here, in a given thread, you could find the group name, and how

Given a gauge named enhanced_jmeter_threads with labels state,group_name you could do this.

import io.prometheus.client.*;

group = ctx.getThreadGroup();

Gauge guage = (Gauge) vars.getObject("enhanced_jmeter_threads");

int total = group.getNumThreads();
int active = group.getNumberOfThreads();
int notFinished = group.numberOfActiveThreads();
int finished = total - notFinished;

String name = group.getName();

guage.labels("total", name).set(total);
guage.labels("active", name).set(active);
guage.labels("finished", name).set(finished);

johrstrom avatar Nov 13 '19 02:11 johrstrom

that's a nice workaround. but not good enough :) it creates another sampler metrics. and you need to remember to have it on every thread group.

this should probably be part of the plugin itself.

looking at the plugin code, it looks like the change should be in ThreadCollector , first in getConfig() to add the 'groupName' label. and then somehow in method collect() need to get access to all the groups and their thread count.

as this is my first jmeter plugin coding, can you guide me how to get that information? the JMeterContextService doesn't seems to have reference to all groups.

thanks.

yarix avatar Jan 13 '22 22:01 yarix

another interesting information would be to get the real thread state i.e. BLOCKED, RUNNABLE, TIMED_WAITING, WAITING. this information is available on jvm_threads_state metric, but again without the group name...

yarix avatar Jan 13 '22 22:01 yarix

Yea coming back to it after so long I don't really know off hand. This plugin isn't under active development anymore, so i'm not sure when or if it'll ever get implemented.

johrstrom avatar Jan 14 '22 02:01 johrstrom

This plugin isn't under active development anymore, so i'm not sure when or if it'll ever get implemented.

Oh, so sad to hear 😭😭😭.

The enhancement suggestion seems to be a really good one to me.

AntonioSun avatar Jul 12 '22 21:07 AntonioSun

Pull requests welcome! Does this not work for you?

https://github.com/johrstrom/jmeter-prometheus-plugin/issues/66#issuecomment-553206254

johrstrom avatar Jul 13 '22 00:07 johrstrom

Does this not work for you?

I'd more agree with @yarix :

that's a nice workaround. but not good enough :) it creates another sampler metrics. and you need to remember to have it on every thread group.

this should probably be part of the plugin itself.

AntonioSun avatar Jul 13 '22 02:07 AntonioSun