Search in sources :

Example 11 with Histogram

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));
}
Also used : Histogram(org.apache.flink.metrics.Histogram) TestHistogram(org.apache.flink.metrics.util.TestHistogram) TestHistogram(org.apache.flink.metrics.util.TestHistogram) Test(org.junit.jupiter.api.Test)

Example 12 with Histogram

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);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) Histogram(org.apache.flink.metrics.Histogram) Meter(org.apache.flink.metrics.Meter) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ObjectName(javax.management.ObjectName) Gauge(org.apache.flink.metrics.Gauge) Counter(org.apache.flink.metrics.Counter)

Example 13 with Histogram

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();
}
Also used : Histogram(org.apache.flink.metrics.Histogram) ConcurrentModificationException(java.util.ConcurrentModificationException) BatchPoints(org.influxdb.dto.BatchPoints) Meter(org.apache.flink.metrics.Meter) Instant(java.time.Instant) Gauge(org.apache.flink.metrics.Gauge) Counter(org.apache.flink.metrics.Counter) Map(java.util.Map) NoSuchElementException(java.util.NoSuchElementException) Nullable(javax.annotation.Nullable)

Example 14 with Histogram

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");
    }
}
Also used : Histogram(org.apache.flink.metrics.Histogram) TestHistogram(org.apache.flink.metrics.util.TestHistogram) TestHistogram(org.apache.flink.metrics.util.TestHistogram) Test(org.junit.jupiter.api.Test)

Example 15 with Histogram

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());
    }
}
Also used : Histogram(org.apache.flink.metrics.Histogram) Counter(org.apache.flink.metrics.Counter) Meter(org.apache.flink.metrics.Meter) ArrayList(java.util.ArrayList) Gauge(org.apache.flink.metrics.Gauge)

Aggregations

Histogram (org.apache.flink.metrics.Histogram)19 Counter (org.apache.flink.metrics.Counter)14 Meter (org.apache.flink.metrics.Meter)13 Gauge (org.apache.flink.metrics.Gauge)11 TestHistogram (org.apache.flink.metrics.util.TestHistogram)9 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)6 SimpleCounter (org.apache.flink.metrics.SimpleCounter)6 Test (org.junit.Test)6 Test (org.junit.jupiter.api.Test)5 MetricGroup (org.apache.flink.metrics.MetricGroup)4 HashMap (java.util.HashMap)3 HistogramStatistics (org.apache.flink.metrics.HistogramStatistics)3 TestMeter (org.apache.flink.metrics.util.TestMeter)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)2 MetricDumpSerialization (org.apache.flink.runtime.metrics.dump.MetricDumpSerialization)2 AbstractMetricGroup (org.apache.flink.runtime.metrics.groups.AbstractMetricGroup)2 TaskManagerMetricGroup (org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup)2