Created
August 30, 2020 13:29
-
-
Save apuravchauhan/123d3640cf65607824754a012af9afa8 to your computer and use it in GitHub Desktop.
Spring Boot Application Integrated with Prometheus
This file contains hidden or 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
server.port=8082 | |
management.endpoint.prometheus.enabled=true | |
management.endpoints.web.exposure.include=info,health,prometheus |
This file contains hidden or 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
package com.apurav; | |
import java.util.Map; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.web.bind.annotation.GetMapping; | |
import org.springframework.web.bind.annotation.PostMapping; | |
import org.springframework.web.bind.annotation.RequestBody; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RestController; | |
import io.micrometer.core.instrument.MeterRegistry; | |
/** | |
* | |
* @author apuravchauhan | |
* | |
*/ | |
@SpringBootApplication | |
@RestController | |
@RequestMapping("/") | |
public class PrometheusSpringBoot { | |
private final MeterRegistry meterRegistry; | |
public PrometheusSpringBoot(MeterRegistry meterRegistry) { | |
this.meterRegistry = meterRegistry; | |
} | |
@GetMapping("/2xx") | |
public String simulate2xxResponse() { | |
meterRegistry.counter("orders.2xx","status","OK").increment(); | |
return "Got 2xx Response"; | |
} | |
@GetMapping("/5xx") | |
public String simulate5xxResponse() { | |
meterRegistry.counter("orders.5xx","status","NOTOK").increment(); | |
return "Got 5xx Response"; | |
} | |
@PostMapping("/alert-hook") | |
public void receiveAlertHook(@RequestBody Map request) throws Exception { | |
System.out.println(request); | |
} | |
public static void main(String[] args) { | |
SpringApplication.run(PrometheusSpringBoot.class, args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment