33
33
import java .util .concurrent .ScheduledFuture ;
34
34
import java .util .concurrent .TimeUnit ;
35
35
import java .util .concurrent .atomic .AtomicInteger ;
36
+ import java .util .function .BiFunction ;
36
37
import java .util .function .Function ;
37
38
import java .util .function .Supplier ;
38
39
import org .slf4j .Logger ;
@@ -108,6 +109,8 @@ private long getConsumedCount() {
108
109
109
110
@ Override
110
111
public void start (String description ) throws Exception {
112
+ long startTime = System .nanoTime ();
113
+
111
114
String metricPublished = "rabbitmqStreamPublished" ;
112
115
String metricProducerConfirmed = "rabbitmqStreamProducer_confirmed" ;
113
116
String metricConsumed = "rabbitmqStreamConsumed" ;
@@ -150,14 +153,18 @@ public void start(String description) throws Exception {
150
153
.entrySet ()
151
154
.forEach (entry -> meters .put (entry .getValue (), registryMeters .get (entry .getKey ())));
152
155
153
- Map <String , Function <Meter , String >> formatMeter = new HashMap <>();
156
+ Map <String , BiFunction <Meter , Duration , String >> formatMeter = new HashMap <>();
154
157
metersNamesAndLabels .entrySet ().stream ()
155
158
.filter (entry -> !entry .getKey ().contains ("bytes" ))
156
159
.forEach (
157
160
entry -> {
158
161
formatMeter .put (
159
162
entry .getValue (),
160
- meter -> String .format ("%s %.0f msg/s, " , entry .getValue (), meter .getMeanRate ()));
163
+ (meter , duration ) -> {
164
+ double rate =
165
+ duration .getSeconds () <= 5 ? meter .getMeanRate () : meter .getOneMinuteRate ();
166
+ return String .format ("%s %.0f msg/s, " , entry .getValue (), rate );
167
+ });
161
168
});
162
169
163
170
metersNamesAndLabels .entrySet ().stream ()
@@ -166,7 +173,11 @@ public void start(String description) throws Exception {
166
173
entry -> {
167
174
formatMeter .put (
168
175
entry .getValue (),
169
- meter -> formatByteRate (entry .getValue (), meter .getMeanRate ()) + ", " );
176
+ (meter , duration ) -> {
177
+ double rate =
178
+ duration .getSeconds () <= 5 ? meter .getMeanRate () : meter .getOneMinuteRate ();
179
+ return formatByteRate (entry .getValue (), rate ) + ", " ;
180
+ });
170
181
});
171
182
172
183
Histogram chunkSize = metricRegistry .getHistograms ().get (metricChunkSize );
@@ -195,6 +206,7 @@ public void start(String description) throws Exception {
195
206
() -> {
196
207
try {
197
208
if (checkActivity ()) {
209
+ Duration duration = Duration .ofNanos (System .nanoTime () - startTime );
198
210
StringBuilder builder = new StringBuilder ();
199
211
builder .append (reportCount .get ()).append (", " );
200
212
meters
@@ -203,7 +215,7 @@ public void start(String description) throws Exception {
203
215
entry -> {
204
216
String meterName = entry .getKey ();
205
217
Meter meter = entry .getValue ();
206
- builder .append (formatMeter .get (meterName ).apply (meter ));
218
+ builder .append (formatMeter .get (meterName ).apply (meter , duration ));
207
219
});
208
220
builder .append (formatLatency .apply (latency )).append (", " );
209
221
builder .append (formatChunkSize .apply (chunkSize ));
@@ -222,8 +234,6 @@ public void start(String description) throws Exception {
222
234
1 ,
223
235
TimeUnit .SECONDS );
224
236
225
- long start = System .currentTimeMillis ();
226
-
227
237
this .closingSequence =
228
238
() -> {
229
239
consoleReportingTask .cancel (true );
@@ -232,18 +242,19 @@ public void start(String description) throws Exception {
232
242
233
243
scheduledExecutorService .shutdownNow ();
234
244
235
- long duration = System .currentTimeMillis () - start ;
245
+ Duration d = Duration .ofNanos (System .nanoTime () - startTime );
246
+ Duration duration = d .getSeconds () <= 0 ? Duration .ofSeconds (1 ) : d ;
236
247
237
248
Function <Map .Entry <String , Meter >, String > formatMeterSummary =
238
249
entry -> {
239
250
if (entry .getKey ().contains ("bytes" )) {
240
251
return formatByteRate (
241
- entry .getKey (), entry .getValue ().getCount () * 1000 / duration )
252
+ entry .getKey (), entry .getValue ().getCount () / duration . getSeconds () )
242
253
+ ", " ;
243
254
} else {
244
255
return String .format (
245
256
"%s %d msg/s, " ,
246
- entry .getKey (), entry .getValue ().getCount () * 1000 / duration );
257
+ entry .getKey (), entry .getValue ().getCount () / duration . getSeconds () );
247
258
}
248
259
};
249
260
0 commit comments