阅读量:0
Prometheus通过注册中心nacos、Eureka 实现服务注册自动发现监控
Prometheus通过Eureka 实现服务注册自动发现监控
使用 Prometheus 中的 Eureka (Service Discover)SD 来使用 Eureka REST API 来查询抓取目标。 Prometheus 将定期检查 REST 端点并为每个应用程序实例创建一个抓取目标
eureka配置(根据自己需要)
#启动服务时指定参数 --eureka.client.service-url.defaultZone=http://eureka-1:8761/eureka/,http://eureka-2:8761/eureka/,http://eureka-3:8761/eureka/ --eureka.client.register-with-eureka=true --eureka.client.fetch-registry=true --eureka.instance.prefer-ip-address=false
prometheus配置
- job_name: 'eureka-prometheus' metrics_path: '/actuator/prometheus' eureka_sd_configs: - server: "http://eureka-1:8761/eureka" - server: 'http://eureka-2:8761/eureka' - server: 'http://eureka-3:8761/eureka' relabel_configs: - source_labels: [__meta_eureka_app_name] target_label: application - action: drop regex: "eureka.*" source_labels: [instance]
prometheus通过nacos实现服务注册自动发现监控
github地址:https://github.com/typ431127/Nacos_check
前提:java服务要开启监控接口
如添加配置:
management.endpoints.web.exposure.include = prometheus,health,metrics management.health.defaults.enabled = false management.metrics.tags.application = ${spring.application.name} management.trace.http.enabled = false
启动脚本
解压后本地启动拉取nacos服务的脚本(指定监控的命名空间,并120s拉取一次)
cat /data/nacos_check/nacos-namespace-discovery.sh #!/bin/bash while true do /data/nacos_check/nacos-check --url http://nacos-1IP:8848,http://nacos-2IP:8848,http://nacos-3IP:8848 --namespace 7b32a553-76d2-47d9-bb7d-53be133ac347 -o /usr/local/prometheus/monitor/nacos/nacos-namespace-discovery.json sleep 120s done
prometheus配置
- job_name: 'nacos-services' scrape_timeout: 15s metrics_path: '/actuator/prometheus' file_sd_configs: - files: - '/usr/local/prometheus/monitor/nacos/*.json' refresh_interval: 15s