Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Prometheus Exporter Pro 3+: add a listener metric


In this article I will show you how you can add your own metric which is counted by a listener event.

This article is based on my previous article.

The video for the article you can watch here.

You can find the final code for this article here.

In this article we will write a metric which counts the number of times a user has been set as a watcher to an issue. To count this metric we need to use the IssueWatcherAddedEvent.

You can develop your own metric based on my previous article but I created an abstract class which lets you create listener metrics much easier. This class is called AbstractListenerMetric.

Let's create our metric:

public class WatcherCounter extends AbstractListenerMetric {

    private Counter watcherMetric =
            .help("shows how many times a user has been set as a watcher to an issue")

    protected WatcherCounter(@ComponentImport EventPublisher eventPublisher) {
        super(eventPublisher, "user_watched", "shows how many times a user has been set as a watcher to an issue", true, true);

    public void onUserAssigned(IssueWatcherAddedEvent event) {

    public PrometheusMetricResult collect() {
        return new PrometheusMetricResult(this.watcherMetric.collect());

As you can see I extended this class from AbstractListenerMetric. I defined a constructor where I pass the bean of the EventPublisher class. Then I call the super constructor and that's it. The AbstractListenerClass will register the listener itself.

Then I define a method which catches the IssueWatcherAddedEvent and set a value for my metric. And then I need to add the collect method to return my metric.

After it I create a collector and register my metric in this collector:

public class ListenerMetricCollector extends PrometheusMetricCollector {

    public ListenerMetricCollector(WatcherCounter watcherCounter) {

And I register my collector in the atlassian-plugin.xml file:

<prometheusMetric key="listener-metric-sample-module" name="Sample Listener Metric Module"

That is it. Now if I add a watcher to an issue I can see my metric in Prometheus:

# HELP user_watched_total shows how many times a user has been set as a watcher to an issue
# TYPE user_watched_total counter
user_watched_total{watcher="JIRAUSER10100",} 1.0

I hope this article will be useful for you if you try to add your own metric to Prometheus Exporter Pro.



Log in or Sign up to comment

Atlassian Community Events