Sentinel k8s MetricFetcher [ java.net.NoRouteToHostException: No route to host ]

rn0zuynd  于 4个月前  发布在  Java
关注(0)|答案(1)|浏览(137)

Issue Description

Type: bug report or feature request

Describe what happened (or what feature you want)

k8s环境部署的Sentinel-dashboard ,pod ip是 172.19.76.231,但是日志显示Sentinel ip是172.19.79.255,以至于 MetricFetcher 报错

报错日志如下:
2023-02-22 19:50:49.517 ERROR 1 --- [pool-5-thread-1] c.a.c.s.dashboard.metric.MetricFetcher   : fetch system  metric http://172.19.79.255:8719/systemStatus error

java.net.NoRouteToHostException: No route to host
	at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.8.0_191]
	at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717) ~[na:1.8.0_191]
	at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvent(DefaultConnectingIOReactor.java:171) [httpcore-nio-4.4.6.jar!/:4.4.6]
	at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:145) [httpcore-nio-4.4.6.jar!/:4.4.6]
	at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:348) [httpcore-nio-4.4.6.jar!/:4.4.6]
	at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:194) [httpasyncclient-4.1.3.jar!/:4.1.3]
	at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64) [httpasyncclient-4.1.3.jar!/:4.1.3]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_191]

Describe what you expected to happen

期望获取正确的pod ip

How to reproduce it (as minimally and precisely as possible)

Tell us your environment

  1. jdk: 8
  2. sentinel : 1.8
  3. system : k8s

Anything else we need to know?

0tdrvxhp

0tdrvxhp1#

获取ip的源代码:

import com.alibaba.csp.sentinel.log.RecordLog;
import lombok.extern.slf4j.Slf4j;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;

/**
 * Get host name and ip of the host.
 *
 * @author leyou
 */
@Slf4j
public final class HostNameUtil {

    private static String ip;
    private static String hostName;

    static {
        try {
            // Init the host information.
            resolveHost();
        } catch (Exception e) {
            RecordLog.error("Failed to get local host", e);
            log.error("Failed to get local host", e);
        }
    }

    public static void resolveHost() throws Exception {
        InetAddress addr = InetAddress.getLocalHost();
        hostName = addr.getHostName();
        ip = addr.getHostAddress();
        if (addr.isLoopbackAddress()) {
            // find the first IPv4 Address that not loopback
            Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
            while (interfaces.hasMoreElements()) {
                NetworkInterface in = interfaces.nextElement();
                Enumeration<InetAddress> addrs = in.getInetAddresses();
                while (addrs.hasMoreElements()) {
                    InetAddress address = addrs.nextElement();
                    if (!address.isLoopbackAddress() && address instanceof Inet4Address) {
                        ip = address.getHostAddress();
                    }
                }
            }
        }
    }

    public static String getIp() {
        return ip;
    }

    public static String getHostName() {
        return hostName;
    }

相关问题