@ -19,10 +19,13 @@ package org.springframework.boot.actuate.metrics.export;
@@ -19,10 +19,13 @@ package org.springframework.boot.actuate.metrics.export;
import java.util.Collection ;
import java.util.HashSet ;
import java.util.Set ;
import java.util.concurrent.ConcurrentHashMap ;
import java.util.concurrent.ConcurrentMap ;
import org.springframework.boot.actuate.metrics.Metric ;
import org.springframework.boot.actuate.metrics.reader.PrefixMetricReader ;
import org.springframework.boot.actuate.metrics.repository.MultiMetricRepository ;
import org.springframework.boot.actuate.metrics.writer.Delta ;
import org.springframework.boot.actuate.metrics.writer.PrefixMetricWriter ;
/ * *
@ -38,6 +41,8 @@ public class PrefixMetricGroupExporter extends AbstractMetricExporter {
@@ -38,6 +41,8 @@ public class PrefixMetricGroupExporter extends AbstractMetricExporter {
private final PrefixMetricWriter writer ;
private ConcurrentMap < String , Long > counts = new ConcurrentHashMap < String , Long > ( ) ;
private Set < String > groups = new HashSet < String > ( ) ;
/ * *
@ -88,7 +93,26 @@ public class PrefixMetricGroupExporter extends AbstractMetricExporter {
@@ -88,7 +93,26 @@ public class PrefixMetricGroupExporter extends AbstractMetricExporter {
@Override
protected void write ( String group , Collection < Metric < ? > > values ) {
this . writer . set ( group , values ) ;
if ( group . contains ( "counter." ) ) {
for ( Metric < ? > value : values ) {
this . writer . increment ( group , calculateDelta ( value ) ) ;
}
}
else {
this . writer . set ( group , values ) ;
}
}
private Delta < ? > calculateDelta ( Metric < ? > value ) {
long delta = value . getValue ( ) . longValue ( ) ;
Long old = this . counts . replace ( value . getName ( ) , delta ) ;
if ( old ! = null ) {
delta = delta - old ;
}
else {
this . counts . putIfAbsent ( value . getName ( ) , delta ) ;
}
return new Delta < Long > ( value . getName ( ) , delta , value . getTimestamp ( ) ) ;
}
}