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

🆘 get global traffic stats from an v2ray config (ask from android devs) #2723

Closed
itsDantes opened this issue Nov 13, 2023 · 3 comments
Closed

Comments

@itsDantes
Copy link

itsDantes commented Nov 13, 2023

Im a android developer and using this lib instead of v2ray. but i have a problem.

i want to get current traffic from an v2ray config:

here is my v2ray config

{
    "dns": { "hosts": { "domain:googleapis.cn": "googleapis.com" }, "servers": ["1.1.1.1"] },
    "inbounds": [
        { "listen": "127.0.0.1", "port": 10808, "protocol": "socks", "settings": { "auth": "noauth", "udp": true, "userLevel": 8 }, "sniffing": { "destOverride": ["http", "tls"], "enabled": true }, "tag": "socks" },
        { "listen": "127.0.0.1", "port": 10809, "protocol": "http", "settings": { "userLevel": 8 }, "tag": "http" }
    ],
    "log": { "loglevel": "warning" },
    "outbounds": [
        {
            "mux": { "concurrency": 8, "enabled": false },
            "protocol": "trojan",
            "settings": { "servers": [{ "address": "13.43.63.65", "flow": "", "level": 8, "method": "chacha20-poly1305", "ota": false, "password": "telegram-id-privatevpns", "port": 22222 }] },
            "streamSettings": {
                "network": "tcp",
                "security": "tls",
                "tcpSettings": { "header": { "type": "none" } },
                "tlsSettings": { "allowInsecure": false, "alpn": ["http/1.1"], "fingerprint": "", "serverName": "trj.rollingnext.co.uk", "show": false }
            },
            "tag": "proxy"
        },
        { "protocol": "freedom", "settings": {}, "tag": "direct" },
        { "protocol": "blackhole", "settings": { "response": { "type": "http" } }, "tag": "block" }
    ],
    "routing": { "domainStrategy": "IPIfNonMatch", "rules": [{ "ip": ["1.1.1.1"], "outboundTag": "proxy", "port": "53", "type": "field" }] },
    "policy": {
        "levels": { "8": { "connIdle": 300, "handshake": 4, "uplinkOnly": 0, "downlinkOnly": 0, "statsUserUplink": true, "statsUserDownlink": true } },
        "system": { "statsOutboundUplink": true, "statsOutboundDownlink": true, "statsInboundUplink": true, "statsInboundDownlink": true }
    },
    "stats": {}
}

and my command is : xray api statsquery --server=127.0.0.1:10808

cmd

I always use v2ray configs like this and everything works fine. but I cant fetch global traffic stats from an active config.

also used below commands:
xray api statsquery --server=127.0.0.1:10808
xray api statsquery --server=127.0.0.1:10809
xray api statsquery --server=127.0.0.1:22222
xray api statsquery --server=13.43.63.65:22222

but none of them is not working and i getting this error:
failed to dial 127.0.0.1:22222

cmd2

1 - do I need to add user to my config? is there any can help me how should pass users with email to my sample config?

2 - I always can fetch used traffic in v2ray via below commands:

downloadSpeed = v2RayPoint.queryStats("block", "downlink") + v2RayPoint.queryStats("proxy", "downlink")
uploadSpeed = v2RayPoint.queryStats("block", "uplink") + v2RayPoint.queryStats("proxy", "uplink")

this code referring to github.com/2dust/AndroidLibV2rayLite/blob/0c32df27 - goLANG
there is no need to add any user to config. so does xray need to add user with their email for this like what it saying here ? what is problem Exactly?

here is more info about my app that i think maybe makes problem:

here is my builder

cmd4

and tun2socks

cmd3

🆘 android developer I needs you to help me about it. I can share more info if needed 🆘

@us254
Copy link

us254 commented Nov 16, 2023

provide logs from the Xray service, which might contain hints as to why the connection is failing or why the stats cannot be fetched.

check if the service is active:

netstat -tuln | grep 22222

