Created
September 30, 2022 15:51
-
-
Save kirshiyin89/595785c94b187840227a7fc492cba6cc to your computer and use it in GitHub Desktop.
custom counter
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
@Endpoint(id = "customEndpoint") | |
@Component | |
public class CustomEndpoint { | |
private final Counter myCounter; | |
@ReadOperation | |
public String customEndpoint(int id) { | |
HashMap<Integer, String> fruitsMap = new HashMap<>(); | |
fruitsMap.put(1, "kiwi"); | |
fruitsMap.put(2, "apple"); | |
fruitsMap.put(3, "banana"); | |
myCounter.increment(); | |
return fruitsMap.get(id); | |
} | |
public CustomEndpoint(MeterRegistry registry) { | |
myCounter = Counter | |
.builder("mycustomcounter") | |
.description("count url hits") | |
.register(registry); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment