use of com.hazelcast.internal.metrics.MetricsPublisher in project hazelcast by hazelcast.
the class MetricsService method registerPublisher.
/**
* Register a custom {@link MetricsPublisher} implementation with a register
* function that takes {@link NodeEngine} as input letting the caller to
* optionally initialize the publisher returned from the function.
*
* @param registerFunction The function that returns with the {@link MetricsPublisher}
* instance.
*/
public void registerPublisher(Function<NodeEngine, MetricsPublisher> registerFunction) {
if (config.isEnabled()) {
MetricsPublisher publisher = registerFunction.apply(nodeEngine);
publishers.add(publisher);
scheduleMetricsCollectorIfNeeded();
} else {
logger.fine(String.format("Custom publisher is not registered with function %s as the metrics system is disabled", registerFunction));
}
}
use of com.hazelcast.internal.metrics.MetricsPublisher in project hazelcast by hazelcast.
the class MetricsServiceTest method testCustomPublisherIsNotRegisteredIfMetricsDisabled.
@Test
public void testCustomPublisherIsNotRegisteredIfMetricsDisabled() {
config.getMetricsConfig().setEnabled(false);
MetricsPublisher publisherMock = mock(MetricsPublisher.class);
MetricsService metricsService = prepareMetricsService();
metricsService.registerPublisher(nodeEngine -> publisherMock);
metricsService.collectMetrics();
verify(publisherMock, never()).publishDouble(any(), anyDouble());
verify(publisherMock, never()).publishLong(any(), anyLong());
}
use of com.hazelcast.internal.metrics.MetricsPublisher in project hazelcast by hazelcast.
the class MetricsServiceTest method testMetricsCollectedIfMetricsEnabledAndMcJmxDisabledButCustomPublisherRegistered.
@Test
public void testMetricsCollectedIfMetricsEnabledAndMcJmxDisabledButCustomPublisherRegistered() {
config.getMetricsConfig().setEnabled(true);
config.getMetricsConfig().getManagementCenterConfig().setEnabled(false);
config.getMetricsConfig().getJmxConfig().setEnabled(false);
MetricsPublisher publisherMock = mock(MetricsPublisher.class);
MetricsService metricsService = prepareMetricsService();
metricsService.registerPublisher(nodeEngine -> publisherMock);
assertTrueEventually(() -> {
verify(publisherMock, atLeastOnce()).publishDouble(any(), anyDouble());
verify(publisherMock, atLeastOnce()).publishLong(any(), anyLong());
});
}
use of com.hazelcast.internal.metrics.MetricsPublisher in project hazelcast by hazelcast.
the class MetricsServiceTest method testCustomPublisherIsRegistered.
@Test
public void testCustomPublisherIsRegistered() {
MetricsPublisher publisherMock = mock(MetricsPublisher.class);
MetricsService metricsService = prepareMetricsService();
metricsService.registerPublisher(nodeEngine -> publisherMock);
metricsService.collectMetrics();
verify(publisherMock, atLeastOnce()).publishDouble(any(), anyDouble());
verify(publisherMock, atLeastOnce()).publishLong(any(), anyLong());
}
use of com.hazelcast.internal.metrics.MetricsPublisher in project hazelcast by hazelcast.
the class TestHazelcastInstanceFactory method registerTestMetricsPublisher.
private void registerTestMetricsPublisher(HazelcastInstance hazelcastInstance) {
if (metricsRule != null && metricsRule.isEnabled()) {
MetricsService metricService = getNodeEngineImpl(hazelcastInstance).getService(MetricsService.SERVICE_NAME);
metricService.registerPublisher((FunctionEx<NodeEngine, MetricsPublisher>) nodeEngine -> metricsRule.getMetricsPublisher(hazelcastInstance));
}
}
Aggregations