-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from beverly-hills-money-gangster/micro-meter-…
…metrics Add micrometer + up version 2.4.0
- Loading branch information
Showing
8 changed files
with
77 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
server/src/main/java/com/beverly/hills/money/gang/meter/RequestsMeter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.beverly.hills.money.gang.meter; | ||
|
||
import com.beverly.hills.money.gang.exception.GameLogicError; | ||
import io.micrometer.core.instrument.Clock; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Timer; | ||
import io.micrometer.jmx.JmxConfig; | ||
import io.micrometer.jmx.JmxMeterRegistry; | ||
|
||
import java.util.Locale; | ||
|
||
public class RequestsMeter { | ||
|
||
private final Timer requestTimer; | ||
|
||
private final MeterRegistry meterRegistry = new JmxMeterRegistry(JmxConfig.DEFAULT, Clock.SYSTEM); | ||
|
||
public RequestsMeter(final String name) { | ||
this.requestTimer = Timer.builder("app.timer." + name.toLowerCase(Locale.ENGLISH)) | ||
.description("Request processing time") | ||
.register(meterRegistry); | ||
} | ||
|
||
public void runAndMeasure(MeasureRunnable r) throws GameLogicError { | ||
Timer.Sample sample = Timer.start(meterRegistry); | ||
try { | ||
r.run(); | ||
} finally { | ||
sample.stop(requestTimer); | ||
} | ||
} | ||
|
||
@FunctionalInterface | ||
public interface MeasureRunnable { | ||
void run() throws GameLogicError; | ||
} | ||
} |