SemanticCoreStatistics implements CoreStatistics { @Override public HighFrequencyDetectorStatistics newHighFrequency() { final MetricId m = metric.tagged("component", "high-freq"); final Map<MetricId, Long> highFreqMetricsMap = new ConcurrentHashMap<>(); return new HighFrequencyDetectorStatistics() { private final Counter dropped = registry.counter( m.tagged("what", "dropped-metrics", "unit", "metric")); @Override public void reportHighFrequencyMetricsDropped(int dropped) { this.dropped.inc(dropped); } @Override public void reportHighFrequencyMetrics(int marked, String... tags) { MetricId gaugeMetric = m.tagged("what", "high-freq-metrics").tagged(tags); registerGauge(gaugeMetric); highFreqMetricsMap.put(gaugeMetric, (long) marked); } private void registerGauge(MetricId gauge) { if (highFreqMetricsMap.containsKey(gauge)) { return; } try { registry.register(gauge, new Gauge<Long>() { @Override public Long getValue() { return highFreqMetricsMap.get(gauge); } }); } catch (IllegalArgumentException e) { } } }; } SemanticCoreStatistics(SemanticMetricRegistry registry); @Override InputManagerStatistics newInputManager(); @Override OutputManagerStatistics newOutputManager(); @Override OutputPluginStatistics newOutputPlugin(final String id); @Override BatchingStatistics newBatching(final String id); @Override HighFrequencyDetectorStatistics newHighFrequency();  }
@Test public void testNewHighFrequency() { HighFrequencyDetectorStatistics stats = statistics.newHighFrequency(); stats.reportHighFrequencyMetrics(1, "keys", "key1|key2|key3","whats","what,waht,what2"); stats.reportHighFrequencyMetrics(2, "keys", "key1|key2|key3|key4","whats","waht,what2"); stats.reportHighFrequencyMetrics(10, "keys", "key1|key2|key3","whats","what,what2"); stats.reportHighFrequencyMetrics(70, "keys", "key1|key2|key3","whats","what,waht,what2"); SortedMap<MetricId, Gauge> gaugesFinal = registry.getGauges(); List<Long> longs = gaugesFinal.entrySet().stream().map(set -> (Long)set.getValue().getValue()).collect(Collectors.toList()); assertEquals(List.of(2L, 70L, 10L), longs); }