Skip to content

Commit

Permalink
升级路由负载均衡的连接观测
Browse files Browse the repository at this point in the history
  • Loading branch information
BI7PRK committed Feb 29, 2024
1 parent ec37323 commit c802f67
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 51 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "luci-app-xray",
"version": "1.0.5",
"release": "0",
"release": "1",
"description": "LuCI support for xray-core and v2ray-core",
"repository": "git@github.com:BI7PRK/luci-app-xray.git",
"author": "BI7PRK",
Expand Down
12 changes: 5 additions & 7 deletions public/luasrc/controller/xray.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@ function index()

entry({"admin", "services", "xray", "routing"}, view("xray/routing"), _("Routing"), 50)

entry({"admin", "services", "xray", "observatory"}, view("xray/observatory"), _("Observatory"), 60)
entry({"admin", "services", "xray", "policy"}, view("xray/policy"), _("Policy"), 60)

entry({"admin", "services", "xray", "policy"}, view("xray/policy"), _("Policy"), 70)
entry({"admin", "services", "xray", "reverse"}, view("xray/reverse"), _("Reverse"), 70)

entry({"admin", "services", "xray", "reverse"}, view("xray/reverse"), _("Reverse"), 80)
entry({"admin", "services", "xray", "transparent-proxy"}, view("xray/transparent-proxy"), _("Transparent Proxy"), 80)

entry({"admin", "services", "xray", "transparent-proxy"}, view("xray/transparent-proxy"), _("Transparent Proxy"), 90)
entry({"admin", "services", "xray", "about"}, view("xray/about"), _("About"), 90)

entry({"admin", "services", "xray", "about"}, view("xray/about"), _("About"), 100)

entry({"admin", "services", "xray", "tools"}, view("xray/tools"), _("Tools"), 110)
entry({"admin", "services", "xray", "tools"}, view("xray/tools"), _("Tools"), 100)

entry({"admin", "services", "xray", "request"}, call("action_request"))
end
Expand Down
20 changes: 9 additions & 11 deletions public/root/etc/config/xray
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ config dns_server 'ali_dns_1'
option s_client_ip ''
list domains 'geosite:cn'

config observatory 'main_observatory'
option enabled '0'
option probeURL 'https://www.gstatic.com/generate_204'
option probeInterval '10s'
option enableConcurrency '1'
option leastTimeout '15s'
option leastSampling '2'
option leastConnectivity 'http://connectivitycheck.platform.hicloud.com/generate_204'
option subjectSelector ''

config routing 'main_routing'
option enabled '1'
option domain_strategy 'IPOnDemand'
Expand Down Expand Up @@ -123,11 +113,19 @@ config routing_rule 'direct_ntp'
list port '123'
option outbound_tag 'direct'

config routing_balancer 'routing_balancer_1'
config routing_balancer 'defalt_balancer'
option tag 'balancer'
option strategy_type 'random'
list selector 'a'
list selector 'ab'
option probeURL 'https://www.gstatic.com/generate_204'
option probeInterval '10s'
option enableConcurrency '1'
option leastTimeout '15s'
option leastSampling '2'
option leastConnectivity 'http://connectivitycheck.platform.hicloud.com/generate_204'
option subjectSelector 'a'
option list subjectSelector 'ab'

config policy 'main_policy'
option enabled '0'
Expand Down
44 changes: 13 additions & 31 deletions public/root/etc/init.d/xray_luci
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,6 @@ dns_server_section_validate() {
'sub_client_ip:ipaddr'
}

observatory_section_validate() {
uci_validate_section "$NAME" "observatory" "$1" \
'enabled:bool:0' \
'leastType:or("leastPing", "leastLoad")' \
'enableConcurrency:bool:0' \
'probeURL:string' \
'probeInterval:string' \
'leastTimeout:string' \
'leastSampling:uinteger:2' \
'leastConnectivity:string' \
'subjectSelector:list(string)'
}

