ARTEMIS-4456 Register metrics plugin

This commit is contained in:
Domenico Francesco Bruscino 2023-10-03 07:00:54 +02:00 committed by Justin Bertram
parent b8bb560ff0
commit c27b7b65c7
4 changed files with 31 additions and 0 deletions

View File

@ -3367,6 +3367,10 @@ public class ActiveMQServerImpl implements ActiveMQServer {
registerBrokerPlugins(getBrokerPlugins());
}
if (configuration.getMetricsConfiguration() != null && configuration.getMetricsConfiguration().getPlugin() != null) {
configuration.getMetricsConfiguration().getPlugin().registered(this);
}
return true;
}

View File

@ -20,10 +20,19 @@ import java.io.Serializable;
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) {
}
}

View File

@ -20,6 +20,7 @@ import java.util.Map;
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;
/**
@ -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();
@ -43,7 +46,16 @@ public class SimpleMetricsPlugin implements ActiveMQMetricsPlugin {
return meterRegistry;
}
@Override
public void registered(ActiveMQServer server) {
this.server = server;
}
public Map<String, String> getOptions() {
return options;
}
public ActiveMQServer getServer() {
return server;
}
}

View File

@ -270,6 +270,12 @@ public class MetricsPluginTest extends ActiveMQTestBase {
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);
}