• 容器环境 springcloud gateway grafana prometheus采集集成与问题


    容器环境 springcloud gateway grafana prometheus采集集成与问题

    大家好,我是烤鸭:
        记录下网关上容器后,监控升级的过程。

    原来的方式

    grafana 和 prometheus 网上教程很多,就不细写了。

    没上容器之前,可以在 prometheus 的配置文件配置具体的ip地址,进行监控数据拉取。

    上了容器之后就不行了,每次发布ip都是动态的。

    初次接入

    prometheus 有个pushgateway的插件,支持被动接受数据的方式。

    网上的开源项目

    https://github.com/prometheus/pushgateway

    cloud的项目pom中引入:

    
       io.prometheus
       simpleclient_servlet
       0.9.0
    
    
       io.prometheus
       simpleclient_pushgateway
       0.9.0
     
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    bootstrap.yml增加配置:

    management:
      metrics:
        export:
          prometheus:
            pushgateway:
              enabled: true
              push-rate: 60s
              base-url: 192.168.1.1:9091 #pushgateway地址
              job: xxx-gateway-job  #job名称
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    接入的问题

    由于第一次没添加ip的上报,导致数据上报的时候都集中在一起,外加频率间隔过大,生成的图也很不好看。

    在这里插入图片描述

    解决方案

    修改yml增加配置:

    management:
      metrics:
        export:
          prometheus:
            pushgateway:
              enabled: true
              push-rate: 15s #缩短push频率
              base-url: 192.168.1.1:9091 #pushgateway地址
              job: xxx-gateway-job  #job名称
              groupingKey:
                instance: ${xxxx.prometheus.instance}  ##配置这个属性需单独引入ip
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    ip获取工具类

    @Configuration
    @ConditionalOnProperty(prefix = "management.metrics.export.prometheus.pushgateway", name = "enabled", havingValue = "true",
            matchIfMissing = false)
    public class PrometheusTagConfig {
    
        @Bean
        MeterRegistryCustomizer configurer() {
            String ip = this.findFirstNonLoopbackAddress();
            System.setProperty("xxxx.prometheus.instance", ip);
            return (registry) -> registry.config().commonTags("instance", ip);
        }
    
        /***
         * 获取ip
         * @date 2022/9/16 14:42
         * @return java.lang.String
         */
        private String findFirstNonLoopbackAddress() {
            try {
                InetAddress result = null;
                int lowest = Integer.MAX_VALUE;
                for (Enumeration nics = NetworkInterface.getNetworkInterfaces();
                     nics.hasMoreElements(); ) {
                    NetworkInterface ifc = nics.nextElement();
                    if (ifc.isUp()) {
                        if (ifc.getIndex() < lowest || result == null) {
                            lowest = ifc.getIndex();
                        } else if (result != null) {
                            continue;
                        }
                        for (Enumeration addrs = ifc.getInetAddresses(); addrs.hasMoreElements(); ) {
                            InetAddress address = addrs.nextElement();
                            if (address instanceof Inet4Address && !address.isLoopbackAddress()) {
                                result = address;
                            }
                        }
                    }
                }
                return result != null ? result.getHostAddress() : null;
            } catch (Exception e) {
            }
            return null;
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44

    现在采集的可以区分ip,而且频率看的曲线比较适合观看。

    在这里插入图片描述

  • 相关阅读:
    docker安装es分词插件ik详情步骤
    【ShuQiHere】探索人工智能核心:机器学习的奥秘
    TypeError: RedLock is not a constructor.
    【前端】记录各种控制台警告/bug
    tinymce富文本编辑器做评论区
    github小记(一):清除github在add或者commit之后缓存区
    获取外网IP接口
    Vue3基础部分
    醛肽:Gly-Phe-Gly-aldehyde、102579-48-6
    leaflet教程021:加载Stadia地图(多种形式)
  • 原文地址:https://blog.csdn.net/Angry_Mills/article/details/127694678