Search in sources :

Example 6 with JmxReporter

use of com.codahale.metrics.jmx.JmxReporter in project wikidata-query-rdf by wikimedia.

the class StreamingUpdate method main.

public static void main(String[] args) {
    log.info("Starting StreamingUpdater");
    StreamingUpdateOptions options = OptionsUtils.handleOptions(StreamingUpdateOptions.class, args);
    MetricRegistry metrics = new MetricRegistry();
    JmxReporter reporter = JmxReporter.forRegistry(metrics).inDomain(options.metricDomain()).build();
    StreamingUpdaterConsumer updater = build(options, metrics);
    Thread streamingUpdaterThread = Thread.currentThread();
    streamingUpdaterThread.setUncaughtExceptionHandler((t, e) -> log.error("Uncaught exception in the updater thread: ", e));
    addShutdownHook(updater, streamingUpdaterThread, reporter);
    reporter.start();
    updater.run();
}
Also used : StreamingUpdateOptions(org.wikidata.query.rdf.updater.consumer.options.StreamingUpdateOptions) MetricRegistry(com.codahale.metrics.MetricRegistry) JmxReporter(com.codahale.metrics.jmx.JmxReporter)

Example 7 with JmxReporter

use of com.codahale.metrics.jmx.JmxReporter in project wikidata-query-rdf by wikimedia.

the class WikibaseContextListener method createMetricRegistry.

private MetricRegistry createMetricRegistry() {
    MetricRegistry registry = new MetricRegistry();
    JmxReporter jmxReporter = JmxReporter.forRegistry(registry).inDomain(METRICS_DOMAIN).build();
    jmxReporter.start();
    shutdownHooks.add(jmxReporter::stop);
    return registry;
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) JmxReporter(com.codahale.metrics.jmx.JmxReporter)

Example 8 with JmxReporter

use of com.codahale.metrics.jmx.JmxReporter in project ambry by linkedin.

the class VcrServerTest method testVCRServerWithReporterFactory.

/**
 * Bring up the VCR server and then shut it down with {@link StaticVcrClusterParticipant} and a custom {@link JmxReporter}
 * factory.
 * @throws Exception
 */
@Test
public void testVCRServerWithReporterFactory() throws Exception {
    VerifiableProperties verifiableProperties = getStaticClusterVcrProps();
    ObjectNameFactory spyObjectNameFactory = spy(new DefaultObjectNameFactory());
    Function<MetricRegistry, JmxReporter> reporterFactory = reporter -> JmxReporter.forRegistry(reporter).createsObjectNamesWith(spyObjectNameFactory).build();
    VcrServer vcrServer = new VcrServer(verifiableProperties, mockClusterAgentsFactory, notificationSystem, reporterFactory);
    vcrServer.startup();
    // check that the custom ObjectNameFactory specified in reporterFactory was used.
    verify(spyObjectNameFactory, atLeastOnce()).createName(anyString(), anyString(), anyString());
    vcrServer.shutdown();
}
Also used : DefaultObjectNameFactory(com.codahale.metrics.jmx.DefaultObjectNameFactory) AfterClass(org.junit.AfterClass) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) SSLFactory(com.github.ambry.commons.SSLFactory) BeforeClass(org.junit.BeforeClass) VerifiableProperties(com.github.ambry.config.VerifiableProperties) TestSSLUtils(com.github.ambry.commons.TestSSLUtils) ObjectNameFactory(com.codahale.metrics.jmx.ObjectNameFactory) IOException(java.io.IOException) Test(org.junit.Test) Function(java.util.function.Function) File(java.io.File) CloudConfig(com.github.ambry.config.CloudConfig) JmxReporter(com.codahale.metrics.jmx.JmxReporter) Mockito(org.mockito.Mockito) TestUtils(com.github.ambry.utils.TestUtils) HelixControllerManager(com.github.ambry.utils.HelixControllerManager) MockClusterAgentsFactory(com.github.ambry.clustermap.MockClusterAgentsFactory) Assert(org.junit.Assert) Collections(java.util.Collections) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) NotificationSystem(com.github.ambry.notification.NotificationSystem) VerifiableProperties(com.github.ambry.config.VerifiableProperties) DefaultObjectNameFactory(com.codahale.metrics.jmx.DefaultObjectNameFactory) ObjectNameFactory(com.codahale.metrics.jmx.ObjectNameFactory) MetricRegistry(com.codahale.metrics.MetricRegistry) DefaultObjectNameFactory(com.codahale.metrics.jmx.DefaultObjectNameFactory) JmxReporter(com.codahale.metrics.jmx.JmxReporter) Test(org.junit.Test)

