org.apache.flink.metrics.reporter.Scheduled Java Examples

The following examples show how to use org.apache.flink.metrics.reporter.Scheduled. 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: MetricRegistryImpl.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new MetricRegistry and starts the configured reporter.
 */
public MetricRegistryImpl(MetricRegistryConfiguration config) {
	this.maximumFramesize = config.getQueryServiceMessageSizeLimit();
	this.scopeFormats = config.getScopeFormats();
	this.globalDelimiter = config.getDelimiter();
	this.delimiters = new ArrayList<>(10);
	this.terminationFuture = new CompletableFuture<>();
	this.isShutdown = false;

	// second, instantiate any custom configured reporters
	this.reporters = new ArrayList<>(4);

	List<Tuple2<String, Configuration>> reporterConfigurations = config.getReporterConfigurations();

	this.executor = Executors.newSingleThreadScheduledExecutor(new ExecutorThreadFactory("Flink-MetricRegistry"));

	this.queryService = null;
	this.metricQueryServicePath = null;

	if (reporterConfigurations.isEmpty()) {
		// no reporters defined
		// by default, don't report anything
		LOG.info("No metrics reporter configured, no metrics will be exposed/reported.");
	} else {
		// we have some reporters so
		for (Tuple2<String, Configuration> reporterConfiguration: reporterConfigurations) {
			String namedReporter = reporterConfiguration.f0;
			Configuration reporterConfig = reporterConfiguration.f1;

			final String className = reporterConfig.getString(ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, null);
			if (className == null) {
				LOG.error("No reporter class set for reporter " + namedReporter + ". Metrics might not be exposed/reported.");
				continue;
			}

			try {
				String configuredPeriod = reporterConfig.getString(ConfigConstants.METRICS_REPORTER_INTERVAL_SUFFIX, null);
				TimeUnit timeunit = TimeUnit.SECONDS;
				long period = 10;

				if (configuredPeriod != null) {
					try {
						String[] interval = configuredPeriod.split(" ");
						period = Long.parseLong(interval[0]);
						timeunit = TimeUnit.valueOf(interval[1]);
					}
					catch (Exception e) {
						LOG.error("Cannot parse report interval from config: " + configuredPeriod +
								" - please use values like '10 SECONDS' or '500 MILLISECONDS'. " +
								"Using default reporting interval.");
					}
				}

				Class<?> reporterClass = Class.forName(className);
				MetricReporter reporterInstance = (MetricReporter) reporterClass.newInstance();

				MetricConfig metricConfig = new MetricConfig();
				reporterConfig.addAllToProperties(metricConfig);
				LOG.info("Configuring {} with {}.", namedReporter, metricConfig);
				reporterInstance.open(metricConfig);

				if (reporterInstance instanceof Scheduled) {
					LOG.info("Periodically reporting metrics in intervals of {} {} for reporter {} of type {}.", period, timeunit.name(), namedReporter, className);

					executor.scheduleWithFixedDelay(
							new MetricRegistryImpl.ReporterTask((Scheduled) reporterInstance), period, period, timeunit);
				} else {
					LOG.info("Reporting metrics for reporter {} of type {}.", namedReporter, className);
				}
				reporters.add(reporterInstance);

				String delimiterForReporter = reporterConfig.getString(ConfigConstants.METRICS_REPORTER_SCOPE_DELIMITER, String.valueOf(globalDelimiter));
				if (delimiterForReporter.length() != 1) {
					LOG.warn("Failed to parse delimiter '{}' for reporter '{}', using global delimiter '{}'.", delimiterForReporter, namedReporter, globalDelimiter);
					delimiterForReporter = String.valueOf(globalDelimiter);
				}
				this.delimiters.add(delimiterForReporter.charAt(0));
			}
			catch (Throwable t) {
				LOG.error("Could not instantiate metrics reporter {}. Metrics might not be exposed/reported.", namedReporter, t);
			}
		}
	}
}
 
Example #2
Source File: MetricRegistryImpl.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private ReporterTask(Scheduled reporter) {
	this.reporter = reporter;
}
 
Example #3
Source File: MetricRegistryImpl.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new MetricRegistry and starts the configured reporter.
 */
public MetricRegistryImpl(MetricRegistryConfiguration config, Collection<ReporterSetup> reporterConfigurations) {
	this.maximumFramesize = config.getQueryServiceMessageSizeLimit();
	this.scopeFormats = config.getScopeFormats();
	this.globalDelimiter = config.getDelimiter();
	this.delimiters = new ArrayList<>(10);
	this.terminationFuture = new CompletableFuture<>();
	this.isShutdown = false;

	// second, instantiate any custom configured reporters
	this.reporters = new ArrayList<>(4);

	this.executor = Executors.newSingleThreadScheduledExecutor(new ExecutorThreadFactory("Flink-MetricRegistry"));

	this.queryService = null;
	this.metricQueryServiceRpcService = null;

	if (reporterConfigurations.isEmpty()) {
		// no reporters defined
		// by default, don't report anything
		LOG.info("No metrics reporter configured, no metrics will be exposed/reported.");
	} else {
		for (ReporterSetup reporterSetup : reporterConfigurations) {
			final String namedReporter = reporterSetup.getName();

			try {
				Optional<String> configuredPeriod = reporterSetup.getIntervalSettings();
				TimeUnit timeunit = TimeUnit.SECONDS;
				long period = 10;

				if (configuredPeriod.isPresent()) {
					try {
						String[] interval = configuredPeriod.get().split(" ");
						period = Long.parseLong(interval[0]);
						timeunit = TimeUnit.valueOf(interval[1]);
					}
					catch (Exception e) {
						LOG.error("Cannot parse report interval from config: " + configuredPeriod +
								" - please use values like '10 SECONDS' or '500 MILLISECONDS'. " +
								"Using default reporting interval.");
					}
				}

				final MetricReporter reporterInstance = reporterSetup.getReporter();
				final String className = reporterInstance.getClass().getName();

				if (reporterInstance instanceof Scheduled) {
					LOG.info("Periodically reporting metrics in intervals of {} {} for reporter {} of type {}.", period, timeunit.name(), namedReporter, className);

					executor.scheduleWithFixedDelay(
							new MetricRegistryImpl.ReporterTask((Scheduled) reporterInstance), period, period, timeunit);
				} else {
					LOG.info("Reporting metrics for reporter {} of type {}.", namedReporter, className);
				}
				reporters.add(reporterInstance);

				String delimiterForReporter = reporterSetup.getDelimiter().orElse(String.valueOf(globalDelimiter));
				if (delimiterForReporter.length() != 1) {
					LOG.warn("Failed to parse delimiter '{}' for reporter '{}', using global delimiter '{}'.", delimiterForReporter, namedReporter, globalDelimiter);
					delimiterForReporter = String.valueOf(globalDelimiter);
				}
				this.delimiters.add(delimiterForReporter.charAt(0));
			}
			catch (Throwable t) {
				LOG.error("Could not instantiate metrics reporter {}. Metrics might not be exposed/reported.", namedReporter, t);
			}
		}
	}
}
 
Example #4
Source File: MetricRegistryImpl.java    From flink with Apache License 2.0 4 votes vote down vote up
private ReporterTask(Scheduled reporter) {
	this.reporter = reporter;
}
 
Example #5
Source File: MetricRegistryImpl.java    From flink with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
MetricRegistryImpl(MetricRegistryConfiguration config, Collection<ReporterSetup> reporterConfigurations, ScheduledExecutorService scheduledExecutor) {
	this.maximumFramesize = config.getQueryServiceMessageSizeLimit();
	this.scopeFormats = config.getScopeFormats();
	this.globalDelimiter = config.getDelimiter();
	this.terminationFuture = new CompletableFuture<>();
	this.isShutdown = false;

	// second, instantiate any custom configured reporters
	this.reporters = new ArrayList<>(4);

	this.executor = scheduledExecutor;

	this.queryService = null;
	this.metricQueryServiceRpcService = null;

	if (reporterConfigurations.isEmpty()) {
		// no reporters defined
		// by default, don't report anything
		LOG.info("No metrics reporter configured, no metrics will be exposed/reported.");
	} else {
		for (ReporterSetup reporterSetup : reporterConfigurations) {
			final String namedReporter = reporterSetup.getName();

			try {
				final MetricReporter reporterInstance = reporterSetup.getReporter();
				final String className = reporterInstance.getClass().getName();

				if (reporterInstance instanceof Scheduled) {
					final Duration period = getConfiguredIntervalOrDefault(reporterSetup);

					LOG.info("Periodically reporting metrics in intervals of {} for reporter {} of type {}.", TimeUtils.formatWithHighestUnit(period), namedReporter, className);

					executor.scheduleWithFixedDelay(
							new MetricRegistryImpl.ReporterTask((Scheduled) reporterInstance), period.toMillis(), period.toMillis(), TimeUnit.MILLISECONDS);
				} else {
					LOG.info("Reporting metrics for reporter {} of type {}.", namedReporter, className);
				}

				String delimiterForReporter = reporterSetup.getDelimiter().orElse(String.valueOf(globalDelimiter));
				if (delimiterForReporter.length() != 1) {
					LOG.warn("Failed to parse delimiter '{}' for reporter '{}', using global delimiter '{}'.", delimiterForReporter, namedReporter, globalDelimiter);
					delimiterForReporter = String.valueOf(globalDelimiter);
				}

				reporters.add(new ReporterAndSettings(
					reporterInstance,
					new ReporterScopedSettings(
						reporters.size(),
						delimiterForReporter.charAt(0),
						reporterSetup.getExcludedVariables())));
			}
			catch (Throwable t) {
				LOG.error("Could not instantiate metrics reporter {}. Metrics might not be exposed/reported.", namedReporter, t);
			}
		}
	}
}
 
Example #6
Source File: MetricRegistryImpl.java    From flink with Apache License 2.0 4 votes vote down vote up
private ReporterTask(Scheduled reporter) {
	this.reporter = reporter;
}