org.apache.flink.metrics.MetricConfig Java Examples

The following examples show how to use org.apache.flink.metrics.MetricConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrometheusPushGatewayReporter.java    From Flink-CEPplus with Apache License 2.0 7 votes vote down vote up
@Override
public void open(MetricConfig config) {
	super.open(config);

	String host = config.getString(HOST.key(), HOST.defaultValue());
	int port = config.getInteger(PORT.key(), PORT.defaultValue());
	String configuredJobName = config.getString(JOB_NAME.key(), JOB_NAME.defaultValue());
	boolean randomSuffix = config.getBoolean(RANDOM_JOB_NAME_SUFFIX.key(), RANDOM_JOB_NAME_SUFFIX.defaultValue());
	deleteOnShutdown = config.getBoolean(DELETE_ON_SHUTDOWN.key(), DELETE_ON_SHUTDOWN.defaultValue());

	if (host == null || host.isEmpty() || port < 1) {
		throw new IllegalArgumentException("Invalid host/port configuration. Host: " + host + " Port: " + port);
	}

	if (randomSuffix) {
		this.jobName = configuredJobName + new AbstractID();
	} else {
		this.jobName = configuredJobName;
	}

	pushGateway = new PushGateway(host + ':' + port);
	log.info("Configured PrometheusPushGatewayReporter with {host:{}, port:{}, jobName: {}, randomJobNameSuffix:{}, deleteOnShutdown:{}}", host, port, jobName, randomSuffix, deleteOnShutdown);
}
 
Example #2
Source File: ReporterSetup.java    From flink with Apache License 2.0 6 votes vote down vote up
private static Optional<MetricReporter> loadViaFactory(
		final String factoryClassName,
		final String reporterName,
		final Configuration reporterConfig,
		final Map<String, MetricReporterFactory> reporterFactories) {

	MetricReporterFactory factory = reporterFactories.get(factoryClassName);

	if (factory == null) {
		LOG.warn("The reporter factory ({}) could not be found for reporter {}. Available factories: ", factoryClassName, reporterName, reporterFactories.keySet());
		return Optional.empty();
	} else {
		final MetricConfig metricConfig = new MetricConfig();
		reporterConfig.addAllToProperties(metricConfig);

		return Optional.of(factory.createMetricReporter(metricConfig));
	}
}
 
Example #3
Source File: PrometheusReporter.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void open(MetricConfig config) {
	super.open(config);

	String portsConfig = config.getString(ARG_PORT, DEFAULT_PORT);
	Iterator<Integer> ports = NetUtils.getPortRangeFromString(portsConfig);

	while (ports.hasNext()) {
		int port = ports.next();
		try {
			// internally accesses CollectorRegistry.defaultRegistry
			httpServer = new HTTPServer(port);
			this.port = port;
			log.info("Started PrometheusReporter HTTP server on port {}.", port);
			break;
		} catch (IOException ioe) { //assume port conflict
			log.debug("Could not start PrometheusReporter HTTP server on port {}.", port, ioe);
		}
	}
	if (httpServer == null) {
		throw new RuntimeException("Could not start PrometheusReporter HTTP server on any configured port. Ports: " + portsConfig);
	}
}
 
Example #4
Source File: StatsDReporter.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void open(MetricConfig config) {
	String host = config.getString(ARG_HOST, null);
	int port = config.getInteger(ARG_PORT, -1);

	if (host == null || host.length() == 0 || port < 1) {
		throw new IllegalArgumentException("Invalid host/port configuration. Host: " + host + " Port: " + port);
	}

	this.address = new InetSocketAddress(host, port);

	try {
		this.socket = new DatagramSocket(0);
	} catch (SocketException e) {
		throw new RuntimeException("Could not create datagram socket. ", e);
	}
	log.info("Configured StatsDReporter with {host:{}, port:{}}", host, port);
}
 
