org.apache.flink.metrics.Meter Java Examples

The following examples show how to use org.apache.flink.metrics.Meter. 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: DatadogHttpClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void serializeMeterWithoutHost() throws JsonProcessingException {

	DMeter m = new DMeter(new Meter() {
		@Override
		public void markEvent() {}

		@Override
		public void markEvent(long n) {}

		@Override
		public double getRate() {
			return 1;
		}

		@Override
		public long getCount() {
			return 0;
		}
	}, "testMeter", null, tags, () -> MOCKED_SYSTEM_MILLIS);

	assertEquals(
		"{\"metric\":\"testMeter\",\"type\":\"gauge\",\"tags\":[\"tag1\",\"tag2\"],\"points\":[[123,1.0]]}",
		DatadogHttpClient.serialize(m));
}
 
Example #2
Source File: AbstractReporter.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void notifyOfRemovedMetric(Metric metric, String metricName, MetricGroup group) {
	synchronized (this) {
		if (metric instanceof Counter) {
			counters.remove(metric);
		} else if (metric instanceof Gauge) {
			gauges.remove(metric);
		} else if (metric instanceof Histogram) {
			histograms.remove(metric);
		} else if (metric instanceof Meter) {
			meters.remove(metric);
		} else {
			log.warn("Cannot remove unknown metric type {}. This indicates that the reporter " +
				"does not support this metric type.", metric.getClass().getName());
		}
	}
}
 
Example #3
Source File: AbstractReporter.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void notifyOfAddedMetric(Metric metric, String metricName, MetricGroup group) {
	final MetricInfo metricInfo = metricInfoProvider.getMetricInfo(metricName, group);
	synchronized (this) {
		if (metric instanceof Counter) {
			counters.put((Counter) metric, metricInfo);
		} else if (metric instanceof Gauge) {
			gauges.put((Gauge<?>) metric, metricInfo);
		} else if (metric instanceof Histogram) {
			histograms.put((Histogram) metric, metricInfo);
		} else if (metric instanceof Meter) {
			meters.put((Meter) metric, metricInfo);
		} else {
			log.warn("Cannot add unknown metric type {}. This indicates that the reporter " +
				"does not support this metric type.", metric.getClass().getName());
		}
	}
}
 
Example #4
Source File: AbstractReporter.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void notifyOfRemovedMetric(Metric metric, String metricName, MetricGroup group) {
	synchronized (this) {
		if (metric instanceof Counter) {
			counters.remove(metric);
		} else if (metric instanceof Gauge) {
			gauges.remove(metric);
		} else if (metric instanceof Histogram) {
			histograms.remove(metric);
		} else if (metric instanceof Meter) {
			meters.remove(metric);
		} else {
			log.warn("Cannot remove unknown metric type {}. This indicates that the reporter " +
				"does not support this metric type.", metric.getClass().getName());
		}
	}
}
 
Example #5
Source File: ScheduledDropwizardReporter.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void notifyOfRemovedMetric(Metric metric, String metricName, MetricGroup group) {
	synchronized (this) {
		String fullName;

		if (metric instanceof Counter) {
			fullName = counters.remove(metric);
		} else if (metric instanceof Gauge) {
			fullName = gauges.remove(metric);
		} else if (metric instanceof Histogram) {
			fullName = histograms.remove(metric);
		} else if (metric instanceof Meter) {
			fullName = meters.remove(metric);
		} else {
			fullName = null;
		}

		if (fullName != null) {
			registry.remove(fullName);
		}
	}
}
 
Example #6
Source File: AbstractReporter.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void notifyOfRemovedMetric(Metric metric, String metricName, MetricGroup group) {
	synchronized (this) {
		if (metric instanceof Counter) {
			counters.remove(metric);
		} else if (metric instanceof Gauge) {
			gauges.remove(metric);
		} else if (metric instanceof Histogram) {
			histograms.remove(metric);
		} else if (metric instanceof Meter) {
			meters.remove(metric);
		} else {
			log.warn("Cannot remove unknown metric type {}. This indicates that the reporter " +
				"does not support this metric type.", metric.getClass().getName());
		}
	}
}
 
