V2ray-core: 获取系统状态的接口不能使用StatsService.GetStats

Created on 26 Sep 2018  ·  8Comments  ·  Source: v2ray/v2ray-core

Please skip to the English section below if you don't write Chinese.

中文:
提交 Issue 之前请先阅读 Issue 指引,然后回答下面的问题,谢谢。
除非特殊情况,请完整填写所有问题。不按模板发的 issue 将直接被关闭。
如果你遇到的问题不是 V2Ray 的 bug,比如你不清楚要如何配置,请使用Discussion进行讨论。

1) 你正在使用哪个版本的 V2Ray?(如果服务器和客户端使用了不同版本,请注明)
v3.4.3
2) 你的使用场景是什么?比如使用 Chrome 通过 Socks/VMess 代理观看 YouTube 视频。
使用 Chrome 通过 Socks/VMess 代理观看 YouTube 视频。
3) 你看到的不正常的现象是什么?(请描述具体现象,比如访问超时,TLS 证书错误等)

增加用户等接口是正常使用的,只有获取状态的接口不可用
获取系统状态的接口不能使用,StatsService.GetStats报错
不管是使用/usr/bin/v2ray/v2ctl还是使用web接口来请求服务器的api接口,均报错

root@vultr:/etc/v2ray# /usr/bin/v2ray/v2ctl api --server=127.0.0.1:10010 StatsService.GetStats 'name: "user>>>myemail>>>traffic>>>downlink" reset: false'
Ext|Tools|Control: failed to call service StatsService.GetStats > rpc error: code = Unknown desc = App|Stats|Command: user>>>myemail>>>traffic>>>downlink not found.

使用api接口请求,抱错:

grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNKNOWN, App|Stats|Command: user>>>test>>>traffic>>>uplink not found.)>

用户email部分因为隐私保护做了处理

4) 你期待看到的正确表现是怎样的?
应该正确获取信息
5) 请附上你的配置(提交 Issue 前请隐藏服务器端IP地址)。
服务器端配置:

{
    "stats": {},
    "api": {
        "tag": "api",
        "services": [
            "HandlerService",
            "LoggerService",
            "StatsService"
        ]
    },
    "routing": {
        "settings": {
            "rules": [
                {
                    "inboundTag": [
                        "api"
                    ],
                    "outboundTag": "api",
                    "type": "field"
                }
            ]
        },
        "strategy": "rules"
    }}

服务器配置应该没有错误,因为增加用户等接口都是可用的,就是获取统计信息的接口不可以使用,这里粘贴的是主要的api部分配置
客户端配置:

    // 在这里附上客户端配置

6) 请附上出错时软件输出的错误日志。在 Linux 中,日志通常在 /var/log/v2ray/error.log 文件中。

服务器端错误日志:

    // 在这里附上服务器端日志
root@vultr:/etc/v2ray# /usr/bin/v2ray/v2ctl api --server=127.0.0.1:10010 StatsService.GetStats 'name: "user>>>lin@*.win>>>traffic>>>downlink" reset: false'
Ext|Tools|Control: failed to call service StatsService.GetStats > rpc error: code = Unknown desc = App|Stats|Command: user>>>lin@*.win>>>traffic>>>downlink not found.

客户端错误日志:

    // 在这里附上客户端日志

7) 请附上访问日志。在 Linux 中,日志通常在 /var/log/v2ray/access.log 文件中。

    // 在这里附上服务器端日志

8) 其它相关的配置文件(如 Nginx)和相关日志。

9) 如果 V2Ray 无法启动,请附上 --test 输出。

通常的命令为 /usr/bin/v2ray/v2ray --test --config /etc/v2ray/config.json。请按实际情况修改。

10) 如果 V2Ray 服务运行不正常,请附上 journal 日志。

通常的命令为 journalctl -u v2ray

请预览一下你填的内容再提交。

如果你已经填完上面的问卷,请把下面的英文部份删除,再提交 Issue。
Please remove the Chinese section above.

English:
Please read the instruction and answer the following questions before submitting your issue. Thank you.
Please answer all the questions with enough information. All issues not following this template will be closed immediately.
If you are not sure if your question is truely a bug in V2Ray, please discuss it here first.

1) What version of V2Ray are you using (If you deploy different version on server and client, please explicitly point out)?

2) What's your scenario of using V2Ray? E.g., Watching YouTube videos in Chrome via Socks/VMess proxy.

3) What did you see? (Please describe in detail, such as timeout, fake TLS certificate etc)

4) What's your expectation?