Example #5
Source File: FileReporter.java    From beam with Apache License 2.0 6 votes vote down vote up
@Override
public void open(MetricConfig config) {
  synchronized (this) {
    if (path == null) {
      path = config.getString("path", null);
      log.info("Opening file: {}", path);
      if (path == null) {
        throw new IllegalStateException("FileReporter metrics config needs 'path' key");
      }
      try {
        FileOutputStream fos = new FileOutputStream(path);
        ps = new PrintStream(fos);
      } catch (FileNotFoundException e) {
        throw new IllegalStateException("FileReporter couldn't open file", e);
      }
    }
  }
}
 
Example #6
Source File: DatadogHttpReporter.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void open(MetricConfig config) {
	String apiKey = config.getString(API_KEY, null);
	String proxyHost = config.getString(PROXY_HOST, null);
	Integer proxyPort = config.getInteger(PROXY_PORT, 8080);
	String rawDataCenter = config.getString(DATA_CENTER, "US");
	maxMetricsPerRequestValue = config.getInteger(MAX_METRICS_PER_REQUEST, 2000);
	DataCenter dataCenter = DataCenter.valueOf(rawDataCenter);
	String tags = config.getString(TAGS, "");

	client = new DatadogHttpClient(apiKey, proxyHost, proxyPort, dataCenter, true);

	configTags = getTagsFromConfig(tags);

	LOGGER.info("Configured DatadogHttpReporter with {tags={}, proxyHost={}, proxyPort={}, dataCenter={}, maxMetricsPerRequest={}", tags, proxyHost, proxyPort, dataCenter, maxMetricsPerRequestValue);
}
 
Example #7
Source File: InfluxdbReporter.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void open(MetricConfig config) {
	String host = getString(config, HOST);
	int port = getInteger(config, PORT);
	if (!isValidHost(host) || !isValidPort(port)) {
		throw new IllegalArgumentException("Invalid host/port configuration. Host: " + host + " Port: " + port);
	}
	String database = getString(config, DB);
	if (database == null) {
		throw new IllegalArgumentException("'" + DB.key() + "' configuration option is not set");
	}
	String url = String.format("http://%s:%d", host, port);
	String username = getString(config, USERNAME);
	String password = getString(config, PASSWORD);

	this.database = database;
	this.retentionPolicy = getString(config, RETENTION_POLICY);
	if (username != null && password != null) {
		influxDB = InfluxDBFactory.connect(url, username, password);
	} else {
		influxDB = InfluxDBFactory.connect(url);
	}

	log.info("Configured InfluxDBReporter with {host:{}, port:{}, db:{}, and retentionPolicy:{}}", host, port, database, retentionPolicy);
}
 
Example #8
Source File: PrometheusReporter.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void open(MetricConfig config) {
	super.open(config);

	String portsConfig = config.getString(ARG_PORT, DEFAULT_PORT);
	Iterator<Integer> ports = NetUtils.getPortRangeFromString(portsConfig);

	while (ports.hasNext()) {
		int port = ports.next();
		try {
			// internally accesses CollectorRegistry.defaultRegistry
			httpServer = new HTTPServer(port);
			this.port = port;
			log.info("Started PrometheusReporter HTTP server on port {}.", port);
			break;
		} catch (IOException ioe) { //assume port conflict
			log.debug("Could not start PrometheusReporter HTTP server on port {}.", port, ioe);
		}
	}
	if (httpServer == null) {
		throw new RuntimeException("Could not start PrometheusReporter HTTP server on any configured port. Ports: " + portsConfig);
	}
}
 
