use of org.apache.flink.metrics.Histogram in project flink by apache.
the class Slf4jReporterTest method testAddHistogram.
@Test
void testAddHistogram() throws Exception {
String histogramName = "histogram";
Histogram histogram = new TestHistogram();
reporter.notifyOfAddedMetric(histogram, histogramName, metricGroup);
assertThat(reporter.getHistograms()).containsKey(histogram);
String expectedHistogramName = reporter.filterCharacters(SCOPE) + delimiter + reporter.filterCharacters(histogramName);
reporter.report();
assertThat(testLoggerResource.getMessages()).anyMatch(logOutput -> logOutput.contains(expectedHistogramName));
}
use of org.apache.flink.metrics.Histogram in project flink by apache.
the class JMXReporter method notifyOfAddedMetric.
// ------------------------------------------------------------------------
// adding / removing metrics
// ------------------------------------------------------------------------
@Override
public void notifyOfAddedMetric(Metric metric, String metricName, MetricGroup group) {
final String domain = generateJmxDomain(metricName, group);
final Hashtable<String, String> table = generateJmxTable(group.getAllVariables());
AbstractBean jmxMetric;
ObjectName jmxName;
try {
jmxName = new ObjectName(domain, table);
} catch (MalformedObjectNameException e) {
/*
* There is an implementation error on our side if this occurs. Either the domain was
* modified and no longer conforms to the JMX domain rules or the table wasn't properly
* generated.
*/
LOG.debug("Implementation error. The domain or table does not conform to JMX rules.", e);
return;
}
if (metric instanceof Gauge) {
jmxMetric = new JmxGauge((Gauge<?>) metric);
} else if (metric instanceof Counter) {
jmxMetric = new JmxCounter((Counter) metric);
} else if (metric instanceof Histogram) {
jmxMetric = new JmxHistogram((Histogram) metric);
} else if (metric instanceof Meter) {
jmxMetric = new JmxMeter((Meter) metric);
} else {
LOG.error("Cannot add unknown metric type: {}. This indicates that the metric type " + "is not supported by this reporter.", metric.getClass().getName());
return;
}
try {
synchronized (this) {
mBeanServer.registerMBean(jmxMetric, jmxName);
registeredMetrics.put(metric, jmxName);
}
} catch (NotCompliantMBeanException e) {
// implementation error on our side
LOG.debug("Metric did not comply with JMX MBean rules.", e);
} catch (InstanceAlreadyExistsException e) {
LOG.warn("A metric with the name " + jmxName + " was already registered.", e);
} catch (Throwable t) {
LOG.warn("Failed to register metric", t);
}
}
use of org.apache.flink.metrics.Histogram in project flink by apache.
the class InfluxdbReporter method buildReport.
@Nullable
private BatchPoints buildReport() {
Instant timestamp = Instant.now();
BatchPoints.Builder report = BatchPoints.database(database);
report.retentionPolicy(retentionPolicy);
report.consistency(consistency);
try {
for (Map.Entry<Gauge<?>, MeasurementInfo> entry : gauges.entrySet()) {
report.point(MetricMapper.map(entry.getValue(), timestamp, entry.getKey()));
}
for (Map.Entry<Counter, MeasurementInfo> entry : counters.entrySet()) {
report.point(MetricMapper.map(entry.getValue(), timestamp, entry.getKey()));
}
for (Map.Entry<Histogram, MeasurementInfo> entry : histograms.entrySet()) {
report.point(MetricMapper.map(entry.getValue(), timestamp, entry.getKey()));
}
for (Map.Entry<Meter, MeasurementInfo> entry : meters.entrySet()) {
report.point(MetricMapper.map(entry.getValue(), timestamp, entry.getKey()));
}
} catch (ConcurrentModificationException | NoSuchElementException e) {
// report next time
return null;
}
return report.build();
}
use of org.apache.flink.metrics.Histogram in project flink by apache.
the class PrometheusReporterTest method histogramIsReportedAsPrometheusSummary.
@Test
void histogramIsReportedAsPrometheusSummary() throws UnirestException {
Histogram testHistogram = new TestHistogram();
String histogramName = "testHistogram";
String summaryName = SCOPE_PREFIX + histogramName;
String response = addMetricAndPollResponse(testHistogram, histogramName);
assertThat(response).contains(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).contains(summaryName + "{" + DIMENSIONS + ",quantile=\"" + quantile + "\",} " + quantile + "\n");
}
}
use of org.apache.flink.metrics.Histogram in project flink by apache.
the class DatadogHttpReporter method notifyOfAddedMetric.
@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) {
Histogram h = (Histogram) metric;
histograms.put(h, new DHistogram(h, name, host, tags, clock));
} else {
LOGGER.warn("Cannot add unknown metric type {}. This indicates that the reporter " + "does not support this metric type.", metric.getClass().getName());
}
}
Aggregations