5) Please attach your configuration file (Mask IP addresses before submit this issue).

Server configuration:

    // Please attach your server configuration here.

Client configuration:

    // Please attach your client configuration here.

6) Please attach error logs, especially the bottom lines if the file is large. Error log file is usually at /var/log/v2ray/error.log on Linux.

Server error log:

    // Please attach your server error log here.

Client error log:

    // Please attach your client error log here.

7) Please attach access log. Access log is usually at '/var/log/v2ray/access.log' on Linux.

    // Please attach your server access log here.

Please review your issue before submitting.

8) Other configurations (such as Nginx) and logs.

9) If V2Ray doesn't run, please attach output from --test.

The command is usually /usr/bin/v2ray/v2ray --test --config /etc/v2ray/config.json, but may vary according to your scenario.

10) If V2Ray service doesn't run, please attach journal log.

Usual command is journalctl -u v2ray.

Most helpful comment

问题找到了,是这个配置的问题:

    "policy": {
        "levels": {
            "0": {
                "connIdle": 300,
                "downlinkOnly": 30,
                "handshake": 4,
                "uplinkOnly": 5,
                "statsUserDownlink": true,
                "statsUserUplink": true
            }
        }
    },

* "statsUserDownlink": true,*
* "statsUserUplink": true*
这两个可能需要设置为true
多谢大佬了

All 8 comments

你的调用方法和命令都是对的,你看输出部分,告诉你要查找的信息no found,你让这个用户产生些流量就有信息输出了。

你的调用方法和命令都是对的,你看输出部分,告诉你要查找的信息no found,你让这个用户产生些流量就有信息输出了。

并不是用户名的问题,即使我把user 换成 inbound 也是不行的

root@vultr:~# /usr/bin/v2ray/v2ctl api --server=localhost:10010 StatsService.GetStats 'name: "inbound>>>master_server>>>traffic>>>downlink" reset: false'
Ext|Tools|Control: failed to call service StatsService.GetStats > rpc error: code = Unknown desc = App|Stats|Command: inbound>>>master_server>>>traffic>>>downlink not found.

v2ctl api [--server=127.0.0.1:8080] Service.Method Request
Call an API in an V2Ray process.
The following methods are currently supported:
        LoggerService.RestartLogger
        StatsService.GetStats




root@vultr:~# /usr/bin/v2ray/v2ctl api --server=localhost:10010 StatsService.GetStats 'name: "inbound>>>[master_server]>>>traffic>>>downlink" reset: false'
Ext|Tools|Control: failed to call service StatsService.GetStats > rpc error: code = Unknown desc = App|Stats|Command: inbound>>>[master_server]>>>traffic>>>downlink not found.

v2ctl api [--server=127.0.0.1:8080] Service.Method Request
Call an API in an V2Ray process.
The following methods are currently supported:
        LoggerService.RestartLogger
        StatsService.GetStats

我的主配置部分信息:

"streamSettings": {
            "network": "kcp"
        },
        "tag": "master_server",

服务器配置不全,应该有个inbound detour设置端口号来接受API请求。

服务器配置不全,应该有个inbound detour设置端口号来接受API请求。

有的老哥,现在是请求 增加用户等接口都是可以使用的,就是获取状态的没法使用,所有我才觉得是这个接口的问题

配置如下:

        {
            "listen": "0.0.0.0",
            "port": 10010,
            "protocol": "dokodemo-door",
            "settings": {
                "address": "0.0.0.0"
            },
            "tag": "api"
        }

参考一下下面的配置,我是可以正常取回用户流量的。