Example #7
Source File: AbstractReporter.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void notifyOfAddedMetric(Metric metric, String metricName, MetricGroup group) {
	final String name = group.getMetricIdentifier(metricName, this);

	synchronized (this) {
		if (metric instanceof Counter) {
			counters.put((Counter) metric, name);
		} else if (metric instanceof Gauge) {
			gauges.put((Gauge<?>) metric, name);
		} else if (metric instanceof Histogram) {
			histograms.put((Histogram) metric, name);
		} else if (metric instanceof Meter) {
			meters.put((Meter) metric, name);
		} else {
			log.warn("Cannot add unknown metric type {}. This indicates that the reporter " +
				"does not support this metric type.", metric.getClass().getName());
		}
	}
}
 
Example #8
Source File: AbstractReporter.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void notifyOfAddedMetric(Metric metric, String metricName, MetricGroup group) {
	final MetricInfo metricInfo = metricInfoProvider.getMetricInfo(metricName, group);
	synchronized (this) {
		if (metric instanceof Counter) {
			counters.put((Counter) metric, metricInfo);
		} else if (metric instanceof Gauge) {
			gauges.put((Gauge<?>) metric, metricInfo);
		} else if (metric instanceof Histogram) {
			histograms.put((Histogram) metric, metricInfo);
		} else if (metric instanceof Meter) {
			meters.put((Meter) metric, metricInfo);
		} else {
			log.warn("Cannot add unknown metric type {}. This indicates that the reporter " +
				"does not support this metric type.", metric.getClass().getName());
		}
	}
}
 
Example #9
Source File: AbstractReporter.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void notifyOfAddedMetric(Metric metric, String metricName, MetricGroup group) {
	final String name = group.getMetricIdentifier(metricName, this);

	synchronized (this) {
		if (metric instanceof Counter) {
			counters.put((Counter) metric, name);
		} else if (metric instanceof Gauge) {
			gauges.put((Gauge<?>) metric, name);
		} else if (metric instanceof Histogram) {
			histograms.put((Histogram) metric, name);
		} else if (metric instanceof Meter) {
			meters.put((Meter) metric, name);
		} else {
			log.warn("Cannot add unknown metric type {}. This indicates that the reporter " +
				"does not support this metric type.", metric.getClass().getName());
		}
	}
}
 
Example #10
Source File: DatadogHttpClientTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void serializeMeterWithoutHost() throws JsonProcessingException {

	DMeter m = new DMeter(new Meter() {
		@Override
		public void markEvent() {}

		@Override
		public void markEvent(long n) {}

		@Override
		public double getRate() {
			return 1;
		}

		@Override
		public long getCount() {
			return 0;
		}
	}, "testMeter", null, tags);

	assertEquals(
		"{\"metric\":\"testMeter\",\"type\":\"gauge\",\"tags\":[\"tag1\",\"tag2\"],\"points\":[[123,1.0]]}",
		DatadogHttpClient.serialize(m));
}
 
Example #11
Source File: DatadogHttpClientTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void serializeMeter() throws JsonProcessingException {

	DMeter m = new DMeter(new Meter() {
		@Override
		public void markEvent() {}

		@Override
		public void markEvent(long n) {}

		@Override
		public double getRate() {
			return 1;
		}

		@Override
		public long getCount() {
			return 0;
		}
	}, "testMeter", "localhost", tags);

	assertEquals(
		"{\"metric\":\"testMeter\",\"type\":\"gauge\",\"host\":\"localhost\",\"tags\":[\"tag1\",\"tag2\"],\"points\":[[123,1.0]]}",
		DatadogHttpClient.serialize(m));
}
 
Example #12
Source File: DatadogHttpReporter.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void notifyOfAddedMetric(Metric metric, String metricName, MetricGroup group) {
	final String name = group.getMetricIdentifier(metricName);

	List<String> tags = new ArrayList<>(configTags);
	tags.addAll(getTagsFromMetricGroup(group));
	String host = getHostFromMetricGroup(group);

	if (metric instanceof Counter) {
		Counter c = (Counter) metric;
		counters.put(c, new DCounter(c, name, host, tags, clock));
	} else if (metric instanceof Gauge) {
		Gauge g = (Gauge) metric;
		gauges.put(g, new DGauge(g, name, host, tags, clock));
	} else if (metric instanceof Meter) {
		Meter m = (Meter) metric;
		// Only consider rate
		meters.put(m, new DMeter(m, name, host, tags, clock));
	} else if (metric instanceof Histogram) {
		LOGGER.warn("Cannot add {} because Datadog HTTP API doesn't support Histogram", metricName);
	} else {
		LOGGER.warn("Cannot add unknown metric type {}. This indicates that the reporter " +
			"does not support this metric type.", metric.getClass().getName());
	}
}
 
Example #13
Source File: AbstractPrometheusReporter.java    From flink with Apache License 2.0 6 votes vote down vote up
private Collector createCollector(Metric metric, List<String> dimensionKeys, List<String> dimensionValues, String scopedMetricName, String helpString) {
	Collector collector;
	if (metric instanceof Gauge || metric instanceof Counter || metric instanceof Meter) {
		collector = io.prometheus.client.Gauge
			.build()
			.name(scopedMetricName)
			.help(helpString)
			.labelNames(toArray(dimensionKeys))
			.create();
	} else if (metric instanceof Histogram) {
		collector = new HistogramSummaryProxy((Histogram) metric, scopedMetricName, helpString, dimensionKeys, dimensionValues);
	} else {
		log.warn("Cannot create collector for unknown metric type: {}. This indicates that the metric type is not supported by this reporter.",
			metric.getClass().getName());
		collector = null;
	}
	return collector;
}
 
Example #14
Source File: AbstractPrometheusReporter.java    From flink with Apache License 2.0 6 votes vote down vote up
private Collector createCollector(Metric metric, List<String> dimensionKeys, List<String> dimensionValues, String scopedMetricName, String helpString) {
	Collector collector;
	if (metric instanceof Gauge || metric instanceof Counter || metric instanceof Meter) {
		collector = io.prometheus.client.Gauge
			.build()
			.name(scopedMetricName)
			.help(helpString)
			.labelNames(toArray(dimensionKeys))
			.create();
	} else if (metric instanceof Histogram) {
		collector = new HistogramSummaryProxy((Histogram) metric, scopedMetricName, helpString, dimensionKeys, dimensionValues);
	} else {
		log.warn("Cannot create collector for unknown metric type: {}. This indicates that the metric type is not supported by this reporter.",
			metric.getClass().getName());
		collector = null;
	}
	return collector;
}
 
Example #15
Source File: Slf4jReporterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddMeter() throws Exception {
	String meterName = "meter";

	Meter meter = taskMetricGroup.meter(meterName, new MeterView(5));
	assertTrue(reporter.getMeters().containsKey(meter));

	String expectedMeterReport = reporter.filterCharacters(HOST_NAME) + delimiter
		+ reporter.filterCharacters(TASK_MANAGER_ID) + delimiter + reporter.filterCharacters(JOB_NAME) + delimiter
		+ reporter.filterCharacters(meterName) + ": 0.0";

	reporter.report();
	assertThat(
		testLoggerResource.getMessages(),
		hasItem(containsString(expectedMeterReport)));
}
 
Example #16
Source File: PrometheusReporterTaskScopeTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void metersCanBeAddedSeveralTimesIfTheyDifferInLabels() throws UnirestException {
	Meter meter = new TestMeter();

	taskMetricGroup1.meter("my_meter", meter);
	taskMetricGroup2.meter("my_meter", meter);

	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_meter", LABEL_NAMES, labelValues1),
		equalTo(5.));
	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_meter", LABEL_NAMES, labelValues2),
		equalTo(5.));
}
 
