diff --git a/docs/.vuepress/config/sidebar/en.ts b/docs/.vuepress/config/sidebar/en.ts index af8de26..c9a631c 100755 --- a/docs/.vuepress/config/sidebar/en.ts +++ b/docs/.vuepress/config/sidebar/en.ts @@ -68,6 +68,7 @@ export const sidebarEn: SidebarConfig = { '/en/config/transports/quic.md', '/en/config/transports/tcp.md', '/en/config/transports/websocket.md', + '/en/config/transports/httpupgrade.md' ], }, ], diff --git a/docs/en/config/README.md b/docs/en/config/README.md index 7ef6815..66c1f4c 100644 --- a/docs/en/config/README.md +++ b/docs/en/config/README.md @@ -74,3 +74,7 @@ Reverse proxy. You can forward server-side traffic to the client, that is, rever > fakedns: [FakeDnsObject](./fakedns.md) FakeDNS configuration. It can be used with transparent proxy to obtain the actual domain name. + +> metrics: [metricsObject](./metrics.md) + +Metrics configuration. A more straightforward (and hopefully better) way to export metrics. \ No newline at end of file diff --git a/docs/en/config/metrics.md b/docs/en/config/metrics.md new file mode 100644 index 0000000..24473e9 --- /dev/null +++ b/docs/en/config/metrics.md @@ -0,0 +1,275 @@ +# Metrics + +A more straightforward (and hopefully better) way to export metrics. + +## Related configurations + +It's possible to add a metrics inbound among inbounds. + +```json + "inbounds": [ + { + "listen": "127.0.0.1", + "port": 11111, + "protocol": "dokodemo-door", + "settings": { + "address": "127.0.0.1" + }, + "tag": "metrics_in" + } + ] +``` + +And add routing rules regarding the metrics inbound in the routing configuration. + +```json + "routing": { + "rules": [ + { + "type": "field", + "inboundTag": [ + "metrics_in" + ], + "outboundTag": "metrics_out" + } + ] + } +``` + +Then finally, enable metrics under the root object. + +```json + "metrics": { + "tag": "metrics_out" + } +``` + +## Usage + +### pprof + +Access `http://127.0.0.1:11111/debug/pprof/` or use go tool pprof to start profiling or inspect running goroutines. + +### expvars + +Access `http://127.0.0.1:11111/debug/vars` + +Variables exported include: +* `stats` includes statistics about inbounds, outbounds and users +* `observatory` includes observatory results + +for example with [luci-app-xray](https://github.com/yichya/luci-app-xray) you are likely to get a result like this (standard expvar things like `cmdline` and `memstats` are omitted) + +
Click to expand
+ +```json +{ + "observatory": { + "tcp_outbound": { + "alive": true, + "delay": 782, + "outbound_tag": "tcp_outbound", + "last_seen_time": 1648477189, + "last_try_time": 1648477189 + }, + "udp_outbound": { + "alive": true, + "delay": 779, + "outbound_tag": "udp_outbound", + "last_seen_time": 1648477191, + "last_try_time": 1648477191 + } + }, + "stats": { + "inbound": { + "api": { + "downlink": 0, + "uplink": 0 + }, + "dns_server_inbound_5300": { + "downlink": 14286, + "uplink": 5857 + }, + "http_inbound": { + "downlink": 74460, + "uplink": 10231 + }, + "https_inbound": { + "downlink": 0, + "uplink": 0 + }, + "metrics": { + "downlink": 6327, + "uplink": 1347 + }, + "socks_inbound": { + "downlink": 19925615, + "uplink": 5512 + }, + "tproxy_tcp_inbound": { + "downlink": 4739161, + "uplink": 1568869 + }, + "tproxy_udp_inbound": { + "downlink": 0, + "uplink": 2608142 + } + }, + "outbound": { + "blackhole_outbound": { + "downlink": 0, + "uplink": 0 + }, + "direct": { + "downlink": 97714548, + "uplink": 3234617 + }, + "dns_server_outbound": { + "downlink": 7116, + "uplink": 2229 + }, + "manual_tproxy_outbound_tcp_1": { + "downlink": 0, + "uplink": 0 + }, + "manual_tproxy_outbound_udp_1": { + "downlink": 0, + "uplink": 0 + }, + "tcp_outbound": { + "downlink": 23873238, + "uplink": 1049595 + }, + "udp_outbound": { + "downlink": 639282, + "uplink": 74634 + } + }, + "user": {} + } +} +``` +
+ +To get a better view of these numbers, [Netdata](https://github.com/netdata/netdata) (with python.d plugin) is a great option: + +1. Edit related configuration file (`sudo /etc/netdata/edit-config python.d/go_expvar.conf`) +2. Take the following configuration file as an example: + +
Click to expand
+ +``` +xray: + name: 'xray' + update_every: 2 + url: 'http://127.0.0.1:11111/debug/vars' + collect_memstats: false + extra_charts: + - id: 'inbounds' + options: + name: 'inbounds' + title: 'Xray System Inbounds' + units: bytes + family: xray + context: xray.inbounds + chart_type: line + lines: + - expvar_key: stats.inbound.tproxy_tcp_inbound.downlink + id: 'tcp.downlink' + algorithm: incremental + expvar_type: int + - expvar_key: stats.inbound.tproxy_udp_inbound.downlink + id: 'udp.downlink' + algorithm: incremental + expvar_type: int + - expvar_key: stats.inbound.http_inbound.downlink + id: 'http.downlink' + algorithm: incremental + expvar_type: int + - expvar_key: stats.inbound.https_inbound.downlink + id: 'https.downlink' + algorithm: incremental + expvar_type: int + - expvar_key: stats.inbound.socks_inbound.downlink + id: 'socks.downlink' + algorithm: incremental + expvar_type: int + - expvar_key: stats.inbound.tproxy_tcp_inbound.uplink + id: 'tcp.uplink' + algorithm: incremental + expvar_type: int + - expvar_key: stats.inbound.tproxy_udp_inbound.uplink + id: 'udp.uplink' + algorithm: incremental + expvar_type: int + - expvar_key: stats.inbound.http_inbound.uplink + id: 'http.uplink' + algorithm: incremental + expvar_type: int + - expvar_key: stats.inbound.https_inbound.uplink + id: 'https.uplink' + algorithm: incremental + expvar_type: int + - expvar_key: stats.inbound.socks_inbound.uplink + id: 'socks.uplink' + algorithm: incremental + expvar_type: int + - id: 'outbounds' + options: + name: 'outbounds' + title: 'Xray System Outbounds' + units: bytes + family: xray + context: xray.outbounds + chart_type: line + lines: + - expvar_key: stats.outbound.tcp_outbound.downlink + id: 'tcp.downlink' + algorithm: incremental + expvar_type: int + - expvar_key: stats.outbound.udp_outbound.downlink + id: 'udp.downlink' + algorithm: incremental + expvar_type: int + - expvar_key: stats.outbound.direct.downlink + id: 'direct.downlink' + algorithm: incremental + expvar_type: int + - expvar_key: stats.outbound.tcp_outbound.uplink + id: 'tcp.uplink' + algorithm: incremental + expvar_type: int + - expvar_key: stats.outbound.udp_outbound.uplink + id: 'udp.uplink' + algorithm: incremental + expvar_type: int + - expvar_key: stats.outbound.direct.uplink + id: 'direct.uplink' + algorithm: incremental + expvar_type: int + - id: 'observatory' + options: + name: 'observatory' + title: 'Xray Observatory Metrics' + units: milliseconds + family: xray + context: xray.observatory + chart_type: line + lines: + - expvar_key: observatory.tcp_outbound.delay + id: tcp + expvar_type: int + - expvar_key: observatory.udp_outbound.delay + id: udp + expvar_type: int +``` +
+ +And you will get a nice plot like this: + +![160428235-2988bf69-5d6c-41ec-8267-1bd512508aa8](https://github.com/chika0801/Xray-docs-next/assets/88967758/455e88ce-ced2-4593-a9fa-425bb293215b) + +### Additional +Maybe reusing the empty object `stats` in config file is better than adding `metrics` here? + +**Edit:** removed prometheus related things and added usage about expvars diff --git a/docs/en/config/transport.md b/docs/en/config/transport.md index 7f6c95e..9024188 100644 --- a/docs/en/config/transport.md +++ b/docs/en/config/transport.md @@ -25,7 +25,8 @@ The `TransportObject` corresponds to the `transport` item in the configuration f "httpSettings": {}, "quicSettings": {}, "dsSettings": {}, - "grpcSettings": {} + "grpcSettings": {}, + "httpupgradeSettings": {} } } ``` @@ -54,6 +55,10 @@ Configuration for QUIC connections. Configuration for gRPC connections. +> `httpupgradeSettings`: [HttpUpgradeObject](./transports/httpupgrade.md) + +Configuration for HTTPUpgrade connections. + > `dsSettings`: [DomainSocketObject](./transports/domainsocket.md) Configuration for Domain Socket connections. @@ -74,6 +79,7 @@ Configuration for Domain Socket connections. "quicSettings": {}, "dsSettings": {}, "grpcSettings": {}, + "httpupgradeSettings": {}, "sockopt": { "mark": 0, "tcpFastOpen": false, @@ -86,11 +92,11 @@ Configuration for Domain Socket connections. } ``` -> `network`: "tcp" | "kcp" | "ws" | "http" | "domainsocket" | "quic" | "grpc" +> `network`: "tcp" | "kcp" | "ws" | "http" | "quic" | "grpc" | "httpupgrade" The type of transport used by the connection's data stream, with a default value of `"tcp"`. -> `security`: "none" | "tls" | "xtls" +> `security`: "none" | "tls" | "reality" Whether to enable transport layer encryption, with supported options: @@ -138,9 +144,13 @@ The gRPC configuration for the current connection, only valid when gRPC is used The Domain socket configuration for the current connection, only valid when Domain socket is used for this connection. The configuration is the same as the global configuration above. +> `httpupgradeSettings`: [HttpUpgradeObject](./transports/httpupgrade.md) + +Configuration of the current HTTPUpragde connection. Valid only when HTTPUpgrade is used by this connection. The configuration schema is the exact same as the global schema. + > `sockopt`: [SockoptObject](./chat#sockoptobject) -Specific configuration for transparent proxying. +Specific configuration for transparent proxies. ### TLSObject diff --git a/docs/en/config/transports/httpupgrade.md b/docs/en/config/transports/httpupgrade.md new file mode 100644 index 0000000..697e433 --- /dev/null +++ b/docs/en/config/transports/httpupgrade.md @@ -0,0 +1,35 @@ +# HttpUpgrade + +A WebSocket-like transport protocol implementing the HTTP/1.1 upgrade and response, allowing it to be reverse proxied by web servers or CDNs just like WebSocket, but without the need to implement the remaining portions of the WebSocket protocol, yielding better performance. + +Standalone usage is not recommended, but rather in conjunction with other security protocols like TLS. + +## HttpUpgradeObject + +The `HttpUpgradeObject` corresponds to the `httpupgradeSettings` section under transport configurations. + +```json +{ + "acceptProxyProtocol": false, + "path": "/", + "host": "xray.com" +} +``` + +> `acceptProxyProtocol`: true | false + +For inbounds only. Specifies whether to accept the PROXY protocol. + +The [PROXY protocol](https://www.haproxy.org/download/2.2/doc/proxy-protocol.txt) is used to pass the real IP address and port of a connection along. **Ignore it if you have no knowledge regarding this**. + +Common reverse proxies (e.g. HAProxy, NGINX) and VLESS fallbacks xver can be configured for its inclusion. + +When `true`, the downstream must first send PROXY protocol version 1 or 2 after establishing the underlying TCP connection, or the connection will be closed. + +> `path`: string + +HTTP path used by the HTTPUpgrade connection. Defaults to `"/"`. + +> `host`: string + +HTTP Host sent by the HTTPUpgrade connection. Empty by default. \ No newline at end of file