Search in sources :

Example 6 with ReadableMetricsRegistry

use of org.apache.samza.metrics.ReadableMetricsRegistry in project samza by apache.

the class SamzaRestService method main.

/**
 * Command line interface to run the server.
 *
 * @param args arguments supported by {@link org.apache.samza.util.CommandLine}.
 *             In particular, --config job.config.loader.properties.path and
 *             --config job.config.loader.factory are used to read the Samza REST config file.
 * @throws Exception if the server could not be successfully started.
 */
public static void main(String[] args) throws Exception {
    SamzaMonitorService monitorService = null;
    try {
        SamzaRestConfig config = parseConfig(args);
        ReadableMetricsRegistry metricsRegistry = new MetricsRegistryMap();
        log.info("Creating new SamzaRestService with config: {}", config);
        MetricsConfig metricsConfig = new MetricsConfig(config);
        Map<String, MetricsReporter> metricsReporters = MetricsReporterLoader.getMetricsReporters(metricsConfig, Util.getLocalHost().getHostName());
        SamzaRestService restService = new SamzaRestService(new Server(config.getPort()), metricsRegistry, metricsReporters, new ServletContextHandler(ServletContextHandler.SESSIONS));
        // Add applications
        SamzaRestApplication samzaRestApplication = new SamzaRestApplication(config);
        ServletContainer container = new ServletContainer(samzaRestApplication);
        restService.addServlet(container, "/*");
        monitorService = new SamzaMonitorService(config, metricsRegistry);
        monitorService.start();
        restService.runBlocking();
    } catch (Throwable t) {
        log.error("Exception in main.", t);
    } finally {
        if (monitorService != null) {
            monitorService.stop();
        }
    }
}
Also used : ReadableMetricsRegistry(org.apache.samza.metrics.ReadableMetricsRegistry) Server(org.eclipse.jetty.server.Server) MetricsConfig(org.apache.samza.config.MetricsConfig) MetricsReporter(org.apache.samza.metrics.MetricsReporter) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) SamzaMonitorService(org.apache.samza.monitor.SamzaMonitorService)

Example 7 with ReadableMetricsRegistry

use of org.apache.samza.metrics.ReadableMetricsRegistry in project samza by apache.

the class TestLoggingMetricsReporter method testMultipleRegister.

@Test
public void testMultipleRegister() {
    when(this.readableMetricsRegistry.getGroups()).thenReturn(Collections.singleton(GROUP_NAME));
    when(this.readableMetricsRegistry.getGroup(GROUP_NAME)).thenReturn(ImmutableMap.of(COUNTER_NAME, this.counter));
    ReadableMetricsRegistry otherRegistry = mock(ReadableMetricsRegistry.class);
    String otherGroupName = "other_group";
    when(otherRegistry.getGroups()).thenReturn(Collections.singleton(otherGroupName));
    when(otherRegistry.getGroup(otherGroupName)).thenReturn(ImmutableMap.of(GAUGE_NAME, this.gauge));
    this.loggingMetricsReporter.register(SOURCE_NAME, this.readableMetricsRegistry);
    this.loggingMetricsReporter.register("other_source", otherRegistry);
    this.loggingMetricsReporter.start();
    verify(this.loggingMetricsReporter).doLog("Metric: source_name-group_name-counter_name, Value: 10");
    verify(this.loggingMetricsReporter).doLog("Metric: other_source-other_group-gauge_name, Value: 20.0");
}
Also used : ReadableMetricsRegistry(org.apache.samza.metrics.ReadableMetricsRegistry) Test(org.junit.Test)

Aggregations

ReadableMetricsRegistry (org.apache.samza.metrics.ReadableMetricsRegistry)7 Test (org.junit.Test)4 Counter (org.apache.samza.metrics.Counter)3 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)3 Timer (org.apache.samza.metrics.Timer)3 HashMap (java.util.HashMap)2 MessageCollector (org.apache.samza.task.MessageCollector)2 TaskCoordinator (org.apache.samza.task.TaskCoordinator)2 Matchers.anyObject (org.mockito.Matchers.anyObject)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Map (java.util.Map)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 SamzaException (org.apache.samza.SamzaException)1 MetricsConfig (org.apache.samza.config.MetricsConfig)1 HttpServer (org.apache.samza.coordinator.server.HttpServer)1 YarnAppState (org.apache.samza.job.yarn.YarnAppState)1 YarnContainer (org.apache.samza.job.yarn.YarnContainer)1 Metric (org.apache.samza.metrics.Metric)1 MetricsRegistryWithSource (org.apache.samza.metrics.MetricsRegistryWithSource)1 MetricsReporter (org.apache.samza.metrics.MetricsReporter)1