spring boot监控之prometheus配置
Posted Season
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring boot监控之prometheus配置相关的知识,希望对你有一定的参考价值。
1,spring boot工程引入jar包
compile ‘org.springframework.boot:spring-boot-starter-actuator‘ compile ‘io.micrometer:micrometer-core:1.3.5‘ compile ‘io.micrometer:micrometer-registry-prometheus:1.3.5‘
2,修改spring boot工程配置
management: server: port: 10091 endpoints: web: exposure: include: ‘*‘
3,监控代码示例
Counter counter = Metrics.counter("counter", "tag-1", "tag-2");
counter.increment();
4, 启动Spring boot工程
启动后访问http://localhost:10091/actuator,应该能看到返回很多链接,如能看到http://localhost:10091/actuator/prometheus, 说明正确。
5,安装配置prometheus
下载安装后后,修改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: [‘localhost:10091‘]
6, 启动prometheus,查看运行效果
以上是关于spring boot监控之prometheus配置的主要内容,如果未能解决你的问题,请参考以下文章
使用 Prometheus + Grafana + Spring Boot Actuator 监控应用
最佳实践|Spring Boot 应用如何快速接入 Prometheus 监控
使用 Prometheus 监控 Kubernetes 集群中的 Spring Boot 应用程序
Spring Boot Actuator 整合 Prometheus