Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Observatory object can't be added (to use leastPing strategy for balancer) #991

Closed
pulsarice opened this issue Feb 21, 2024 · 9 comments
Closed
Labels
enhancement New feature or request

Comments

@pulsarice
Copy link

pulsarice commented Feb 21, 2024

Xray has a feature (borrowed from v2ray project) to ping outbounds in a set interval and use the best one via balancer routing rules.
I have tested it locally and it works. (by manually editing config.json and running xray)
It needs ObservatoryObject to be added to config.json. but when I add this to xray config in x-ui, it's not added to "/usr/local/x-ui/bin/config.json", therefore this feature does not work.
Please fix this

observatory settings in config.json:

{
    "log": {},
    "api": {},
    "dns": {},
    "routing": {},
    "policy": {},
    "inbounds": [],
    "outbounds": [],
    "transport": {},
    "stats": {},
    "reverse": {},
    "fakedns": [],
    "observatory": {}
}

The format of observatory is like this:

  "observatory": {
    "subjectSelector": [
          "server1",
          "server2"
    ],
    "probeURL": "https://www.google.com/generate_204",
    "probeInterval": "1m",
    "enableConcurrency": true
  }

and the balancer will be like this:

  "routing": {
    "balancers": [
      {
        "tag": "balancer",
        "selector": [
          "server1",
          "server2"
        ],
        "strategy": {
          "type": "leastPing"
        }
      }
    ],
    "rules": []
  }
@pulsarice pulsarice added the enhancement New feature or request label Feb 21, 2024
@alireza0
Copy link
Owner

This feature is advanced configuration which in this panel, we use it in JSON subscription. But in simple UI like x-ui could not be controlled simply.

It is true that this part is not defined as an object in Backend codes. I will fix it in next version.

@pulsarice
Copy link
Author

If the observatory object could be added manually in xray advanced settings (even without UI integration), that would be great.
It's much appreciated sir.

@alireza0
Copy link
Owner

Due to some typos I have rebuilt the 1.7.2 tag.
You can now update your installation again and get the most of it ;)

@pulsarice
Copy link
Author

Thank you very much dear sir. You made my day.
Now xray pings my reverse-tunnels periodically and chooses the best one.
If a portal fails, it will failover to a healthy one.

@ErfanTech
Copy link

Dear @pulsarice
I'm also using reverse tunnel,
Can you please guide me on how to configure my xray to take advantage of load balance?
How many servers do you have and in each what custome config are you using?

@pulsarice
Copy link
Author

pulsarice commented Feb 21, 2024

I have 3 reverse connections, named portal-1, portal-2 and portal-3
I added this object at the end of xray config

  "reverse": { ...... my reverse portal configs},
  "observatory": {
    "subjectSelector": [
          "portal"
    ],
    "probeURL": "https://www.google.com/generate_204",
    "probeInterval": "5s",
    "enableConcurrency": true
  }

the selector "portal" will ping all outbound/reverse tunnels begining with "portal" every 5 seconds, which will include all my tunnels.

then I added the balancer object inside routing, before rules:

  "routing": {
    "balancers": [
      {
        "tag": "balancer",
        "selector": [
          "portal"
        ],
        "strategy": {
          "type": "leastPing"
        }
      }
    ],
    "rules": [..... your rules]
  }

Then in routing rules, instead of outboundtag, I use balancertag "balancer"

you can also put all outbound/portal names seperately in selector object

selector: [ string ]
An array of strings, each of which will be used to match the prefix of the outbound identifier. For example, in the following outbound identifiers: [ "a", "ab", "c", "ba" ], "selector": ["a"] will match [ "a", "ab" ].

        "selector": [
          "reverse-01",
          "reverse-02",
          "reverse-03"
        ]

@ErfanTech
Copy link

Thanks for your detailed explanation❤️, I will try it.
Does leastPing method works in the current version of xray?
Can I have your telegram to message you?

@pulsarice
Copy link
Author

Does leastPing method works in the current version of xray?

I can cofirm that it works on v1.8.7

Can I have your telegram to message you?

I'm sorry, but I don't feel comfortable sharing my contact info.

@alireza0
Copy link
Owner

alireza0 commented May 3, 2024

It is already added. Closing issue...

@alireza0 alireza0 closed this as completed May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants