Skip to content

Commit

Permalink
Merge pull request #1284 from erfjab/mainserverusage
Browse files Browse the repository at this point in the history
Feat(users): add master server usage ratio
  • Loading branch information
erfjab authored Sep 2, 2024
2 parents c2c98b7 + 041b810 commit d4e2be5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ UVICORN_PORT = 8000
## Whitelist of IPs/hosts to disable login notifications
# LOGIN_WHITE_LIST = '1.1.1.1,sub.domain.com,127.0.0.1'

## Main Server Usege Ratio
# MAIN_SERVER_USAGE_RATIO = 1

### for developers
# DOCS=True
# DEBUG=True
Expand Down
5 changes: 3 additions & 2 deletions app/jobs/record_usages.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from app.db.models import NodeUsage, NodeUserUsage, System, User
from config import (DISABLE_RECORDING_NODE_USAGE,
JOB_RECORD_NODE_USAGES_INTERVAL,
JOB_RECORD_USER_USAGES_INTERVAL)
JOB_RECORD_USER_USAGES_INTERVAL,
MASTER_SERVER_USAGE_RATIO)
from xray_api import XRay as XRayAPI
from xray_api import exc as xray_exc

Expand Down Expand Up @@ -125,7 +126,7 @@ def get_outbounds_stats(api: XRayAPI):

def record_user_usages():
api_instances = {None: xray.api}
usage_coefficient = {None: 1} # default usage coefficient for the main api instance
usage_coefficient = {None: MASTER_SERVER_USAGE_RATIO} # default usage coefficient for the main api instance

for node_id, node in list(xray.nodes.items()):
if node.connected and node.started:
Expand Down
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

EXTERNAL_CONFIG = config("EXTERNAL_CONFIG", default="", cast=str)
LOGIN_WHITE_LIST = [ip.strip() for ip in config("LOGIN_WHITE_LIST", default="", cast=str).split(",") if ip.strip()]
MASTER_SERVER_USAGE_RATIO = config("MASTER_SERVER_USAGE_RATIO", default=1, cast=float)

USE_CUSTOM_JSON_DEFAULT = config("USE_CUSTOM_JSON_DEFAULT", default=False, cast=bool)
USE_CUSTOM_JSON_FOR_V2RAYN = config("USE_CUSTOM_JSON_FOR_V2RAYN", default=False, cast=bool)
Expand Down

0 comments on commit d4e2be5

Please sign in to comment.