Example #9
Source File: PrometheusPushGatewayReporter.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void open(MetricConfig config) {
	super.open(config);

	String host = config.getString(HOST.key(), HOST.defaultValue());
	int port = config.getInteger(PORT.key(), PORT.defaultValue());
	String configuredJobName = config.getString(JOB_NAME.key(), JOB_NAME.defaultValue());
	boolean randomSuffix = config.getBoolean(RANDOM_JOB_NAME_SUFFIX.key(), RANDOM_JOB_NAME_SUFFIX.defaultValue());
	deleteOnShutdown = config.getBoolean(DELETE_ON_SHUTDOWN.key(), DELETE_ON_SHUTDOWN.defaultValue());
	groupingKey = parseGroupingKey(config.getString(GROUPING_KEY.key(), GROUPING_KEY.defaultValue()));

	if (host == null || host.isEmpty() || port < 1) {
		throw new IllegalArgumentException("Invalid host/port configuration. Host: " + host + " Port: " + port);
	}

	if (randomSuffix) {
		this.jobName = configuredJobName + new AbstractID();
	} else {
		this.jobName = configuredJobName;
	}

	pushGateway = new PushGateway(host + ':' + port);
	log.info("Configured PrometheusPushGatewayReporter with {host:{}, port:{}, jobName:{}, randomJobNameSuffix:{}, deleteOnShutdown:{}, groupingKey:{}}",
		host, port, jobName, randomSuffix, deleteOnShutdown, groupingKey);
}
 
Example #10
Source File: StatsDReporter.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void open(MetricConfig config) {
	String host = config.getString(ARG_HOST, null);
	int port = config.getInteger(ARG_PORT, -1);

	if (host == null || host.length() == 0 || port < 1) {
		throw new IllegalArgumentException("Invalid host/port configuration. Host: " + host + " Port: " + port);
	}

	this.address = new InetSocketAddress(host, port);

	try {
		this.socket = new DatagramSocket(0);
	} catch (SocketException e) {
		throw new RuntimeException("Could not create datagram socket. ", e);
	}
	log.info("Configured StatsDReporter with {host:{}, port:{}}", host, port);
}
 
Example #11
Source File: PrometheusReporter.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void open(MetricConfig config) {
	super.open(config);

	String portsConfig = config.getString(ARG_PORT, DEFAULT_PORT);
	Iterator<Integer> ports = NetUtils.getPortRangeFromString(portsConfig);

	while (ports.hasNext()) {
		int port = ports.next();
		try {
			// internally accesses CollectorRegistry.defaultRegistry
			httpServer = new HTTPServer(port);
			this.port = port;
			log.info("Started PrometheusReporter HTTP server on port {}.", port);
			break;
		} catch (IOException ioe) { //assume port conflict
			log.debug("Could not start PrometheusReporter HTTP server on port {}.", port, ioe);
		}
	}
	if (httpServer == null) {
		throw new RuntimeException("Could not start PrometheusReporter HTTP server on any configured port. Ports: " + portsConfig);
	}
}
 
Example #12
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testReporterIntervalParsingErrorFallsBackToDefaultValue() throws Exception {
	MetricConfig config = new MetricConfig();
	// in a prior implementation the time amount was applied even if the time unit was invalid
	// in this case this would imply using 1 SECOND as the interval (seconds is the default)
	config.setProperty(ConfigConstants.METRICS_REPORTER_INTERVAL_SUFFIX, "1 UNICORN");

	final ManuallyTriggeredScheduledExecutorService manuallyTriggeredScheduledExecutorService = new ManuallyTriggeredScheduledExecutorService();

	MetricRegistryImpl registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Collections.singletonList(ReporterSetup.forReporter("test", config, new TestReporter3())),
		manuallyTriggeredScheduledExecutorService);
	try {
		Collection<ScheduledFuture<?>> scheduledTasks = manuallyTriggeredScheduledExecutorService.getScheduledTasks();
		ScheduledFuture<?> reportTask = Iterators.getOnlyElement(scheduledTasks.iterator());
		Assert.assertEquals(MetricOptions.REPORTER_INTERVAL.defaultValue().getSeconds(), reportTask.getDelay(TimeUnit.SECONDS));
	} finally {
		registry.shutdown().get();
	}
}
 