To fetch stats, ensure that the stats feature is correctly configured. add a stats object in your configuration :


"stats": {},
"api": {
  "tag": "api",
  "services": ["HandlerService", "StatsService"]
},

ensure that the inbound settings include a section for the API:

"inbounds": [
  // ... other inbounds ...
  {
    "listen": "127.0.0.1",
    "port": 10800, // This should be a port that's not used by other services.
    "protocol": "dokodemo-door",
    "settings": {
      "address": "127.0.0.1"
    },
    "tag": "api"
  }
]

The stats query command seems to be malformed. The correct format should not include spaces around the equals sign

xray api statsquery --server=127.0.0.1:10800
port should match the one set in the inbound API settings.

error messages failed to dial 127.0.0.1:22222 and failed to dial 13.43.63.65:22222 suggest that is trying to query stats from the wrong port or address.

@itsDantes
Copy link
Author

itsDantes commented Nov 17, 2023

@us254 thanks for replay dear.

I changed my config like what you said:

{
    "dns": { "hosts": { "domain:googleapis.cn": "googleapis.com" }, "servers": ["1.1.1.1"] },
    "inbounds": [
        { "listen": "127.0.0.1", "port": 10808, "protocol": "socks", "settings": { "auth": "noauth", "udp": true, "userLevel": 8 }, "sniffing": { "destOverride": ["http", "tls"], "enabled": true }, "tag": "socks" },
        { "listen": "127.0.0.1", "port": 10809, "protocol": "http", "settings": { "userLevel": 8 }, "tag": "http" },
        { "listen": "127.0.0.1", "port": 10800, "protocol": "dokodemo-door", "settings": { "address": "127.0.0.1" }, "tag": "api" }
    ],
    "log": { "loglevel": "warning" },
    "outbounds": [
        {
            "protocol": "vless",
            "settings": { "vnext": [{ "address": "128.140.84.193", "port": 20304, "users": [{ "encryption": "none", "flow": "xtls-rprx-vision", "id": "0816aff6-9396-40e4-b686-22598b65cce6", "level": 8, "security": "auto" }] }] },
            "streamSettings": {
                "network": "tcp",
                "realitySettings": { "allowInsecure": false, "fingerprint": "chrome", "publicKey": "N9RAetubJnOE7u0iwBUqFyGM7cP7GVfBeCWAmS_LzB4", "serverName": "sourceforge.net", "shortId": "7632b824", "show": false, "spiderX": "" },
                "security": "reality",
                "tcpSettings": { "header": { "type": "none" } }
            },
            "tag": "proxy",
            "mux": { "enabled": false, "concurrency": 8, "xudpConcurrency": 8, "xudpProxyUDP443": "reject" }
        },
        { "protocol": "freedom", "settings": {}, "tag": "direct" },
        { "protocol": "blackhole", "settings": { "response": { "type": "http" } }, "tag": "block" }
    ],
    "routing": { "domainStrategy": "IPIfNonMatch", "rules": [{ "ip": ["1.1.1.1"], "outboundTag": "proxy", "port": "53", "type": "field" }] },
    "api": { "tag": "api", "services": ["HandlerService", "StatsService"] },
    "policy": {
        "levels": { "8": { "connIdle": 300, "handshake": 4, "uplinkOnly": 0, "downlinkOnly": 0, "statsUserUplink": true, "statsUserDownlink": true } },
        "system": { "statsOutboundUplink": true, "statsOutboundDownlink": true, "statsInboundUplink": true, "statsInboundDownlink": true }
    },
    "stats": {}
}

but still getting error failed to dial 127.0.0.1:10800

how can monitor and see logs? if I see logs, so may know whats the problem.

@yuhan6665
Copy link
Member

Please see document https://guide.v2fly.org/advanced/traffic.html#%E9%85%8D%E7%BD%AE%E7%BB%9F%E8%AE%A1%E5%8A%9F%E8%83%BD
If still doesn't work, debug v2rayNG side by side to see what is the difference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants