use of org.apache.flink.metrics.MetricConfig in project flink by apache.
the class ReporterSetup method setupReporters.
private static List<ReporterSetup> setupReporters(Map<String, MetricReporterFactory> reporterFactories, List<Tuple2<String, Configuration>> reporterConfigurations) {
List<ReporterSetup> reporterSetups = new ArrayList<>(reporterConfigurations.size());
for (Tuple2<String, Configuration> reporterConfiguration : reporterConfigurations) {
String reporterName = reporterConfiguration.f0;
Configuration reporterConfig = reporterConfiguration.f1;
try {
Optional<MetricReporter> metricReporterOptional = loadReporter(reporterName, reporterConfig, reporterFactories);
// massage user variables keys into scope format for parity to variable exclusion
Map<String, String> additionalVariables = reporterConfig.get(ADDITIONAL_VARIABLES).entrySet().stream().collect(Collectors.toMap(e -> ScopeFormat.asVariable(e.getKey()), Entry::getValue));
metricReporterOptional.ifPresent(reporter -> {
MetricConfig metricConfig = new MetricConfig();
reporterConfig.addAllToProperties(metricConfig);
reporterSetups.add(createReporterSetup(reporterName, metricConfig, reporter, additionalVariables));
});
} catch (Throwable t) {
LOG.error("Could not instantiate metrics reporter {}. Metrics might not be exposed/reported.", reporterName, t);
}
}
return reporterSetups;
}
use of org.apache.flink.metrics.MetricConfig in project flink by apache.
the class ReporterSetup method loadViaFactory.
private static Optional<MetricReporter> loadViaFactory(final Configuration reporterConfig, final MetricReporterFactory factory) {
final MetricConfig metricConfig = new MetricConfig();
reporterConfig.addAllToProperties(metricConfig);
return Optional.of(factory.createMetricReporter(metricConfig));
}
use of org.apache.flink.metrics.MetricConfig in project flink by apache.
the class Slf4jReporterTest method setUp.
@BeforeAll
static void setUp() {
delimiter = '.';
metricGroup = TestMetricGroup.newBuilder().setMetricIdentifierFunction((s, characterFilter) -> SCOPE + delimiter + s).build();
reporter = new Slf4jReporter();
reporter.open(new MetricConfig());
}
use of org.apache.flink.metrics.MetricConfig in project flink by apache.
the class StatsDReporterTest method testMetricAndAssert.
private void testMetricAndAssert(Metric metric, String metricName, Set<String> expectation) throws Exception {
StatsDReporter reporter = null;
DatagramSocketReceiver receiver = null;
Thread receiverThread = null;
long timeout = 5000;
long joinTimeout = 30000;
try {
receiver = new DatagramSocketReceiver();
receiverThread = new Thread(receiver);
receiverThread.start();
int port = receiver.getPort();
MetricConfig config = new MetricConfig();
config.setProperty("host", "localhost");
config.setProperty("port", String.valueOf(port));
reporter = new StatsDReporter();
reporter.open(config);
MetricGroup metricGroup = new UnregisteredMetricsGroup();
reporter.notifyOfAddedMetric(metric, metricName, metricGroup);
reporter.report();
receiver.waitUntilNumLines(expectation.size(), timeout);
assertThat(receiver.getLines()).isEqualTo(expectation);
} finally {
if (reporter != null) {
reporter.close();
}
if (receiver != null) {
receiver.stop();
}
if (receiverThread != null) {
receiverThread.join(joinTimeout);
}
}
}
use of org.apache.flink.metrics.MetricConfig in project flink by apache.
the class PrometheusReporterFactory method createMetricReporter.
@Override
public PrometheusReporter createMetricReporter(Properties properties) {
MetricConfig metricConfig = (MetricConfig) properties;
String portsConfig = metricConfig.getString(ARG_PORT, DEFAULT_PORT);
Iterator<Integer> ports = NetUtils.getPortRangeFromString(portsConfig);
return new PrometheusReporter(ports);
}
Aggregations