普罗米修斯Prometheus(4) - springboot集成

这里以spring boot2.2.2为例
在pom.xml中添加依赖

org.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-starter-jdbcorg.springframework.bootspring-boot-starter-aoporg.springframework.bootspring-boot-starter-testorg.springframework.bootspring-boot-starter-actuatorio.micrometermicrometer-registry-prometheus1.1.4

配置application.yml

management:  
  metrics:    
    tags:      application: ${spring.application.name}  
  endpoints:    
    web:      
      exposure:        include: "*"    
    health:      show-details: always

配置启动类application

@SpringBootApplicationpublic class Springboot2PrometheusApplication {    public static void main(String[] args) {        SpringApplication.run(Springboot2PrometheusApplication.class, args);    }    @Bean    MeterRegistryCustomizer configurer(@Value("${spring.application.name}") String applicationName){        return registry -> registry.config().commonTags("application", applicationName);    }}

配置prometheus的job,修改prometheus.yml,端口号对应application.yml的server.port,检查端口开放状态

- job_name: 'mxr-sdk-server_springboot_prometheus'    
scrape_interval: 5s    
metrics_path: '/actuator/prometheus'    
static_configs:      - targets: ['localhost:10000']

重启prometheus

# systemctl restart prometheus.service

浏览http://你的服务器ip:9090/targets

配置Grafana 监控 JVM 的Dashboard模板,模板id:4701

// 配置Prometheus Micrometer仪表盘
1. 在左侧边栏选择Dashboards --> Manage 菜单;
2. 在主界面,点击import按钮;
3. Granfana.com Dashboard中填写4701,自动跳转到import详情界面;可以通过以下地址查询更多模板:https://grafana.com/grafana/dashboards?dataSource=prometheus&collector=nodeExporter
4. Prometheus Data Source选择上面的数据源名称,点击import按钮;
5. 进入仪表盘查看相应的监控指标;

你可能感兴趣的:(普罗米修斯Prometheus(4) - springboot集成)