0%
Monitoring with Prometheus and Grafana

Monitoring with Prometheus and Grafana

Monitoring microservices

10-15 min

Monitoring with Prometheus and Grafana

In this chapter, we will explore how to set up a complete monitoring system with Prometheus and Grafana. We will see how to collect, store, and visualize our microservices' metrics.

1. Configuring Prometheus

Starting Prometheus

docker run -d -p 9090:9090 \
  -v /path/to/prometheus.yml:/etc/prometheus/prometheus.yml \
  prom/prometheus

Basic configuration

# prometheus.yml
global:
  scrape_interval: 15s
  evaluation_interval: 15s

scrape_configs:
  - job_name: 'spring-boot-app'
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['localhost:8080']

2. Configuring the Applications

Dependencies

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

Actuator configuration

# application.yml
management:
  endpoints:
    web:
      exposure:
        include: health,info,metrics,prometheus
  endpoint:
    health:
      show-details: always
  metrics:
    tags:
      application: ${spring.application.name}
    distribution:
      percentiles-histogram:
        http.server.requests: true
      sla:
        http.server.requests: 10ms, 50ms, 100ms, 200ms, 500ms

Comments

Comments are powered by GitHub Discussions

Sign in with GitHub to join the discussion

Link copied!