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);
}
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");
}
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());
}
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);
}
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());
}
}
Aggregations