Skip to content

Commit

Permalink
ARTEMIS-4456 Register metrics plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
brusdev authored and jbertram committed Oct 12, 2023
1 parent b8bb560 commit c27b7b6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3367,6 +3367,10 @@ synchronized boolean initialisePart1(boolean scalingDown) throws Exception {
registerBrokerPlugins(getBrokerPlugins());
}

if (configuration.getMetricsConfiguration() != null && configuration.getMetricsConfiguration().getPlugin() != null) {
configuration.getMetricsConfiguration().getPlugin().registered(this);
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@
import java.util.Map;

import io.micrometer.core.instrument.MeterRegistry;
import org.apache.activemq.artemis.core.server.ActiveMQServer;

public interface ActiveMQMetricsPlugin extends Serializable {

ActiveMQMetricsPlugin init(Map<String, String> options);

MeterRegistry getRegistry();

/**
* The plugin has been registered with the server
*
* @param server The ActiveMQServer the plugin has been registered to
*/
default void registered(ActiveMQServer server) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.metrics.ActiveMQMetricsPlugin;

/**
Expand All @@ -31,6 +32,8 @@ public class SimpleMetricsPlugin implements ActiveMQMetricsPlugin {

private Map<String, String> options;

private ActiveMQServer server;

@Override
public ActiveMQMetricsPlugin init(Map<String, String> options) {
this.meterRegistry = new SimpleMeterRegistry();
Expand All @@ -43,7 +46,16 @@ public MeterRegistry getRegistry() {
return meterRegistry;
}

@Override
public void registered(ActiveMQServer server) {
this.server = server;
}

public Map<String, String> getOptions() {
return options;
}

public ActiveMQServer getServer() {
return server;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ public void testMessageCountWithPaging() throws Exception {
checkMetric(getMetrics(), "artemis.message.count", "queue", queueName, Double.valueOf(messageCount * 2));
}

@Test
public void testMetricsPluginRegistration() {
assertEquals(SimpleMetricsPlugin.class, server.getConfiguration().getMetricsConfiguration().getPlugin().getClass());
assertEquals(server, ((SimpleMetricsPlugin)server.getConfiguration().getMetricsConfiguration().getPlugin()).getServer());
}

public Map<Meter.Id, Double> getMetrics() {
return getMetrics(server);
}
Expand Down

0 comments on commit c27b7b6

Please sign in to comment.