Example #13
Source File: ScheduledDropwizardReporterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidCharacterReplacement() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
	ScheduledDropwizardReporter reporter = new ScheduledDropwizardReporter() {
		@Override
		public ScheduledReporter getReporter(MetricConfig config) {
			return null;
		}
	};

	assertEquals("abc", reporter.filterCharacters("abc"));
	assertEquals("a--b-c-", reporter.filterCharacters("a..b.c."));
	assertEquals("ab-c", reporter.filterCharacters("a\"b.c"));
}
 
Example #14
Source File: InfluxdbReporterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private MetricRegistryImpl createMetricRegistry(String retentionPolicy) {
	MetricConfig metricConfig = new MetricConfig();
	metricConfig.setProperty(InfluxdbReporterOptions.HOST.key(), "localhost");
	metricConfig.setProperty(InfluxdbReporterOptions.PORT.key(), String.valueOf(wireMockRule.port()));
	metricConfig.setProperty(InfluxdbReporterOptions.DB.key(), TEST_INFLUXDB_DB);
	metricConfig.setProperty(InfluxdbReporterOptions.RETENTION_POLICY.key(), retentionPolicy);

	return new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Collections.singletonList(ReporterSetup.forReporter("test", metricConfig, new InfluxdbReporter())));
}
 
Example #15
Source File: DatadogHttpReporter.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void open(MetricConfig config) {
	client = new DatadogHttpClient(config.getString(API_KEY, null));
	LOGGER.info("Configured DatadogHttpReporter");

	configTags = getTagsFromConfig(config.getString(TAGS, ""));
}
 
Example #16
Source File: AbstractMetricGroupTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testScopeCachingForMultipleReporters() throws Exception {
	Configuration config = new Configuration();
	config.setString(MetricOptions.SCOPE_NAMING_TM, "A.B.C.D");

	MetricConfig metricConfig1 = new MetricConfig();
	metricConfig1.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");

	MetricConfig metricConfig2 = new MetricConfig();
	metricConfig2.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "!");

	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter1.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter2.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "!");

	MetricRegistryImpl testRegistry = new MetricRegistryImpl(
		MetricRegistryConfiguration.fromConfiguration(config),
		Arrays.asList(
			ReporterSetup.forReporter("test1", metricConfig1, new TestReporter1()),
			ReporterSetup.forReporter("test2", metricConfig2, new TestReporter2())));
	try {
		MetricGroup tmGroup = new TaskManagerMetricGroup(testRegistry, "host", "id");
		tmGroup.counter("1");
		assertEquals("Reporters were not properly instantiated", 2, testRegistry.getReporters().size());
		for (MetricReporter reporter : testRegistry.getReporters()) {
			ScopeCheckingTestReporter typedReporter = (ScopeCheckingTestReporter) reporter;
			if (typedReporter.failureCause != null) {
				throw typedReporter.failureCause;
			}
		}
	} finally {
		testRegistry.shutdown().get();
	}
}
 
Example #17
Source File: InfluxdbReporter.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open(MetricConfig config) {
	String host = getString(config, HOST);
	int port = getInteger(config, PORT);
	if (!isValidHost(host) || !NetUtils.isValidClientPort(port)) {
		throw new IllegalArgumentException("Invalid host/port configuration. Host: " + host + " Port: " + port);
	}
	String database = getString(config, DB);
	if (database == null) {
		throw new IllegalArgumentException("'" + DB.key() + "' configuration option is not set");
	}
	String url = String.format("http://%s:%d", host, port);
	String username = getString(config, USERNAME);
	String password = getString(config, PASSWORD);

	this.database = database;
	this.retentionPolicy = getString(config, RETENTION_POLICY);
	this.consistency = getConsistencyLevel(config, CONSISTENCY);

	int connectTimeout = getInteger(config, CONNECT_TIMEOUT);
	int writeTimeout = getInteger(config, WRITE_TIMEOUT);
	OkHttpClient.Builder client = new OkHttpClient.Builder()
		.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS)
		.writeTimeout(writeTimeout, TimeUnit.MILLISECONDS);

	if (username != null && password != null) {
		influxDB = InfluxDBFactory.connect(url, username, password, client);
	} else {
		influxDB = InfluxDBFactory.connect(url, client);
	}

	log.info("Configured InfluxDBReporter with {host:{}, port:{}, db:{}, retentionPolicy:{} and consistency:{}}",
		host, port, database, retentionPolicy, consistency.name());
}
 
Example #18
Source File: ScheduledDropwizardReporterTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidCharacterReplacement() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
	ScheduledDropwizardReporter reporter = new ScheduledDropwizardReporter() {
		@Override
		public ScheduledReporter getReporter(MetricConfig config) {
			return null;
		}
	};

	assertEquals("abc", reporter.filterCharacters("abc"));
	assertEquals("a--b-c-", reporter.filterCharacters("a..b.c."));
	assertEquals("ab-c", reporter.filterCharacters("a\"b.c"));
}
 
Example #19
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigurableDelimiterForReporters() throws Exception {
	MetricConfig config1 = new MetricConfig();
	config1.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "_");

	MetricConfig config2 = new MetricConfig();
	config2.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");

	MetricConfig config3 = new MetricConfig();
	config3.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "AA");

	MetricRegistryImpl registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Arrays.asList(
			ReporterSetup.forReporter("test1", config1, new TestReporter()),
			ReporterSetup.forReporter("test2", config2, new TestReporter()),
			ReporterSetup.forReporter("test3", config3, new TestReporter())));

	assertEquals(GLOBAL_DEFAULT_DELIMITER, registry.getDelimiter());
	assertEquals('_', registry.getDelimiter(0));
	assertEquals('-', registry.getDelimiter(1));
	assertEquals(GLOBAL_DEFAULT_DELIMITER, registry.getDelimiter(2));
	assertEquals(GLOBAL_DEFAULT_DELIMITER, registry.getDelimiter(3));
	assertEquals(GLOBAL_DEFAULT_DELIMITER, registry.getDelimiter(-1));

	registry.shutdown().get();
}
 
Example #20
Source File: AbstractPrometheusReporter.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void open(MetricConfig config) {
	boolean filterLabelValueCharacters = config.getBoolean(
		FILTER_LABEL_VALUE_CHARACTER.key(), FILTER_LABEL_VALUE_CHARACTER.defaultValue());

	if (!filterLabelValueCharacters) {
		labelValueCharactersFilter = input -> input;
	}
}
 
Example #21
Source File: AbstractMetricGroupTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testScopeCachingForMultipleReporters() throws Exception {
	Configuration config = new Configuration();
	config.setString(MetricOptions.SCOPE_NAMING_TM, "A.B.C.D");

	MetricConfig metricConfig1 = new MetricConfig();
	metricConfig1.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");

	MetricConfig metricConfig2 = new MetricConfig();
	metricConfig2.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "!");

	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter1.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test1." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, TestReporter2.class.getName());
	config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "test2." + ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "!");

	MetricRegistryImpl testRegistry = new MetricRegistryImpl(
		MetricRegistryConfiguration.fromConfiguration(config),
		Arrays.asList(
			ReporterSetup.forReporter("test1", metricConfig1, new TestReporter1()),
			ReporterSetup.forReporter("test2", metricConfig2, new TestReporter2())));
	try {
		MetricGroup tmGroup = new TaskManagerMetricGroup(testRegistry, "host", "id");
		tmGroup.counter("1");
		assertEquals("Reporters were not properly instantiated", 2, testRegistry.getReporters().size());
		for (MetricReporter reporter : testRegistry.getReporters()) {
			ScopeCheckingTestReporter typedReporter = (ScopeCheckingTestReporter) reporter;
			if (typedReporter.failureCause != null) {
				throw typedReporter.failureCause;
			}
		}
	} finally {
		testRegistry.shutdown().get();
	}
}
 
