Search in sources :

Example 1 with DropwizardMeterWrapper

use of org.apache.flink.dropwizard.metrics.DropwizardMeterWrapper in project flink by apache.

the class ScheduledDropwizardReporter method notifyOfAddedMetric.

// ------------------------------------------------------------------------
// adding / removing metrics
// ------------------------------------------------------------------------
@Override
public void notifyOfAddedMetric(Metric metric, String metricName, MetricGroup group) {
    final String fullName = group.getMetricIdentifier(metricName, this);
    synchronized (this) {
        if (metric instanceof Counter) {
            counters.put((Counter) metric, fullName);
            registry.register(fullName, new FlinkCounterWrapper((Counter) metric));
        } else if (metric instanceof Gauge) {
            gauges.put((Gauge<?>) metric, fullName);
            registry.register(fullName, FlinkGaugeWrapper.fromGauge((Gauge<?>) metric));
        } else if (metric instanceof Histogram) {
            Histogram histogram = (Histogram) metric;
            histograms.put(histogram, fullName);
            if (histogram instanceof DropwizardHistogramWrapper) {
                registry.register(fullName, ((DropwizardHistogramWrapper) histogram).getDropwizardHistogram());
            } else {
                registry.register(fullName, new FlinkHistogramWrapper(histogram));
            }
        } else if (metric instanceof Meter) {
            Meter meter = (Meter) metric;
            meters.put(meter, fullName);
            if (meter instanceof DropwizardMeterWrapper) {
                registry.register(fullName, ((DropwizardMeterWrapper) meter).getDropwizardMeter());
            } else {
                registry.register(fullName, new FlinkMeterWrapper(meter));
            }
        } else {
            log.warn("Cannot add metric of type {}. This indicates that the reporter " + "does not support this metric type.", metric.getClass().getName());
        }
    }
}
Also used : FlinkHistogramWrapper(org.apache.flink.dropwizard.metrics.FlinkHistogramWrapper) DropwizardHistogramWrapper(org.apache.flink.dropwizard.metrics.DropwizardHistogramWrapper) Histogram(org.apache.flink.metrics.Histogram) Counter(org.apache.flink.metrics.Counter) DropwizardMeterWrapper(org.apache.flink.dropwizard.metrics.DropwizardMeterWrapper) Meter(org.apache.flink.metrics.Meter) FlinkCounterWrapper(org.apache.flink.dropwizard.metrics.FlinkCounterWrapper) FlinkMeterWrapper(org.apache.flink.dropwizard.metrics.FlinkMeterWrapper) Gauge(org.apache.flink.metrics.Gauge)

Example 2 with DropwizardMeterWrapper

use of org.apache.flink.dropwizard.metrics.DropwizardMeterWrapper in project flink by apache.

the class ScheduledDropwizardReporterTest method testAddingMetrics.

/**
 * Tests that the registered metrics' names don't contain invalid characters.
 */
@Test
void testAddingMetrics() {
    final String scope = "scope";
    final char delimiter = '_';
    final String counterName = "testCounter";
    final MetricGroup metricGroup = TestMetricGroup.newBuilder().setMetricIdentifierFunction((metricName, characterFilter) -> characterFilter.orElse(s -> s).filterCharacters(scope + delimiter + metricName)).build();
    final TestingScheduledDropwizardReporter reporter = new TestingScheduledDropwizardReporter();
    SimpleCounter myCounter = new SimpleCounter();
    com.codahale.metrics.Meter dropwizardMeter = new com.codahale.metrics.Meter();
    DropwizardMeterWrapper meterWrapper = new DropwizardMeterWrapper(dropwizardMeter);
    reporter.notifyOfAddedMetric(myCounter, counterName, metricGroup);
    reporter.notifyOfAddedMetric(meterWrapper, "meter", metricGroup);
    Map<Counter, String> counters = reporter.getCounters();
    assertThat(counters).containsKey(myCounter);
    Map<Meter, String> meters = reporter.getMeters();
    assertThat(meters).containsKey(meterWrapper);
    String expectedCounterName = reporter.filterCharacters(scope) + delimiter + reporter.filterCharacters(counterName);
    assertThat(counters).containsEntry(myCounter, expectedCounterName);
}
Also used : MetricConfig(org.apache.flink.metrics.MetricConfig) UnregisteredMetricsGroup(org.apache.flink.metrics.groups.UnregisteredMetricsGroup) TestMetricGroup(org.apache.flink.metrics.util.TestMetricGroup) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ScheduledReporter(com.codahale.metrics.ScheduledReporter) DropwizardMeterWrapper(org.apache.flink.dropwizard.metrics.DropwizardMeterWrapper) TestMeter(org.apache.flink.metrics.util.TestMeter) Histogram(org.apache.flink.metrics.Histogram) Test(org.junit.jupiter.api.Test) Meter(org.apache.flink.metrics.Meter) MetricGroup(org.apache.flink.metrics.MetricGroup) TestHistogram(org.apache.flink.metrics.util.TestHistogram) Map(java.util.Map) Gauge(org.apache.flink.metrics.Gauge) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) TestMeter(org.apache.flink.metrics.util.TestMeter) Meter(org.apache.flink.metrics.Meter) TestMetricGroup(org.apache.flink.metrics.util.TestMetricGroup) MetricGroup(org.apache.flink.metrics.MetricGroup) DropwizardMeterWrapper(org.apache.flink.dropwizard.metrics.DropwizardMeterWrapper) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Test(org.junit.jupiter.api.Test)

Aggregations

DropwizardMeterWrapper (org.apache.flink.dropwizard.metrics.DropwizardMeterWrapper)2 Counter (org.apache.flink.metrics.Counter)2 Gauge (org.apache.flink.metrics.Gauge)2 Histogram (org.apache.flink.metrics.Histogram)2 Meter (org.apache.flink.metrics.Meter)2 ScheduledReporter (com.codahale.metrics.ScheduledReporter)1 Map (java.util.Map)1 DropwizardHistogramWrapper (org.apache.flink.dropwizard.metrics.DropwizardHistogramWrapper)1 FlinkCounterWrapper (org.apache.flink.dropwizard.metrics.FlinkCounterWrapper)1 FlinkHistogramWrapper (org.apache.flink.dropwizard.metrics.FlinkHistogramWrapper)1 FlinkMeterWrapper (org.apache.flink.dropwizard.metrics.FlinkMeterWrapper)1 MetricConfig (org.apache.flink.metrics.MetricConfig)1 MetricGroup (org.apache.flink.metrics.MetricGroup)1 SimpleCounter (org.apache.flink.metrics.SimpleCounter)1 UnregisteredMetricsGroup (org.apache.flink.metrics.groups.UnregisteredMetricsGroup)1 TestHistogram (org.apache.flink.metrics.util.TestHistogram)1 TestMeter (org.apache.flink.metrics.util.TestMeter)1 TestMetricGroup (org.apache.flink.metrics.util.TestMetricGroup)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Test (org.junit.jupiter.api.Test)1