• 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个应用的监控大盘。

    结束。

  • 相关阅读:
    iOS-禁止scrollview垂直方向滚动,只允许水平方向滚动;或只允许垂直方向滚动
    MongoDB安装
    Vue运用
    egg-middleware 中间件
    如何判断扫码的客户端是微信还是支付宝
    node 短信接口的调用
    Mui 长按保存图片
    egg-sequelize --- nodejs
    egg-mongoose --- nodejs
    Mongoose 基本用法
  • 原文地址:https://www.cnblogs.com/shileibrave/p/14544513.html
Copyright © 2020-2023  润新知