-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introducing micrometer/prometheus metric collection #105
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,17 +85,42 @@ ENV SPRING_PROFILES_ACTIVE docker,mysql | |
In the `mysql section` of the `application.yml` from the [Configuration repository], you have to change | ||
the host and port of your MySQL JDBC connection string. | ||
|
||
## Custom metrics monitoring | ||
|
||
@todo Add default custom dashboards to grafana | ||
|
||
Grafana and Prometheus are included in the `docker-compose.yml` configuration, and the public facing applications have been instrumented with [MicroMeter](https://micrometer.io) to collect JVM and custom business metrics. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For development, does the application work if Grafana and Prometheus are not started? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no dependency on those services at runtime. This implementation produces an additional endpoint on the actuator which is scraped by prometheus. |
||
|
||
### Using Prometheus | ||
|
||
* Prometheus can be accessed from your local machine at http://localhost:9091 | ||
|
||
### Using Grafana with Prometheus | ||
|
||
* Login to Grafana at http://localhost:3000, the default user/pass is `admin:admin`, you will be prompted to change your password. | ||
* Setup a prometheus datasource and point the URL to `http://prometheus-server:9090`, leave all the other options set to their default. | ||
* Add the [Micrometer/SpringBoot dashboard](https://grafana.com/dashboards/4701) via the Import Dashboard menu item. The id for the dashboard is `4701` | ||
|
||
### Custom metrics implementation | ||
|
||
* `customers-service` application has the following custom metrics enabled: | ||
* counter: `create.owner` | ||
* counter: `update.owner` | ||
* counter: `create.pet` | ||
* counter: `update.pet` | ||
* `visits-service` application has the following custom metrics enabled: | ||
* counter: `create.visit` | ||
|
||
## Looking for something in particular? | ||
|
||
| Spring Cloud components | Resources | | ||
|-------------------------|------------| | ||
| Configuration server | [Config server properties](spring-petclinic-config-server/src/main/resources/application.yml) and [Configuration repository] | | ||
| Service Discovery | [Eureka server](spring-petclinic-discovery-server) and [Service discovery client](spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/VetsServiceApplication.java) | | ||
| API Gateway | [Zuul reverse proxy](spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/ApiGatewayApplication.java) and [Routing configuration](https://github.com/spring-petclinic/spring-petclinic-microservices-config/blob/master/api-gateway.yml) | | ||
| Docker Compose | [Spring Boot with Docker guide](https://spring.io/guides/gs/spring-boot-docker/) and [docker-compose file](docker-compose.yml) | | ||
| Circuit Breaker | [Circuit Breaker with Hystrix guide](https://spring.io/guides/gs/circuit-breaker/) and [fallback method configuration](spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/application/VisitsServiceClient.java) | | ||
| Graphite Monitoring | TBD | | ||
| Spring Cloud components | Resources | | ||
|---------------------------------|------------| | ||
| Configuration server | [Config server properties](spring-petclinic-config-server/src/main/resources/application.yml) and [Configuration repository] | | ||
| Service Discovery | [Eureka server](spring-petclinic-discovery-server) and [Service discovery client](spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/VetsServiceApplication.java) | | ||
| API Gateway | [Zuul reverse proxy](spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/ApiGatewayApplication.java) and [Routing configuration](https://github.com/spring-petclinic/spring-petclinic-microservices-config/blob/master/api-gateway.yml) | | ||
| Docker Compose | [Spring Boot with Docker guide](https://spring.io/guides/gs/spring-boot-docker/) and [docker-compose file](docker-compose.yml) | | ||
| Circuit Breaker | TBD | | ||
| Grafana / Prometheus Monitoring | [Micrometer implementation](https://micrometer.io/) | | ||
|
||
Front-end module | Files | | ||
|-------------------|-------| | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM prom/prometheus:v2.4.2 | ||
ADD prometheus.yml /etc/prometheus/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# my global config | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any configuration to commit in the config git repository; https://github.com/spring-petclinic/spring-petclinic-microservices-config ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch! There is. I'll fork that and create a PR for those changes. |
||
global: | ||
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. | ||
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. | ||
# scrape_timeout is set to the global default (10s). | ||
|
||
# A scrape configuration containing exactly one endpoint to scrape: | ||
# Here it's Prometheus itself. | ||
scrape_configs: | ||
- job_name: prometheus | ||
static_configs: | ||
- targets: ['localhost:9090'] | ||
|
||
- job_name: api-gateway | ||
metrics_path: /actuator/prometheus | ||
static_configs: | ||
- targets: ['api-gateway:8080'] | ||
|
||
- job_name: customers-service | ||
metrics_path: /actuator/prometheus | ||
static_configs: | ||
- targets: ['customers-service:8081'] | ||
|
||
- job_name: visits-service | ||
metrics_path: /actuator/prometheus | ||
static_configs: | ||
- targets: ['visits-service:8082'] | ||
|
||
- job_name: vets-service | ||
metrics_path: /actuator/prometheus | ||
static_configs: | ||
- targets: ['vets-service:8083'] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
*/ | ||
package org.springframework.samples.petclinic.customers.web; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
|
@@ -40,13 +41,15 @@ | |
class OwnerResource { | ||
|
||
private final OwnerRepository ownerRepository; | ||
private final MeterRegistry registry; | ||
|
||
/** | ||
* Create Owner | ||
*/ | ||
@PostMapping | ||
@ResponseStatus(HttpStatus.CREATED) | ||
public void createOwner(@Valid @RequestBody Owner owner) { | ||
registry.counter("create.owner").increment(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about using @Timed? If we use it instead of manually incrementing metrics, tests will be alse simplified. IMHO there is little profit in measuring number of requests - Prometheus has metrics for RPS etc.) https://spring.io/blog/2018/03/16/micrometer-spring-boot-2-s-new-application-metrics-collector There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. I'm delivering the workshop today so once that's done I'll make this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @notsureifkevin do you any time to make the change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://micrometer.io/docs/concepts#_the_code_timed_code_annotation It's not clear to me how to use this annotation and I'm constrained for time as-is. You're welcome to use merge this PR as-is, attempt to make these modifications yourself, or drop it completely. I've rebased atop master, so it should be good to go as-is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mszarlinski I propose to merge this PR and create an issue for improvment. I could work on it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've created the #120 in order to merge this PR then improve it. |
||
ownerRepository.save(owner); | ||
} | ||
|
||
|
@@ -81,6 +84,7 @@ public Owner updateOwner(@PathVariable("ownerId") int ownerId, @Valid @RequestBo | |
ownerModel.setAddress(ownerRequest.getAddress()); | ||
ownerModel.setTelephone(ownerRequest.getTelephone()); | ||
log.info("Saving owner {}", ownerModel); | ||
registry.counter("update.owner").increment(); | ||
return ownerRepository.save(ownerModel); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe in a docs/ folder or a gh-pages branch?
I have also to reupload the Spring Petcilinic screenshot of thr readme.md. The link is broken: https://cloud.githubusercontent.com/assets/838318/19653851/61c1986a-9a16-11e6-8b94-03fd7f775bb3.png
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, screenshots of the default dashboard setup in the meantime until the custom metrics dashboard can be built out and included in a custom image build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For information,
docs/
folder has been introduced in the PR #106