Example #17
Source File: MetricDumpSerializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNullGaugeHandling() throws IOException {
	MetricDumpSerialization.MetricDumpSerializer serializer = new MetricDumpSerialization.MetricDumpSerializer();
	MetricDumpSerialization.MetricDumpDeserializer deserializer = new MetricDumpSerialization.MetricDumpDeserializer();

	Map<Gauge<?>, Tuple2<QueryScopeInfo, String>> gauges = new HashMap<>();

	gauges.put(new Gauge<Object>() {
		@Override
		public Object getValue() {
			return null;
		}
	}, new Tuple2<QueryScopeInfo, String>(new QueryScopeInfo.JobManagerQueryScopeInfo("A"), "g"));

	MetricDumpSerialization.MetricSerializationResult output = serializer.serialize(
		Collections.<Counter, Tuple2<QueryScopeInfo, String>>emptyMap(),
		gauges,
		Collections.<Histogram, Tuple2<QueryScopeInfo, String>>emptyMap(),
		Collections.<Meter, Tuple2<QueryScopeInfo, String>>emptyMap());

	// no metrics should be serialized
	Assert.assertEquals(0, output.serializedCounters.length);
	Assert.assertEquals(0, output.serializedGauges.length);
	Assert.assertEquals(0, output.serializedHistograms.length);
	Assert.assertEquals(0, output.serializedMeters.length);

	List<MetricDump> deserialized = deserializer.deserialize(output);
	Assert.assertEquals(0, deserialized.size());
}
 
Example #18
Source File: FlinkMeterWrapperTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testWrapper() {
	Meter meter = new TestMeter();

	FlinkMeterWrapper wrapper = new FlinkMeterWrapper(meter);
	assertEquals(0, wrapper.getMeanRate(), DELTA);
	assertEquals(5, wrapper.getOneMinuteRate(), DELTA);
	assertEquals(0, wrapper.getFiveMinuteRate(), DELTA);
	assertEquals(0, wrapper.getFifteenMinuteRate(), DELTA);
	assertEquals(100L, wrapper.getCount());
}
 
Example #19
Source File: MetricQueryService.java    From flink with Apache License 2.0 5 votes vote down vote up
public void addMetric(String metricName, Metric metric, AbstractMetricGroup group) {
	runAsync(() -> {
		QueryScopeInfo info = group.getQueryServiceMetricInfo(FILTER);

		if (metric instanceof Counter) {
			counters.put((Counter) metric, new Tuple2<>(info, FILTER.filterCharacters(metricName)));
		} else if (metric instanceof Gauge) {
			gauges.put((Gauge<?>) metric, new Tuple2<>(info, FILTER.filterCharacters(metricName)));
		} else if (metric instanceof Histogram) {
			histograms.put((Histogram) metric, new Tuple2<>(info, FILTER.filterCharacters(metricName)));
		} else if (metric instanceof Meter) {
			meters.put((Meter) metric, new Tuple2<>(info, FILTER.filterCharacters(metricName)));
		}
	});
}
 
Example #20
Source File: MetricQueryService.java    From flink with Apache License 2.0 5 votes vote down vote up
public void removeMetric(Metric metric) {
	runAsync(() -> {
		if (metric instanceof Counter) {
			this.counters.remove(metric);
		} else if (metric instanceof Gauge) {
			this.gauges.remove(metric);
		} else if (metric instanceof Histogram) {
			this.histograms.remove(metric);
		} else if (metric instanceof Meter) {
			this.meters.remove(metric);
		}
	});
}
 
Example #21
Source File: FlinkMeterWrapperTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testMarkOneEvent() {
	Meter meter = mock(Meter.class);

	FlinkMeterWrapper wrapper = new FlinkMeterWrapper(meter);
	wrapper.mark();

	verify(meter).markEvent();
}
 
Example #22
Source File: FlinkMeterWrapperTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testMarkSeveralEvents() {
	Meter meter = mock(Meter.class);

	FlinkMeterWrapper wrapper = new FlinkMeterWrapper(meter);
	wrapper.mark(5);

	verify(meter).markEvent(5);
}
 
Example #23
Source File: Slf4jReporterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddMeter() throws Exception {
	String meterName = "meter";

	Meter meter = taskMetricGroup.meter(meterName, new MeterView(5));
	assertTrue(reporter.getMeters().containsKey(meter));

	String expectedMeterReport = reporter.filterCharacters(HOST_NAME) + delimiter
		+ reporter.filterCharacters(TASK_MANAGER_ID) + delimiter + reporter.filterCharacters(JOB_NAME) + delimiter
		+ reporter.filterCharacters(meterName) + ": 0.0";

	reporter.report();
	TestUtils.checkForLogString(expectedMeterReport);
}
 
