2.配置org.springframework.boot spring-boot-starter-actuatorio.micrometer micrometer-registry-prometheus1.7.3
server: port: 10200 servlet: context-path: / spring: application: name: lys-openstack devtools: remote: restart: enabled: true thymeleaf: cache: false prefix: classpath:/templates encoding: UTF-8 suffix: .html mode: LEGACYHTML5 management: endpoints: web: exposure: include: "*" metrics: tags: application: lys-openstack endpoint: metrics: enabled: true prometheus: enabled: true info: enabled: true3.修改启动类
package com.lys; import io.micrometer.core.instrument.MeterRegistry; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; @SpringBootApplication public class AppApplication { public static void main(String[] args) { SpringApplication.run(AppApplication.class, args); } @Bean MeterRegistryCustomizer4.验证configurer( @Value("${spring.application.name}") String applicationName) { return (registry) -> registry.config().commonTags("application", applicationName); } }
http://localhost:10200/actuator/prometheus
5.Prometheus配置# 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=` to any timeseries scraped from this config. - job_name: "prometheus" # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ["localhost:9090"] #通过配置file 获取target,这里以lys-web项目进行举例 - job_name: 'lys-other' #metrics_path: /metrics file_sd_configs: - files: - host.json - job_name: 'container' static_configs: - targets: ['10.6.8.184:8080'] # 本地 cadvisor 访问地址 - job_name: 'rds' metrics_path: /actuator/prometheus static_configs: - targets: ['10.6.9.35:10200'] # 本地 springboot 访问地址
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#actuator.endpoints.enabling
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)