diff --git a/backend/build.gradle b/backend/build.gradle index 7308627..ab79616 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -30,6 +30,10 @@ dependencies { compile("io.springfox:springfox-swagger2:" + SPRINGFOX_VERSION) compile("io.springfox:springfox-swagger-ui:" + SPRINGFOX_VERSION) + compile('org.springframework.boot:spring-boot-starter-actuator') + compile("io.micrometer:micrometer-spring-legacy:latest.release") + compile("io.micrometer:micrometer-registry-prometheus:1.0.4") + compileOnly('org.projectlombok:lombok') runtimeOnly name: 'frontend' @@ -49,4 +53,4 @@ afterEvaluate { jar { baseName = 'spring-react' version = '0.0.1' -} \ No newline at end of file +} diff --git a/backend/src/main/java/com/allstate/springreact/controller/StateController.java b/backend/src/main/java/com/allstate/springreact/controller/StateController.java index cdc8c1e..5fdad47 100644 --- a/backend/src/main/java/com/allstate/springreact/controller/StateController.java +++ b/backend/src/main/java/com/allstate/springreact/controller/StateController.java @@ -1,13 +1,28 @@ package com.allstate.springreact.controller; import com.allstate.springreact.domain.InitialState; +import io.micrometer.core.instrument.Counter; +import io.micrometer.core.instrument.MeterRegistry; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController class StateController { + private Counter counter; + + @Autowired + public StateController(MeterRegistry registry) { + /* + This value is already exposed under the 'http_server_requests_seconds_count' metric, + but I wanted to show how to wire up a counter if desired + */ + counter = Counter.builder("initial-endpoint-call-count").register(registry); + } + @GetMapping("/state") public InitialState getInitialCountRequest() { + counter.increment(); InitialState state = new InitialState(); state.setText("Spring-React is wired up!"); state.setValue(7); diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index d55abb4..3910f8b 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -1,2 +1,19 @@ +spring.application.name: spring-react + server: port: ${PORT:8080} + +# Enable the /prometheus endpoint to be publicly accessible +endpoints: + prometheus: + sensitive: false + +management.metrics: + distribution: + # Enable publishing of histogram metrics to allow for computing aggregable percentile approximations + percentiles-histogram[http.server.requests]: true + # Publish the median and 95th percentile values + percentiles[http.server.requests]: 0.5, 0.95 + tags: + # Add a custom label to each metric name to differentiate from other services + application: ${spring.application.name}