{
"stats": {},
"api": {
"services": ["StatsService", "LoggerService", "HandlerService"],
"tag": "api"
},
"policy": {
"levels": {
"0": {
"connIdle": 300,
"downlinkOnly": 30,
"handshake": 4,
"uplinkOnly": 5,
"statsUserDownlink": true,
"statsUserUplink": true
}
}
},
"inbound": {
"tag": "proxy",
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls"]
},
"port": 10001,
"listen": "127.0.0.1",
"protocol": "vmess",
"settings": {
"clients": [{
"id": "xxx",
"email": "[email protected]",
"security": "auto",
"alterId": 64,
"level": 0
}, {
"id": "xxx",
"email": "[email protected]",
"security": "auto",
"alterId": 64,
"level": 0
}, {
"id": "xxx",
"email": "[email protected]",
"security": "auto",
"alterId": 64,
"level": 0
}]
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/play"
}
}
},
"inboundDetour": [{
"listen": "0.0.0.0",
"port": 10010,
"protocol": "dokodemo-door",
"settings": {
"address": "127.0.0.1"
},
"tag": "api"
}],
"outbound": {
"protocol": "freedom",
"settings": {}
},
"outboundDetour": [{
"protocol": "blackhole",
"settings": {},
"tag": "block"
}],
"routing": {
"strategy": "rules",
"settings": {
"rules": [{
"inboundTag": ["api"],
"outboundTag": "api",
"type": "field"
}, {
"type": "field",
"outboundTag": "block",
"protocol": ["bittorrent"]
}, {
"type": "field",
"ip": ["0.0.0.0/8", "10.0.0.0/8", "100.64.0.0/10", "127.0.0.0/8", "169.254.0.0/16", "172.16.0.0/12", "192.0.0.0/24", "192.0.2.0/24", "192.168.0.0/16", "198.18.0.0/15", "198.51.100.0/24", "203.0.113.0/24", "::1/128", "fc00::/7", "fe80::/10"],
"outboundTag": "freedom"
}]
}
}
}

问题找到了,是这个配置的问题:

    "policy": {
        "levels": {
            "0": {
                "connIdle": 300,
                "downlinkOnly": 30,
                "handshake": 4,
                "uplinkOnly": 5,
                "statsUserDownlink": true,
                "statsUserUplink": true
            }
        }
    },

* "statsUserDownlink": true,*
* "statsUserUplink": true*
这两个可能需要设置为true
多谢大佬了

同样的配置 还是这个问题,能把配置贴出来吗

同样的配置 还是这个问题,能把配置贴出来吗

@cpzz50

主要注意api、routing、policy的配置,仔细校对一下

{
    "log": {
        "#access": "/root/access_v2ray.log",
        "error": "/root/error_v2ray.log",
        "loglevel": "warning"
    },
    "api": {
        "tag": "api",
        "services": [
            "HandlerService",
            "LoggerService",
            "StatsService"
        ]
    },
    "stats": {
    },
    "routing": {
        "domainStrategy": "AsIs",
        "rules": [
            {
                "inboundTag": [
                    "api"
                ],
                "outboundTag": "api",
                "type": "field"
            },
            {
                "type": "field",
                "outboundTag": "block",
                "protocol": [
                    "bittorrent"
                ]
            }
        ]
    },
    "policy": {
        "levels": {
            "0": {
                "handshake": 4,
                "connIdle": 300,
                "uplinkOnly": 2,
                "downlinkOnly": 5,
                "statsUserUplink": true,
                "statsUserDownlink": true,
                "bufferSize": 10240
            }
        },
        "system": {
            "statsInboundUplink": false,
            "statsInboundDownlink": false
        }
    },
    "inbounds": [
        {
            "tag": "main_kcp",
            "port": 48800,
            "listen": "0.0.0.0",
            "protocol": "vmess",
            "settings": {
                "clients": [
                    // 为了保密移除用户
                ],
                "default": {
                    "level": 0,
                    "alterId": 32
                },
                "disableInsecureEncryption": false
            },
            "streamSettings": {
                "network": "kcp",
                "security": "none"
            },
            "sniffing": {
                "enabled": true
            }
        },
        {
            "tag": "main_ws",
            "port": 48443,
            "listen": "0.0.0.0",
            "protocol": "vmess",
            "settings": {
                "clients": [
                    // 为了保密移除用户
                ],
                "default": {
                    "level": 0,
                    "alterId": 32
                },
                "disableInsecureEncryption": false
            },
            "streamSettings": {
                "network": "ws",
                "security": "none"
            },
            "sniffing": {
                "enabled": true
            }
        },
        {
            "listen": "0.0.0.0",
            "port": 10010,
            "protocol": "dokodemo-door",
            "settings": {
                "address": "127.0.0.1"
            },
            "tag": "api"
        }
    ],
    "outbounds": [
        {
            "protocol": "freedom",
            "settings": {
            }
        },
        {
            "protocol": "blackhole",
            "settings": {
            },
            "tag": "block"
        }
    ],
    "transport": {
        "kcpSettings": {
            "mtu": 1350,
            "tti": 20,
            "uplinkCapacity": 100,
            "downlinkCapacity": 100,
            "congestion": false,
            "readBufferSize": 20,
            "writeBufferSize": 20,
            "header": {
                "type": "srtp"
            }
        },
        "wsSettings": {
            "path": "/data"
        }
    }
}
Was this page helpful?
0 / 5 - 0 ratings