routing_section_validate() {
uci_validate_section "$NAME" "routing" "$1" \
Expand Down Expand Up @@ -218,8 +206,13 @@ routing_rule_section_validate() {
routing_balancer_section_validate() {
uci_validate_section "$NAME" "routing_balancer" "$1" \
'tag:string' \
'strategy_type:or("random", "leastPing")' \
'selector:list(string)'
'strategy_type:or("random", "leastPing", "leastLoad")' \
'selector:list(string)' \
'probeURL:string' \
'probeInterval:string' \
'leastTimeout:string' \
'leastSampling:uinteger:2' \
'leastConnectivity:string'
}

policy_section_validate() {
Expand Down Expand Up @@ -889,18 +882,8 @@ add_dns_settings() {
}

add_observatory_settings() {
local section="${1}_observatory"
if ! observatory_section_validate "$section"; then
_err "Invalid routing config: $section, skip"
return 1
fi

if [ "x$enabled" != "x1" ]; then
_info "observatory disabled: $section"
return 0
fi
json_add_object "observatory"
if [ "$leastType" = "leastPing" ]; then
if [ "$strategy_type" = "leastPing" ]; then
test -n "$probeURL" &&
json_add_string "probeURL" "$probeURL"

Expand All @@ -927,10 +910,10 @@ add_observatory_settings() {

json_close_object # pingConfig
fi
if [ -n "$subjectSelector" ]; then
if [ -n "$selector" ]; then
json_add_array "subjectSelector"
local str
for str in $subjectSelector; do
for str in $selector; do
json_add_string "" "$str"
done
json_close_array # subjectSelector
Expand Down Expand Up @@ -1069,9 +1052,7 @@ add_routing_settings() {
json_add_object "strategy"
json_add_string "type" "$strategy_type"
json_close_object

json_add_array "selector"

local s
for s in $selector; do
json_add_string "" "$s"
Expand All @@ -1084,8 +1065,10 @@ add_routing_settings() {

json_close_array # balancers
fi

json_close_object
if [ -n "$balancers" ] && [ "$strategy_type" != "random" ]; then
add_observatory_settings "$1"
fi
}

add_policy_settings() {
Expand Down Expand Up @@ -2508,7 +2491,6 @@ start_instance() {
fi

add_dns_settings "$section"
add_observatory_settings "$section"
add_routing_settings "$section"
add_policy_settings "$section"
add_reverse_settings "$section"
Expand Down
39 changes: 38 additions & 1 deletion src/view/xray/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,47 @@ return L.view.extend<SectionItem[][]>({
o = s3.option(form.ListValue, "strategy_type", _("Balancer strategy"));
o.value("random");
o.value("leastPing");
o.value("leastLoad");
o.modalonly = true;

o = s3.option(form.DynamicList, "selector", _("Selector"));
o = s3.option(
form.Value,
"probeURL",
_("ProbeURL"),
_(
"A valid URL, it will be get request to testing. eg: <code>%s</code>."
).format("https://www.gstatic.com/generate_204")
);
o.placeholder = _("empty use the built-in value");
o.depends("strategy_type", "leastPing");
o.depends("strategy_type", "leastLoad");

o = s3.option(form.Value, "probeInterval", _("ProbeInterval"));
o.depends("strategy_type", "leastPing");
o.depends("strategy_type", "leastLoad");

o = s3.option(form.Flag, "enableConcurrency", _("Enable concurrency"));
o.depends("strategy_type", "leastPing");

o = s3.option(form.Value, "leastTimeout", _("Timeout"));
o.depends("strategy_type", "leastLoad");

o = s3.option(form.Value, "leastSampling", _("Sampling"));
o.depends("strategy_type", "leastLoad");

o = s3.option(
form.Value,
"leastConnectivity",
_("Connectivity"),
_(
"A valid URL, it will be get request to testing. eg: <code>%s</code>."
).format("http://connectivitycheck.platform.hicloud.com/generate_204")
);
o.depends("strategy_type", "leastLoad");

o = s3.option(form.DynamicList, "selector", _("Selector"));
o.depends("strategy_type", "leastPing");
o.depends("strategy_type", "leastLoad");
return m.render();
},
});

0 comments on commit c802f67

Please sign in to comment.