Example 9 with JmxReporter

use of com.codahale.metrics.jmx.JmxReporter in project ambry by linkedin.

the class RestServerTest method startShutdownTestWithReporterFactory.

/**
 * Tests {@link RestServer#start()} and {@link RestServer#shutdown()} with a custom {@link JmxReporter} factory.
 * @throws Exception
 */
@Test
public void startShutdownTestWithReporterFactory() throws Exception {
    Properties properties = new Properties();
    VerifiableProperties verifiableProperties = getVProps(properties);
    ClusterMap clusterMap = new MockClusterMap();
    NotificationSystem notificationSystem = new LoggingNotificationSystem();
    ObjectNameFactory spyObjectNameFactory = spy(new DefaultObjectNameFactory());
    Function<MetricRegistry, JmxReporter> reporterFactory = reporter -> JmxReporter.forRegistry(reporter).createsObjectNamesWith(spyObjectNameFactory).build();
    RestServer server = new RestServer(verifiableProperties, clusterMap, notificationSystem, SSL_FACTORY, Collections.emptyList(), reporterFactory);
    server.start();
    // check that the custom ObjectNameFactory specified in reporterFactory was used.
    verify(spyObjectNameFactory, atLeastOnce()).createName(anyString(), anyString(), anyString());
    server.shutdown();
    server.awaitShutdown();
}
Also used : DefaultObjectNameFactory(com.codahale.metrics.jmx.DefaultObjectNameFactory) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) SSLFactory(com.github.ambry.commons.SSLFactory) VerifiableProperties(com.github.ambry.config.VerifiableProperties) ObjectNameFactory(com.codahale.metrics.jmx.ObjectNameFactory) ClusterMap(com.github.ambry.clustermap.ClusterMap) IOException(java.io.IOException) Test(org.junit.Test) Function(java.util.function.Function) JmxReporter(com.codahale.metrics.jmx.JmxReporter) Mockito(org.mockito.Mockito) InMemoryRouterFactory(com.github.ambry.router.InMemoryRouterFactory) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) Assert(org.junit.Assert) Collections(java.util.Collections) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) NotificationSystem(com.github.ambry.notification.NotificationSystem) ClusterMap(com.github.ambry.clustermap.ClusterMap) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) VerifiableProperties(com.github.ambry.config.VerifiableProperties) DefaultObjectNameFactory(com.codahale.metrics.jmx.DefaultObjectNameFactory) ObjectNameFactory(com.codahale.metrics.jmx.ObjectNameFactory) MetricRegistry(com.codahale.metrics.MetricRegistry) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) NotificationSystem(com.github.ambry.notification.NotificationSystem) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) DefaultObjectNameFactory(com.codahale.metrics.jmx.DefaultObjectNameFactory) JmxReporter(com.codahale.metrics.jmx.JmxReporter) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Example 10 with JmxReporter

use of com.codahale.metrics.jmx.JmxReporter in project ambry by linkedin.

the class AmbryServerTest method testAmbryServerWithReporterFactory.

/**
 * Test starting and shutting down the server with a custom {@link JmxReporter} factory.
 * @throws Exception
 */
