Skip to content

Instantly share code, notes, and snippets.

@kirshiyin89
Created September 30, 2022 15:51
Show Gist options
  • Save kirshiyin89/595785c94b187840227a7fc492cba6cc to your computer and use it in GitHub Desktop.
Save kirshiyin89/595785c94b187840227a7fc492cba6cc to your computer and use it in GitHub Desktop.
custom counter
@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