Xray-core
                                
                                
                                
                                    Xray-core copied to clipboard
                            
                            
                            
                        observatory 定时检测的问题
observatory:
    probeInterval: 60m
    probeURL: https://example.com
    subjectSelector:
     - Proxy
2023/12/31 19:04:08 [Warning] core: Xray 1.8.6 started
2023/12/31 19:04:08 [Info] app/dispatcher: taking platform initialized detour [Proxy1] for [tcp:example.com:443]
2023/12/31 19:04:08 [Info] transport/internet/tcp: dialing TCP to tcp:192.168.123.203:1089
2023/12/31 19:04:08 [Debug] transport/internet: dialing to tcp:192.168.123.203:1089
2023/12/31 19:04:13 [Info] app/observatory: the outbound Proxy1 is dead: > app/observatory: GET request failed:app/observatory: outbound failed to relay connection > Get "https://example.com": net/http: TLS handshake timeout (Client.Timeout exceeded while awaiting headers) > app/observatory: with outbound handler report > app/observatory: underlying connection failed > app/observatory: failed to produce report
2023/12/31 19:04:23 [Info] transport/internet/tcp: dialing TCP to tcp:192.168.123.203:1089
2023/12/31 19:04:26 [Debug] transport/internet: dialing to tcp:192.168.123.203:1089
可以看到 observatory 检测 the outbound Proxy1 is dead 之后, 就不会管后面的 Proxy2, Proxy3... 必须等 probeInterval: 60分钟过后才检测.
于是我验证了下设置 probeInterval: 10s 确实是如此:
xray run -c config.yaml | grep "app/observatory"
2023/12/31 19:08:40 [Info] app/observatory: the outbound Proxy1 is dead: > app/observatory: GET request failed:app/observatory: outbound failed to relay connection > Get "https://example.com": net/http: TLS handshake timeout (Client.Timeout exceeded while awaiting headers) > app/observatory: with outbound handler report > app/observatory: underlying connection failed > app/observatory: failed to produce report
2023/12/31 19:08:51 [Info] app/observatory: the outbound Proxy2 is alive:0.70848
2023/12/31 19:09:04 [Info] app/observatory: the outbound Proxy3 is dead: > app/observatory: GET request failed:app/observatory: outbound failed to relay connection > Get "https://example.com": context deadline exceeded (Client.Timeout exceeded while awaiting headers) > app/observatory: with outbound handler report > app/observatory: underlying connection failed > app/observatory: failed to produce report
2023/12/31 19:09:17 [Info] app/observatory: the outbound Proxy1 is dead: > app/observatory: GET request failed:app/observatory: outbound failed to relay connection > Get "https://example.com": net/http: TLS handshake timeout (Client.Timeout exceeded while awaiting headers) > app/observatory: with outbound handler report > app/observatory: underlying connection failed > app/observatory: failed to produce report
是否可以增加这种一次全部检测的方式. 这样一开始就可以直接排除掉 dead 的服务器, 而不是要等 probeInterval * n 花很长时间才能排除.
发现 v2ray 支持了 MultiObservatory 可以解决这个问题. 但是 xray 并不支持. 以下是 v2ray 下可用配置.
MultiObservatory:
    observers:
      - type: default
        settings:
            probeInterval: 60m
            probeURL: http://connectivitycheck.gstatic.com/generate_204
            subjectSelector:
               - Proxy1
      - type: default
        settings:
            probeInterval: 60m
            probeURL: http://connectivitycheck.gstatic.com/generate_204
            subjectSelector:
               - Proxy2
它的实现在这里: https://github.com/v2fly/v2ray-core/blob/master/infra/conf/v4/observatory.go