spring boot 監控 prometheus + grafana

一、spring boot maven 引入jarweb

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

yml 配置 添加以下配置spring

management:
  server:
    port: 9001
  endpoints:
    web:
      exposure:
        include: '*'
  endpoint:
    health:
      show-details: always
  metrics:
    export:
      prometheus:
        step: 1m
        enabled: true
        descriptions: true
    web:
      server:
        auto-time-requests: true

二、prometheus 配置 新增prometheus.yml配置文件docker

# my global config
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).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'spring'
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['localhost:9001']

docker 啓動以下數據庫

run --name prometheus -p 9090:9090 -v /home/user/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus --config.file=/etc/prometheus/prometheus.yml

查看:http://localhost:9090maven

三、grafana docker啓動以下spring-boot

run -d -p 3000:3000 --name=grafana grafana/grafana

grafana 的 prometheus數據庫配置 http://localhost:9090this

而後在Dashboards 中 import 看板lua

查看結果 http://localhost:3000code

相關文章
相關標籤/搜索