Java Code Examples for org.apache.flink.metrics.MetricConfig#getString()

The following examples show how to use org.apache.flink.metrics.MetricConfig#getString() . 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: 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 3
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 4
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 5
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 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: 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 8
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 9
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 10
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());

	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 11
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 12
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 13
Source File: DatadogHttpReporter.java    From flink with Apache License 2.0 5 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);

	client = new DatadogHttpClient(apiKey, proxyHost, proxyPort);
	LOGGER.info("Configured DatadogHttpReporter");

	configTags = getTagsFromConfig(config.getString(TAGS, ""));
}
 
Example 14
Source File: JMXReporter.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void open(MetricConfig config) {
	String portsConfig = config.getString(ARG_PORT, null);

	if (portsConfig != null) {
		Iterator<Integer> ports = NetUtils.getPortRangeFromString(portsConfig);

		JMXServer server = new JMXServer();
		while (ports.hasNext()) {
			int port = ports.next();
			try {
				server.start(port);
				LOG.info("Started JMX server on port " + port + ".");
				// only set our field if the server was actually started
				jmxServer = server;
				break;
			} catch (IOException ioe) { //assume port conflict
				LOG.debug("Could not start JMX server on port " + port + ".", ioe);
				try {
					server.stop();
				} catch (Exception e) {
					LOG.debug("Could not stop JMX server.", e);
				}
			}
		}
		if (jmxServer == null) {
			throw new RuntimeException("Could not start JMX server on any configured port. Ports: " + portsConfig);
		}
	}
	LOG.info("Configured JMXReporter with {port:{}}", portsConfig);
}
 
Example 15
Source File: GraphiteReporter.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public ScheduledReporter getReporter(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);
	}

	String prefix = config.getString(ARG_PREFIX, null);
	String conversionRate = config.getString(ARG_CONVERSION_RATE, null);
	String conversionDuration = config.getString(ARG_CONVERSION_DURATION, null);
	String protocol = config.getString(ARG_PROTOCOL, "TCP");

	com.codahale.metrics.graphite.GraphiteReporter.Builder builder =
		com.codahale.metrics.graphite.GraphiteReporter.forRegistry(registry);

	if (prefix != null) {
		builder.prefixedWith(prefix);
	}

	if (conversionRate != null) {
		builder.convertRatesTo(TimeUnit.valueOf(conversionRate));
	}

	if (conversionDuration != null) {
		builder.convertDurationsTo(TimeUnit.valueOf(conversionDuration));
	}

	Protocol prot;
	try {
		prot = Protocol.valueOf(protocol);
	} catch (IllegalArgumentException iae) {
		log.warn("Invalid protocol configuration: " + protocol + " Expected: TCP or UDP, defaulting to TCP.");
		prot = Protocol.TCP;
	}

	log.info("Configured GraphiteReporter with {host:{}, port:{}, protocol:{}}", host, port, prot);
	switch(prot) {
		case UDP:
			return builder.build(new GraphiteUDP(host, port));
		case TCP:
		default:
			return builder.build(new Graphite(host, port));
	}
}
 
Example 16
Source File: InfluxdbReporterOptions.java    From flink with Apache License 2.0 4 votes vote down vote up
static String getString(MetricConfig config, ConfigOption<String> key) {
	return config.getString(key.key(), key.defaultValue());
}
 
Example 17
Source File: GraphiteReporter.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public ScheduledReporter getReporter(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);
	}

	String prefix = config.getString(ARG_PREFIX, null);
	String conversionRate = config.getString(ARG_CONVERSION_RATE, null);
	String conversionDuration = config.getString(ARG_CONVERSION_DURATION, null);
	String protocol = config.getString(ARG_PROTOCOL, "TCP");

	com.codahale.metrics.graphite.GraphiteReporter.Builder builder =
		com.codahale.metrics.graphite.GraphiteReporter.forRegistry(registry);

	if (prefix != null) {
		builder.prefixedWith(prefix);
	}

	if (conversionRate != null) {
		builder.convertRatesTo(TimeUnit.valueOf(conversionRate));
	}

	if (conversionDuration != null) {
		builder.convertDurationsTo(TimeUnit.valueOf(conversionDuration));
	}

	Protocol prot;
	try {
		prot = Protocol.valueOf(protocol);
	} catch (IllegalArgumentException iae) {
		log.warn("Invalid protocol configuration: " + protocol + " Expected: TCP or UDP, defaulting to TCP.");
		prot = Protocol.TCP;
	}

	log.info("Configured GraphiteReporter with {host:{}, port:{}, protocol:{}}", host, port, prot);
	switch(prot) {
		case UDP:
			return builder.build(new GraphiteUDP(host, port));
		case TCP:
		default:
			return builder.build(new Graphite(host, port));
	}
}
 
Example 18
Source File: InfluxdbReporterOptions.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
static String getString(MetricConfig config, ConfigOption<String> key) {
	return config.getString(key.key(), key.defaultValue());
}
 
Example 19
Source File: InfluxdbReporterOptions.java    From flink with Apache License 2.0 4 votes vote down vote up
static String getString(MetricConfig config, ConfigOption<String> key) {
	return config.getString(key.key(), key.defaultValue());
}
 
Example 20
Source File: GraphiteReporter.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public ScheduledReporter getReporter(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);
	}

	String prefix = config.getString(ARG_PREFIX, null);
	String conversionRate = config.getString(ARG_CONVERSION_RATE, null);
	String conversionDuration = config.getString(ARG_CONVERSION_DURATION, null);
	String protocol = config.getString(ARG_PROTOCOL, "TCP");

	com.codahale.metrics.graphite.GraphiteReporter.Builder builder =
		com.codahale.metrics.graphite.GraphiteReporter.forRegistry(registry);

	if (prefix != null) {
		builder.prefixedWith(prefix);
	}

	if (conversionRate != null) {
		builder.convertRatesTo(TimeUnit.valueOf(conversionRate));
	}

	if (conversionDuration != null) {
		builder.convertDurationsTo(TimeUnit.valueOf(conversionDuration));
	}

	Protocol prot;
	try {
		prot = Protocol.valueOf(protocol);
	} catch (IllegalArgumentException iae) {
		log.warn("Invalid protocol configuration: " + protocol + " Expected: TCP or UDP, defaulting to TCP.");
		prot = Protocol.TCP;
	}

	log.info("Configured GraphiteReporter with {host:{}, port:{}, protocol:{}}", host, port, prot);
	switch(prot) {
		case UDP:
			return builder.build(new GraphiteUDP(host, port));
		case TCP:
		default:
			return builder.build(new Graphite(host, port));
	}
}