org.apache.flink.metrics.Histogram Java Examples

The following examples show how to use org.apache.flink.metrics.Histogram. 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: 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 #2
Source File: StatsDReporter.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private void reportHistogram(final String name, final Histogram histogram) {
	if (histogram != null) {

		HistogramStatistics statistics = histogram.getStatistics();

		if (statistics != null) {
			send(prefix(name, "count"), String.valueOf(histogram.getCount()));
			send(prefix(name, "max"), String.valueOf(statistics.getMax()));
			send(prefix(name, "min"), String.valueOf(statistics.getMin()));
			send(prefix(name, "mean"), String.valueOf(statistics.getMean()));
			send(prefix(name, "stddev"), String.valueOf(statistics.getStdDev()));
			send(prefix(name, "p50"), String.valueOf(statistics.getQuantile(0.5)));
			send(prefix(name, "p75"), String.valueOf(statistics.getQuantile(0.75)));
			send(prefix(name, "p95"), String.valueOf(statistics.getQuantile(0.95)));
			send(prefix(name, "p98"), String.valueOf(statistics.getQuantile(0.98)));
			send(prefix(name, "p99"), String.valueOf(statistics.getQuantile(0.99)));
			send(prefix(name, "p999"), String.valueOf(statistics.getQuantile(0.999)));
		}
	}
}
 
Example #3
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 #4
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 #5
Source File: LatencyStatsTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private static void testLatencyStats(
	final LatencyStats.Granularity granularity,
	final Consumer<List<Tuple2<String, Histogram>>> verifier) {

	final AbstractMetricGroup<?> dummyGroup = UnregisteredMetricGroups.createUnregisteredOperatorMetricGroup();
	final TestMetricRegistry registry = new TestMetricRegistry();
	final MetricGroup parentGroup = new GenericMetricGroup(registry, dummyGroup, PARENT_GROUP_NAME);

	final LatencyStats latencyStats = new LatencyStats(
		parentGroup,
		MetricOptions.LATENCY_HISTORY_SIZE.defaultValue(),
		OPERATOR_SUBTASK_INDEX,
		OPERATOR_ID,
		granularity);

	latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_1, 0));
	latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_1, 0));
	latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_1, 1));
	latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_2, 2));
	latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_2, 3));

	verifier.accept(registry.latencyHistograms);
}
 
Example #6
Source File: PrometheusReporterTaskScopeTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void histogramsCanBeAddedSeveralTimesIfTheyDifferInLabels() throws UnirestException {
	Histogram histogram = new TestHistogram();

	taskMetricGroup1.histogram("my_histogram", histogram);
	taskMetricGroup2.histogram("my_histogram", histogram);

	final String exportedMetrics = pollMetrics(reporter.getPort()).getBody();
	assertThat(exportedMetrics, containsString("subtask_index=\"0\",quantile=\"0.5\",} 0.5")); // histogram
	assertThat(exportedMetrics, containsString("subtask_index=\"1\",quantile=\"0.5\",} 0.5")); // histogram

	final String[] labelNamesWithQuantile = addToArray(LABEL_NAMES, "quantile");
	for (Double quantile : PrometheusReporter.HistogramSummaryProxy.QUANTILES) {
		assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_histogram", labelNamesWithQuantile, addToArray(labelValues1, "" + quantile)),
			equalTo(quantile));
		assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_histogram", labelNamesWithQuantile, addToArray(labelValues2, "" + quantile)),
			equalTo(quantile));
	}
}
 
Example #7
Source File: MetricMapperTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testMapHistogram() {
	Histogram histogram = new TestHistogram();

	verifyPoint(
		MetricMapper.map(INFO, TIMESTAMP, histogram),
		"count=3",
		"max=6",
		"mean=4.0",
		"min=7",
		"p50=0.5",
		"p75=0.75",
		"p95=0.95",
		"p98=0.98",
		"p99=0.99",
		"p999=0.999",
		"stddev=5.0");
}
 
