/** Registers all the sources configured in the metrics config. */ private void registerSources() { Properties instConfig = mMetricsConfig.getInstanceProperties(mInstance); Map<String, Properties> sourceConfigs = mMetricsConfig.subProperties(instConfig, SOURCE_REGEX); for (Map.Entry<String, Properties> entry : sourceConfigs.entrySet()) { String classPath = entry.getValue().getProperty("class"); if (classPath != null) { try { Source source = (Source) Class.forName(classPath).newInstance(); registerSource(source); } catch (Exception e) { LOG.error("Source class {} cannot be instantiated", classPath, e); } } } }
/** Registers all the sinks configured in the metrics config. */ private void registerSinks() { Properties instConfig = mMetricsConfig.getInstanceProperties(mInstance); Map<String, Properties> sinkConfigs = mMetricsConfig.subProperties(instConfig, SINK_REGEX); for (Map.Entry<String, Properties> entry : sinkConfigs.entrySet()) { String classPath = entry.getValue().getProperty("class"); if (classPath != null) { try { Sink sink = (Sink) Class.forName(classPath) .getConstructor(Properties.class, MetricRegistry.class) .newInstance(entry.getValue(), mMetricRegistry); if (entry.getKey().equals("servlet")) { mMetricsServlet = (MetricsServlet) sink; } else { mSinks.add(sink); } } catch (Exception e) { LOG.error("Sink class {} cannot be instantiated", classPath, e); } } } }