SpringBoot集成Prometheus 01

一、Prometheus集成

1、再pom文件中添加如下配置

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

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

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

2、添加yum配置文件

management:
  server:
    port: 11001
  endpoints:
    web:
      exposure:
        include: prometheus,health

3、在启动类中添加入下代码,用于注册统一tag名,便于查询

     方案1:添加配置文件 (低版本没tags属性:譬如 2.0.9.RELEASE)

 

    方案2:注册代码

@Bean
MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String applicationName){
    return registry -> registry.config().commonTags("application", applicationName);
}

4、启动项目访问:http://127.0.0.1:11001/actuator/prometheus

二、Prometheus监控

1、下载Prometheus

      官网:https://prometheus.io/download/

      地址:https://prometheus.io/download/prometheus-2.21.0.linux-amd64.tar.gz

2、 解压并修改配置

    修改 prometheus.yml

    scrape_configs:
      - job_name: 'prometheus-job1'

        metrics_path: '/actuator/prometheus'
        static_configs:
        - targets: ['127.0.0.1:11001']

3、启动Prometheus

     ./prometheus --config.file="prometheus.yml" &

4、访问  http://192.168.158.200:9090/targets

三、配置Grafana 监控

1、  下载Grafana

      官网:https://grafana.com/grafana/download?platform=linux

      地址:https://dl.grafana.com/oss/release/grafana-7.1.5.linux-amd64.tar.gz

2、解压启动grafana

     bin/grafana-server &

3、访问 http://192.168.158.200:3000/

  1)、添加Prometheus数据源

2、添加监控DashBoard

  1)添加监控 JVM 的 Dashboard ,导入模板编号为 4701

 1)添加自定panel,点击右上角添加新panel

 

以上!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值