@Test
public void testAmbryServerWithReporterFactory() throws Exception {
    ClusterAgentsFactory clusterAgentsFactory = new MockClusterAgentsFactory(false, false, 1, 1, 1);
    ObjectNameFactory spyObjectNameFactory = spy(new DefaultObjectNameFactory());
    Function<MetricRegistry, JmxReporter> reporterFactory = reporter -> JmxReporter.forRegistry(reporter).createsObjectNamesWith(spyObjectNameFactory).build();
    DataNodeId dataNodeId = clusterAgentsFactory.getClusterMap().getDataNodeIds().get(0);
    Properties props = new Properties();
    props.setProperty("host.name", dataNodeId.getHostname());
    props.setProperty("port", Integer.toString(dataNodeId.getPort()));
    props.setProperty("clustermap.cluster.name", "test");
    props.setProperty("clustermap.datacenter.name", "DC1");
    props.setProperty("clustermap.host.name", dataNodeId.getHostname());
    AmbryServer ambryServer = new AmbryServer(new VerifiableProperties(props), clusterAgentsFactory, null, new LoggingNotificationSystem(), SystemTime.getInstance(), reporterFactory);
    ambryServer.startup();
    verify(spyObjectNameFactory, atLeastOnce()).createName(anyString(), anyString(), anyString());
    ambryServer.shutdown();
}
Also used : DefaultObjectNameFactory(com.codahale.metrics.jmx.DefaultObjectNameFactory) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) ClusterAgentsFactory(com.github.ambry.clustermap.ClusterAgentsFactory) VerifiableProperties(com.github.ambry.config.VerifiableProperties) DataNodeId(com.github.ambry.clustermap.DataNodeId) ObjectNameFactory(com.codahale.metrics.jmx.ObjectNameFactory) Test(org.junit.Test) Function(java.util.function.Function) JmxReporter(com.codahale.metrics.jmx.JmxReporter) Mockito(org.mockito.Mockito) SystemTime(com.github.ambry.utils.SystemTime) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) MockClusterAgentsFactory(com.github.ambry.clustermap.MockClusterAgentsFactory) VerifiableProperties(com.github.ambry.config.VerifiableProperties) DefaultObjectNameFactory(com.codahale.metrics.jmx.DefaultObjectNameFactory) ObjectNameFactory(com.codahale.metrics.jmx.ObjectNameFactory) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) DefaultObjectNameFactory(com.codahale.metrics.jmx.DefaultObjectNameFactory) JmxReporter(com.codahale.metrics.jmx.JmxReporter) MockClusterAgentsFactory(com.github.ambry.clustermap.MockClusterAgentsFactory) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) ClusterAgentsFactory(com.github.ambry.clustermap.ClusterAgentsFactory) MockClusterAgentsFactory(com.github.ambry.clustermap.MockClusterAgentsFactory) DataNodeId(com.github.ambry.clustermap.DataNodeId) Test(org.junit.Test)

Aggregations

JmxReporter (com.codahale.metrics.jmx.JmxReporter)13 MetricRegistry (com.codahale.metrics.MetricRegistry)9 VerifiableProperties (com.github.ambry.config.VerifiableProperties)5 ObjectNameFactory (com.codahale.metrics.jmx.ObjectNameFactory)4 DefaultObjectNameFactory (com.codahale.metrics.jmx.DefaultObjectNameFactory)3 IOException (java.io.IOException)3 Collections (java.util.Collections)3 Properties (java.util.Properties)3 Function (java.util.function.Function)3 Test (org.junit.Test)3 Mockito (org.mockito.Mockito)3 MockClusterAgentsFactory (com.github.ambry.clustermap.MockClusterAgentsFactory)2 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)2 LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)2 SSLFactory (com.github.ambry.commons.SSLFactory)2 NotificationSystem (com.github.ambry.notification.NotificationSystem)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 ObjectName (javax.management.ObjectName)2 Assert (org.junit.Assert)2 JCommander (com.beust.jcommander.JCommander)1