Example #22
Source File: ScheduledDropwizardReporterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidCharacterReplacement() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
	ScheduledDropwizardReporter reporter = new ScheduledDropwizardReporter() {
		@Override
		public ScheduledReporter getReporter(MetricConfig config) {
			return null;
		}
	};

	assertEquals("abc", reporter.filterCharacters("abc"));
	assertEquals("a--b-c-", reporter.filterCharacters("a..b.c."));
	assertEquals("ab-c", reporter.filterCharacters("a\"b.c"));
}
 
Example #23
Source File: DropwizardFlinkHistogramWrapperTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public ScheduledReporter getReporter(MetricConfig config) {
	scheduledReporter = new TestingScheduledReporter(
		registry,
		getClass().getName(),
		null,
		TimeUnit.MILLISECONDS,
		TimeUnit.MILLISECONDS);

	return scheduledReporter;
}
 
Example #24
Source File: MetricRegistryImplTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigurableDelimiterForReporters() throws Exception {
	MetricConfig config1 = new MetricConfig();
	config1.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "_");

	MetricConfig config2 = new MetricConfig();
	config2.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "-");

	MetricConfig config3 = new MetricConfig();
	config3.setProperty(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, "AA");

	MetricRegistryImpl registry = new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Arrays.asList(
			ReporterSetup.forReporter("test1", config1, new TestReporter()),
			ReporterSetup.forReporter("test2", config2, new TestReporter()),
			ReporterSetup.forReporter("test3", config3, new TestReporter())));

	assertEquals(GLOBAL_DEFAULT_DELIMITER, registry.getDelimiter());
	assertEquals('_', registry.getDelimiter(0));
	assertEquals('-', registry.getDelimiter(1));
	assertEquals(GLOBAL_DEFAULT_DELIMITER, registry.getDelimiter(2));
	assertEquals(GLOBAL_DEFAULT_DELIMITER, registry.getDelimiter(3));
	assertEquals(GLOBAL_DEFAULT_DELIMITER, registry.getDelimiter(-1));

	registry.shutdown().get();
}
 
Example #25
Source File: InfluxdbReporterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private MetricRegistryImpl createMetricRegistry(String retentionPolicy, InfluxDB.ConsistencyLevel consistencyLevel) {
	MetricConfig metricConfig = new MetricConfig();
	metricConfig.setProperty(InfluxdbReporterOptions.HOST.key(), "localhost");
	metricConfig.setProperty(InfluxdbReporterOptions.PORT.key(), String.valueOf(wireMockRule.port()));
	metricConfig.setProperty(InfluxdbReporterOptions.DB.key(), TEST_INFLUXDB_DB);
	metricConfig.setProperty(InfluxdbReporterOptions.RETENTION_POLICY.key(), retentionPolicy);
	metricConfig.setProperty(InfluxdbReporterOptions.CONSISTENCY.key(), consistencyLevel.name());

	return new MetricRegistryImpl(
		MetricRegistryConfiguration.defaultMetricRegistryConfiguration(),
		Collections.singletonList(ReporterSetup.forReporter("test", metricConfig, new InfluxdbReporter())));
}
 
Example #26
Source File: ScheduledDropwizardReporter.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void open(MetricConfig config) {
	this.reporter = getReporter(config);
}
 
Example #27
Source File: ReporterSetupTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void open(MetricConfig config) {
	wasOpened = true;
}
 
Example #28
Source File: ReporterSetup.java    From flink with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
MetricConfig getConfiguration() {
	return configuration;
}
 
Example #29
Source File: ReporterSetup.java    From flink with Apache License 2.0 4 votes vote down vote up
public ReporterSetup(final String name, final MetricConfig configuration, MetricReporter reporter) {
	this.name = name;
	this.configuration = configuration;
	this.reporter = reporter;
}
 
Example #30
Source File: Slf4jReporter.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void open(MetricConfig metricConfig) {
}