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

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

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</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><version>1.1.4</version></dependency>

配置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<MeterRegistry> 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. 进入仪表盘查看相应的监控指标;
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容