当前位置:   article > 正文

搭建Grafana+Prometheus监控Spring Boot应用

搭建Grafana+Prometheus监控Spring Boot应用

Spring项目改造

maven依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

Spring配置

management.endpoints.web.exposure.include=*
management.metrics.tags.application=${spring.application.name}
  • 1
  • 2

搭建prometheus

下载Prometheus镜像

docker pull prom/prometheus
  • 1

创建prometheus配置

/opt/docker/prometheus/config目录下创建prometheus.yml

# 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: '/actuator/prometheus'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["10.10.10.10:9090"]

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

targets配置目标java应用的ip端口,例如10.10.10.10:9090

启动Prometheus

docker run -d -p 9090:9090 --name prom \
-v /opt/docker/prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus
  • 1
  • 2
  • 3

可以查看容器启动日志确认是否启动成功:

docker logs xxxx
  • 1

访问http://xxxxxxxxxx:9090即可
在这里插入图片描述

搭建Grafana

docker pull grafana/grafana
docker run -d --name grafana -p 3000:3000 grafana/grafana
  • 1
  • 2

访问http://localhost:3000
在这里插入图片描述

配置prometheus数据源

在这里插入图片描述

配置Dashboards

下载模板

Dashboards模板下载地址:https://grafana.com/grafana/dashboards/

导入模板

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/399318?site
推荐阅读
相关标签
  

闽ICP备14008679号