Example #8
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 #9
Source File: MetricMapper.java    From flink with Apache License 2.0 6 votes vote down vote up
static Point map(MeasurementInfo info, Instant timestamp, Histogram histogram) {
	HistogramStatistics statistics = histogram.getStatistics();
	return builder(info, timestamp)
		.addField("count", statistics.size())
		.addField("min", statistics.getMin())
		.addField("max", statistics.getMax())
		.addField("mean", statistics.getMean())
		.addField("stddev", statistics.getStdDev())
		.addField("p50", statistics.getQuantile(.50))
		.addField("p75", statistics.getQuantile(.75))
		.addField("p95", statistics.getQuantile(.95))
		.addField("p98", statistics.getQuantile(.98))
		.addField("p99", statistics.getQuantile(.99))
		.addField("p999", statistics.getQuantile(.999))
		.build();
}
 
Example #10
Source File: MetricMapperTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testMapHistogram() {
	Histogram histogram = new TestHistogram();

	verifyPoint(
		MetricMapper.map(INFO, TIMESTAMP, histogram),
		"count=3",
		"max=6",
		"mean=4.0",
		"min=7",
		"p50=0.5",
		"p75=0.75",
		"p95=0.95",
		"p98=0.98",
		"p99=0.99",
		"p999=0.999",
		"stddev=5.0");
}
 
Example #11
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 #12
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 #13
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 #14
Source File: MetricMapper.java    From flink with Apache License 2.0 6 votes vote down vote up
static Point map(MeasurementInfo info, Instant timestamp, Histogram histogram) {
	HistogramStatistics statistics = histogram.getStatistics();
	return builder(info, timestamp)
		.addField("count", statistics.size())
		.addField("min", statistics.getMin())
		.addField("max", statistics.getMax())
		.addField("mean", statistics.getMean())
		.addField("stddev", statistics.getStdDev())
		.addField("p50", statistics.getQuantile(.50))
		.addField("p75", statistics.getQuantile(.75))
		.addField("p95", statistics.getQuantile(.95))
		.addField("p98", statistics.getQuantile(.98))
		.addField("p99", statistics.getQuantile(.99))
		.addField("p999", statistics.getQuantile(.999))
		.build();
}
 
Example #15
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 #16
Source File: PrometheusReporterTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void histogramIsReportedAsPrometheusSummary() throws UnirestException {
	Histogram testHistogram = new TestHistogram();

	String histogramName = "testHistogram";
	String summaryName = SCOPE_PREFIX + histogramName;

	String response = addMetricAndPollResponse(testHistogram, histogramName);
	assertThat(response, containsString(HELP_PREFIX + summaryName + " " + histogramName + " (scope: taskmanager)\n" +
		TYPE_PREFIX + summaryName + " summary" + "\n" +
		summaryName + "_count" + DEFAULT_LABELS + " 1.0" + "\n"));
	for (String quantile : Arrays.asList("0.5", "0.75", "0.95", "0.98", "0.99", "0.999")) {
		assertThat(response, containsString(
			summaryName + "{" + DIMENSIONS + ",quantile=\"" + quantile + "\",} " + quantile + "\n"));
	}
}
 
Example #17
Source File: PrometheusReporterTaskScopeTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void histogramsCanBeAddedSeveralTimesIfTheyDifferInLabels() throws UnirestException {
	Histogram histogram = new TestHistogram();

	taskMetricGroup1.histogram("my_histogram", histogram);
	taskMetricGroup2.histogram("my_histogram", histogram);

	final String exportedMetrics = pollMetrics(reporter.getPort()).getBody();
	assertThat(exportedMetrics, containsString("subtask_index=\"0\",quantile=\"0.5\",} 0.5")); // histogram
	assertThat(exportedMetrics, containsString("subtask_index=\"1\",quantile=\"0.5\",} 0.5")); // histogram

	final String[] labelNamesWithQuantile = addToArray(LABEL_NAMES, "quantile");
	for (Double quantile : PrometheusReporter.HistogramSummaryProxy.QUANTILES) {
		assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_histogram", labelNamesWithQuantile, addToArray(labelValues1, "" + quantile)),
			equalTo(quantile));
		assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_histogram", labelNamesWithQuantile, addToArray(labelValues2, "" + quantile)),
			equalTo(quantile));
	}
}
 
Example #18
Source File: AbstractPrometheusReporter.java    From Flink-CEPplus 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 #19
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));
	} else if (metric instanceof Gauge) {
		Gauge g = (Gauge) metric;
		gauges.put(g, new DGauge(g, name, host, tags));
	} else if (metric instanceof Meter) {
		Meter m = (Meter) metric;
		// Only consider rate
		meters.put(m, new DMeter(m, name, host, tags));
	} 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 #20
Source File: LatencyStatsTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private static void testLatencyStats(
	final LatencyStats.Granularity granularity,
	final Consumer<List<Tuple2<String, Histogram>>> verifier) {

	final AbstractMetricGroup<?> dummyGroup = UnregisteredMetricGroups.createUnregisteredOperatorMetricGroup();
	final TestMetricRegistry registry = new TestMetricRegistry();
	final MetricGroup parentGroup = new GenericMetricGroup(registry, dummyGroup, PARENT_GROUP_NAME);

	final LatencyStats latencyStats = new LatencyStats(
		parentGroup,
		MetricOptions.LATENCY_HISTORY_SIZE.defaultValue(),
		OPERATOR_SUBTASK_INDEX,
		OPERATOR_ID,
		granularity);

	latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_1, 0));
	latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_1, 0));
	latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_1, 1));
	latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_2, 2));
	latencyStats.reportLatency(new LatencyMarker(0L, SOURCE_ID_2, 3));

	verifier.accept(registry.latencyHistograms);
}
 
Example #21
Source File: StatsDReporter.java    From flink with Apache License 2.0 6 votes vote down vote up
private void reportHistogram(final String name, final Histogram histogram) {
	if (histogram != null) {

		HistogramStatistics statistics = histogram.getStatistics();

		if (statistics != null) {
			send(prefix(name, "count"), histogram.getCount());
			send(prefix(name, "max"), statistics.getMax());
			send(prefix(name, "min"), statistics.getMin());
			send(prefix(name, "mean"), statistics.getMean());
			send(prefix(name, "stddev"), statistics.getStdDev());
			send(prefix(name, "p50"), statistics.getQuantile(0.5));
			send(prefix(name, "p75"), statistics.getQuantile(0.75));
			send(prefix(name, "p95"), statistics.getQuantile(0.95));
			send(prefix(name, "p98"), statistics.getQuantile(0.98));
			send(prefix(name, "p99"), statistics.getQuantile(0.99));
			send(prefix(name, "p999"), statistics.getQuantile(0.999));
		}
	}
}
 
Example #22
Source File: PrometheusReporterTaskScopeTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void histogramsCanBeAddedSeveralTimesIfTheyDifferInLabels() throws UnirestException {
	Histogram histogram = new TestHistogram();

	taskMetricGroup1.histogram("my_histogram", histogram);
	taskMetricGroup2.histogram("my_histogram", histogram);

	final String exportedMetrics = pollMetrics(reporter.getPort()).getBody();
	assertThat(exportedMetrics, containsString("subtask_index=\"0\",quantile=\"0.5\",} 0.5")); // histogram
	assertThat(exportedMetrics, containsString("subtask_index=\"1\",quantile=\"0.5\",} 0.5")); // histogram

	final String[] labelNamesWithQuantile = addToArray(LABEL_NAMES, "quantile");
	for (Double quantile : PrometheusReporter.HistogramSummaryProxy.QUANTILES) {
		assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_histogram", labelNamesWithQuantile, addToArray(labelValues1, "" + quantile)),
			equalTo(quantile));
		assertThat(CollectorRegistry.defaultRegistry.getSampleValue("flink_taskmanager_job_task_my_histogram", labelNamesWithQuantile, addToArray(labelValues2, "" + quantile)),
			equalTo(quantile));
	}
}
 
Example #23
Source File: PrometheusReporterTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void histogramIsReportedAsPrometheusSummary() throws UnirestException {
	Histogram testHistogram = new TestHistogram();

	String histogramName = "testHistogram";
	String summaryName = SCOPE_PREFIX + histogramName;

	String response = addMetricAndPollResponse(testHistogram, histogramName);
	assertThat(response, containsString(HELP_PREFIX + summaryName + " " + histogramName + " (scope: taskmanager)\n" +
		TYPE_PREFIX + summaryName + " summary" + "\n" +
		summaryName + "_count" + DEFAULT_LABELS + " 1.0" + "\n"));
	for (String quantile : Arrays.asList("0.5", "0.75", "0.95", "0.98", "0.99", "0.999")) {
		assertThat(response, containsString(
			summaryName + "{" + DIMENSIONS + ",quantile=\"" + quantile + "\",} " + quantile + "\n"));
	}
}
 
