Search in sources :

Example 46 with Counter

use of org.apache.flink.metrics.Counter in project flink by apache.

the class InfluxdbReporterTest method testMetricRegistration.

@Test
void testMetricRegistration() {
    InfluxdbReporter reporter = createReporter(InfluxdbReporterOptions.RETENTION_POLICY.defaultValue(), InfluxdbReporterOptions.CONSISTENCY.defaultValue());
    String metricName = "TestCounter";
    Counter counter = new SimpleCounter();
    reporter.notifyOfAddedMetric(counter, metricName, metricGroup);
    MeasurementInfo measurementInfo = reporter.counters.get(counter);
    assertThat(measurementInfo).isNotNull();
    assertThat(measurementInfo.getName()).isEqualTo("taskmanager_" + metricName);
    assertThat(measurementInfo.getTags()).containsEntry("host", METRIC_HOSTNAME);
}
Also used : SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Test(org.junit.jupiter.api.Test)

Example 47 with Counter

use of org.apache.flink.metrics.Counter in project flink by apache.

the class MetricMapperTest method testMapCounter.

@Test
void testMapCounter() {
    Counter counter = new SimpleCounter();
    counter.inc(42L);
    verifyPoint(MetricMapper.map(INFO, TIMESTAMP, counter), "count=42");
}
Also used : SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Test(org.junit.jupiter.api.Test)

Example 48 with Counter

use of org.apache.flink.metrics.Counter in project flink by apache.

the class DCounterTest method testGetMetricValue.

@Test
public void testGetMetricValue() {
    final Counter backingCounter = new SimpleCounter();
    final DCounter counter = new DCounter(backingCounter, "counter", "localhost", Collections.emptyList(), () -> 0);
    // sane initial state
    assertEquals(0L, counter.getMetricValue());
    counter.ackReport();
    assertEquals(0L, counter.getMetricValue());
    // value is compared against initial state 0
    backingCounter.inc(10);
    assertEquals(10L, counter.getMetricValue());
    // last value was not acked, should still be compared against initial state 0
    backingCounter.inc(10);
    assertEquals(20L, counter.getMetricValue());
    // last value (20) acked, now target of comparison
    counter.ackReport();
    assertEquals(0L, counter.getMetricValue());
    // we now compare against the acked value
    backingCounter.inc(10);
    assertEquals(10L, counter.getMetricValue());
    // properly handle decrements
    backingCounter.dec(10);
    assertEquals(0L, counter.getMetricValue());
}
Also used : SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.flink.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Test(org.junit.Test)

Example 49 with Counter

use of org.apache.flink.metrics.Counter 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)

Example 50 with Counter

use of org.apache.flink.metrics.Counter 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

Counter (org.apache.flink.metrics.Counter)78 SimpleCounter (org.apache.flink.metrics.SimpleCounter)24 Test (org.junit.Test)22 CountingCollector (org.apache.flink.runtime.operators.util.metrics.CountingCollector)18 Test (org.junit.jupiter.api.Test)16 Histogram (org.apache.flink.metrics.Histogram)15 Meter (org.apache.flink.metrics.Meter)15 Gauge (org.apache.flink.metrics.Gauge)14 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)12 CountingMutableObjectIterator (org.apache.flink.runtime.operators.util.metrics.CountingMutableObjectIterator)10 MetricGroup (org.apache.flink.metrics.MetricGroup)7 TestHistogram (org.apache.flink.metrics.util.TestHistogram)7 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)6 TestMeter (org.apache.flink.metrics.util.TestMeter)5 TaskConfig (org.apache.flink.runtime.operators.util.TaskConfig)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 OperatorIOMetricGroup (org.apache.flink.metrics.groups.OperatorIOMetricGroup)4 MetricListener (org.apache.flink.metrics.testutils.MetricListener)4