Example #24
Source File: AbstractPrometheusReporter.java    From flink with Apache License 2.0 5 votes vote down vote up
private void removeMetric(Metric metric, List<String> dimensionValues, Collector collector) {
	if (metric instanceof Gauge) {
		((io.prometheus.client.Gauge) collector).remove(toArray(dimensionValues));
	} else if (metric instanceof Counter) {
		((io.prometheus.client.Gauge) collector).remove(toArray(dimensionValues));
	} else if (metric instanceof Meter) {
		((io.prometheus.client.Gauge) collector).remove(toArray(dimensionValues));
	} else if (metric instanceof Histogram) {
		((HistogramSummaryProxy) collector).remove(dimensionValues);
	} else {
		log.warn("Cannot remove unknown metric type: {}. This indicates that the metric type is not supported by this reporter.",
			metric.getClass().getName());
	}
}
 
Example #25
Source File: ScheduledDropwizardReporter.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void report() {
	// we do not need to lock here, because the dropwizard registry is
	// internally a concurrent map
	@SuppressWarnings("rawtypes")
	final SortedMap<String, com.codahale.metrics.Gauge> gauges = registry.getGauges();
	final SortedMap<String, com.codahale.metrics.Counter> counters = registry.getCounters();
	final SortedMap<String, com.codahale.metrics.Histogram> histograms = registry.getHistograms();
	final SortedMap<String, com.codahale.metrics.Meter> meters = registry.getMeters();
	final SortedMap<String, com.codahale.metrics.Timer> timers = registry.getTimers();

	this.reporter.report(gauges, counters, histograms, meters, timers);
}
 
Example #26
Source File: PrometheusReporterTaskScopeTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void metersCanBeAddedSeveralTimesIfTheyDifferInLabels() throws UnirestException {
	Meter meter = new TestMeter();

	taskMetricGroup1.meter("my_meter", meter);
	taskMetricGroup2.meter("my_meter", meter);

	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_meter", LABEL_NAMES, labelValues1),
		equalTo(5.));
	assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_meter", LABEL_NAMES, labelValues2),
		equalTo(5.));
}
 
Example #27
Source File: AbstractPrometheusReporter.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static io.prometheus.client.Gauge.Child gaugeFrom(Meter meter) {
	return new io.prometheus.client.Gauge.Child() {
		@Override
		public double get() {
			return meter.getRate();
		}
	};
}
 
Example #28
Source File: AbstractPrometheusReporter.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void removeMetric(Metric metric, List<String> dimensionValues, Collector collector) {
	if (metric instanceof Gauge) {
		((io.prometheus.client.Gauge) collector).remove(toArray(dimensionValues));
	} else if (metric instanceof Counter) {
		((io.prometheus.client.Gauge) collector).remove(toArray(dimensionValues));
	} else if (metric instanceof Meter) {
		((io.prometheus.client.Gauge) collector).remove(toArray(dimensionValues));
	} else if (metric instanceof Histogram) {
		((HistogramSummaryProxy) collector).remove(dimensionValues);
	} else {
		log.warn("Cannot remove unknown metric type: {}. This indicates that the metric type is not supported by this reporter.",
			metric.getClass().getName());
	}
}
 
Example #29
Source File: DatadogHttpReporter.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyOfRemovedMetric(Metric metric, String metricName, MetricGroup group) {
	if (metric instanceof Counter) {
		counters.remove(metric);
	} else if (metric instanceof Gauge) {
		gauges.remove(metric);
	} else if (metric instanceof Meter) {
		meters.remove(metric);
	} else if (metric instanceof Histogram) {
		// No Histogram is registered
	} else {
		LOGGER.warn("Cannot remove unknown metric type {}. This indicates that the reporter " +
			"does not support this metric type.", metric.getClass().getName());
	}
}
 
Example #30
Source File: DatadogHttpReporter.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void notifyOfRemovedMetric(Metric metric, String metricName, MetricGroup group) {
	if (metric instanceof Counter) {
		counters.remove(metric);
	} else if (metric instanceof Gauge) {
		gauges.remove(metric);
	} else if (metric instanceof Meter) {
		meters.remove(metric);
	} else if (metric instanceof Histogram) {
		// No Histogram is registered
	} else {
		LOGGER.warn("Cannot remove unknown metric type {}. This indicates that the reporter " +
			"does not support this metric type.", metric.getClass().getName());
	}
}