Example #24
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 #25
Source File: MetricMapper.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
static Point map(MeasurementInfo info, Instant timestamp, Histogram histogram) {
	HistogramStatistics statistics = histogram.getStatistics();
	return builder(info, timestamp)
		.addField("count", statistics.size())
		.addField("min", statistics.getMin())
		.addField("max", statistics.getMax())
		.addField("mean", statistics.getMean())
		.addField("stddev", statistics.getStdDev())
		.addField("p50", statistics.getQuantile(.50))
		.addField("p75", statistics.getQuantile(.75))
		.addField("p95", statistics.getQuantile(.95))
		.addField("p98", statistics.getQuantile(.98))
		.addField("p99", statistics.getQuantile(.99))
		.addField("p999", statistics.getQuantile(.999))
		.build();
}
 
Example #26
Source File: MetricMapperTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testMapHistogram() {
	Histogram histogram = new TestHistogram();

	verifyPoint(
		MetricMapper.map(INFO, TIMESTAMP, histogram),
		"count=3",
		"max=6",
		"mean=4.0",
		"min=7",
		"p50=0.5",
		"p75=0.75",
		"p95=0.95",
		"p98=0.98",
		"p99=0.99",
		"p999=0.999",
		"stddev=5.0");
}
 
Example #27
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 #28
Source File: MetricQueryServiceTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateDump() throws Exception {
	MetricQueryService queryService = MetricQueryService.createMetricQueryService(rpcService, ResourceID.generate(), Long.MAX_VALUE);
	queryService.start();

	final Counter c = new SimpleCounter();
	final Gauge<String> g = () -> "Hello";
	final Histogram h = new TestHistogram();
	final Meter m = new TestMeter();

	final TaskManagerMetricGroup tm = UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup();

	queryService.addMetric("counter", c, tm);
	queryService.addMetric("gauge", g, tm);
	queryService.addMetric("histogram", h, tm);
	queryService.addMetric("meter", m, tm);

	MetricDumpSerialization.MetricSerializationResult dump = queryService.queryMetrics(TIMEOUT).get();

	assertTrue(dump.serializedCounters.length > 0);
	assertTrue(dump.serializedGauges.length > 0);
	assertTrue(dump.serializedHistograms.length > 0);
	assertTrue(dump.serializedMeters.length > 0);

	queryService.removeMetric(c);
	queryService.removeMetric(g);
	queryService.removeMetric(h);
	queryService.removeMetric(m);

	MetricDumpSerialization.MetricSerializationResult emptyDump = queryService.queryMetrics(TIMEOUT).get();

	assertEquals(0, emptyDump.serializedCounters.length);
	assertEquals(0, emptyDump.serializedGauges.length);
	assertEquals(0, emptyDump.serializedHistograms.length);
	assertEquals(0, emptyDump.serializedMeters.length);
}
 
Example #29
Source File: AbstractPrometheusReporter.java    From flink with Apache License 2.0 5 votes vote down vote up
private void addMetric(Metric metric, List<String> dimensionValues, Collector collector) {
	if (metric instanceof Gauge) {
		((io.prometheus.client.Gauge) collector).setChild(gaugeFrom((Gauge) metric), toArray(dimensionValues));
	} else if (metric instanceof Counter) {
		((io.prometheus.client.Gauge) collector).setChild(gaugeFrom((Counter) metric), toArray(dimensionValues));
	} else if (metric instanceof Meter) {
		((io.prometheus.client.Gauge) collector).setChild(gaugeFrom((Meter) metric), toArray(dimensionValues));
	} else if (metric instanceof Histogram) {
		((HistogramSummaryProxy) collector).addChild((Histogram) metric, dimensionValues);
	} else {
		log.warn("Cannot add unknown metric type: {}. This indicates that the metric type is not supported by this reporter.",
			metric.getClass().getName());
	}
}
 
Example #30
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());
	}
}