use of org.apache.samza.metrics.MetricsReporter in project samza by apache.
the class StreamAppender method setupSystem.
/**
* This should only be called after verifying that the {@link LoggingContextHolder} has the config.
*/
protected void setupSystem() {
config = getConfig();
Log4jSystemConfig log4jSystemConfig = getLog4jSystemConfig(config);
if (streamName == null) {
streamName = getStreamName(log4jSystemConfig.getJobName(), log4jSystemConfig.getJobId());
}
// Instantiate metrics
MetricsRegistryMap metricsRegistry = new MetricsRegistryMap();
// Take this.getClass().getName() as the name to make it extend-friendly
metrics = getMetrics(metricsRegistry);
// Register metrics into metrics reporters so that they are able to be reported to other systems
Map<String, MetricsReporter> metricsReporters = MetricsReporterLoader.getMetricsReporters(new MetricsConfig(config), containerName);
metricsReporters.values().forEach(reporter -> {
reporter.register(containerName, metricsRegistry);
reporter.start();
});
String systemName = log4jSystemConfig.getSystemName();
String systemFactoryName = log4jSystemConfig.getSystemFactory(systemName).orElseThrow(() -> new SamzaException("Could not figure out \"" + systemName + "\" system factory for log4j " + getName() + " to use"));
SystemFactory systemFactory = ReflectionUtil.getObj(systemFactoryName, SystemFactory.class);
setSerde(log4jSystemConfig, systemName);
setupStream(systemFactory, systemName);
systemProducer = systemFactory.getProducer(systemName, config, metricsRegistry, this.getClass().getSimpleName());
systemStream = new SystemStream(systemName, streamName);
systemProducer.register(SOURCE);
systemProducer.start();
System.out.println(SOURCE + " has been registered in " + systemName + ". So all the logs will be sent to " + streamName + " in " + systemName + ". Logs are partitioned by " + key);
startTransferThread();
}
use of org.apache.samza.metrics.MetricsReporter 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.MetricsReporter in project beam by apache.
the class SamzaRunner method getMetricsReporters.
private Map<String, MetricsReporterFactory> getMetricsReporters() {
if (options.getMetricsReporters() != null) {
final Map<String, MetricsReporterFactory> reporters = new HashMap<>();
for (int i = 0; i < options.getMetricsReporters().size(); i++) {
final String name = "beam-metrics-reporter-" + i;
final MetricsReporter reporter = options.getMetricsReporters().get(i);
reporters.put(name, (MetricsReporterFactory) (nm, processorId, config) -> reporter);
LOG.info(name + ": " + reporter.getClass().getName());
}
return reporters;
} else {
return Collections.emptyMap();
}
}
use of org.apache.samza.metrics.MetricsReporter in project samza by apache.
the class LocalApplicationRunner method createStreamProcessor.
@VisibleForTesting
StreamProcessor createStreamProcessor(Config config, ApplicationDescriptorImpl<? extends ApplicationDescriptor> appDesc, StreamProcessor.StreamProcessorLifecycleListenerFactory listenerFactory, Optional<ExternalContext> externalContextOptional, MetadataStore coordinatorStreamStore) {
TaskFactory taskFactory = TaskFactoryUtil.getTaskFactory(appDesc);
Map<String, MetricsReporter> reporters = new HashMap<>();
String processorId = createProcessorId(new ApplicationConfig(config));
appDesc.getMetricsReporterFactories().forEach((name, factory) -> reporters.put(name, factory.getMetricsReporter(name, processorId, config)));
return new StreamProcessor(processorId, config, reporters, taskFactory, appDesc.getApplicationContainerContextFactory(), appDesc.getApplicationTaskContextFactory(), externalContextOptional, listenerFactory, null, coordinatorStreamStore);
}
Aggregations