prometheus配置信息
- mq
- eureka:使用注册中心对接减少了配置,不然每个模块都要配置一次,
集成eureka
global:
scrape_interval: 5s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['prometheus:9090']
- job_name: 'linux-exporter'
metrics_path: /metrics
static_configs:
- targets: ['192.168.1.101:9110']
- job_name: rocketmq
static_configs:
- targets: ['192.168.1.101:5557']
labels:
instance: 192.168.1.101
- job_name: 'eureka'
metrics_path: '/actuator/prometheus' #springboot默认的actuator路径
# Scrape Eureka itself to discover new services.
eureka_sd_configs:
- server: http://192.168.1.101:8000/eureka #这里是Eureka注册地址
basic_auth:
username: web
password: 1
relabel_configs:
- source_labels: [__meta_eureka_app_instance_metadata_prometheus_path]
action: replace
target_label: __metrics_path__
regex: (.+)
# 增加一个自定义label sys_model 它的值从配置eureka中获取
- source_labels: ["__meta_eureka_app_instance_metadata_sys_module"]
action: replace
target_label: sys_module
regex: (.+)
访问prometheus:
springboot 客户端配置
启动类指定配置名称用来区分
@Bean
MeterRegistryCustomizer<MeterRegistry> metricsCommonTags(@Value("${spring.application.name}") String applicationName) {
return registry -> registry.config().commonTags("application", applicationName);
}
eureka:
instance:
preferIpAddress: true
# 向Server发送心跳间隔时间,单位为秒,默认为30
lease-renewal-interval-in-seconds: 5
# 过期清理时间,两次心跳间隔时间大于该值Server将剔除该服务,默认为90
lease-expiration-duration-in-seconds: 20
statusPageUrlPath: /doc.html
instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
metadata-map:
version: test
management:
context-path: '/${spring.application.name}/actuator'
# 集成到prometheus重新指定为下面配置的参数
"prometheus.scrape": "true"
"prometheus.path": "/${spring.application.name}/actuator/prometheus"
"sys.module": "${spring.application.name}"
ip-address: 192.168.1.203
client:
serviceUrl:
defaultZone: http://web:1@${server.ip-address}:8000/eureka/
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: always
logfile:
external-file: ./nr_cloud/logs/${spring.application.name}/${spring.application.name}_info.log
# 不启用 Micrometer 与 Hystrix 结合的度量指标的收集,引入actuator会无法启动
metrics:
binders:
hystrix:
enabled: false
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
在grafana中展示 ,可以使用其他图表