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();
}
}
}
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");
}
Aggregations