Spring Cloud 之 Prometheus+Grafana+Eureka實現動態微服務監控(二十二)


上一篇我們講了Prometheus和Grafana集成實現微服務JVM監控(傳送門:Spring Cloud 之 Prometheus+Grafana監控微服務(二十一) ),但是不知道大家有沒有注意到,我們沒增加一個服務都要修改prometheus.yml配置,還要重啟Prometheus。大公司可能每周都會有新的微服務應用誕生,甚至每天都有。頻繁的重啟Prometheus肯定是不行的。所以本篇講一下基於Eureka服務發現實現普羅米修斯數據采集。

 

本篇跳過Prometheus和Grafana安裝及運行,不知道的小伙伴請看上一篇,下面切入正題。

1、修改x-demo-springcloud-pay-service的build.gradle文件

dependencies {
    compile("org.springframework.cloud:spring-cloud-starter-netflix-eureka-client")
    compile("org.springframework.cloud:spring-cloud-starter-zipkin")
    compile("org.springframework.cloud:spring-cloud-stream-binder-rabbit")
    compile("org.springframework.cloud:spring-cloud-starter-netflix-ribbon")
    compile("io.micrometer:micrometer-registry-prometheus")

}

 

2、修改啟動類

/**
 * @author Leo
 */
@SpringBootApplication
@EnableEurekaClient
@RestController
public class PayServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(PayServerApplication.class, args);
    }

    @Bean MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String applicationName) {
        return registry -> registry.config().commonTags("application", applicationName);
    }
}

到這里應用改造就完成了。bootstrap.yml可以不修改。

3、prometheus.yml配置修改

我們把之前的SpringBoot應用配置注釋掉,增加了job_name名稱為eureka的配置,server配置為eureka注冊中心的地址。

 

 

改造過程中順手把x-demo-springcloud-order-service和x-demo-springcloud-user-service也一並修改了。

4、重啟Prometheus.exe以及應用。

訪問:http://localhost:9090/classic/targets,如下圖,可以看到Prometheus已經可以正常采集8085,8086,8087應用數據了。其中兩個DOWN狀態的應用是apollo的配置中心和后端接口服務,不用管。

 

 

訪問Grafana UI:http://localhost:3000/,如下圖,可以看到Grafana也可以正常看到3個應用的監控大盤。

 

 

結束。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM