Skip to content

Commit

Permalink
Update traffic.md & Vmess.md (#267)
Browse files Browse the repository at this point in the history
* Update traffic.md
1. Add all of the required object including api, policy and routing
2. Tab indent in the config changed to 2
3. Adjusted paragraph structure and the format of the command, and remove excessively long output results in query traffic stats block
4. Deleted history block
5. Fix typo

* Update vmess.md
1. Update the latest path of v2ray and its config
2. delete history block

Inspired by:
#202

* eof

* Update traffic.md

* Update traffic.md

---------

Co-authored-by: Nicholas Wang <7414442+nicholascw@users.noreply.github.com>
  • Loading branch information
DolorHunter and nicholascw committed Sep 6, 2023
1 parent 286a863 commit 169ef71
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 135 deletions.
206 changes: 87 additions & 119 deletions zh_CN/advanced/traffic.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ V2Ray 内包含了流量记录器功能,但是默认并不启用。流量统

要实现流量统计功能,配置内需要确保存在以下配置:

1. `"stats":{}` 对象的存在;
1. `"stats", "api", "policy", "routing"` 对象的存在;
2. `"policy"` 中的统计开关为 true。全局统计的开关在 `"system"` 下,用户统计的开关在 `"levels"` 下;
3. 全局统计在相应的入站出站要有 tag;
4. 用户统计在 `"clients"` 里面要有 email;
Expand All @@ -21,117 +21,115 @@ V2Ray 内包含了流量记录器功能,但是默认并不启用。流量统
2. 专用的 `dokodemo-door` 协议的入口,tag 为 api;
3. routing 里面有 inboundTag:api -> outboundTag:api 的规则;

注意: 统计的 `email`/`tag` 是当前的 V2Ray 进程实例的数据,比如在服务器上统计,客户端写的 email 对服务器没有意义;如果在客户端统计,输出的就是客户端本身的数据。
注意: 统计的 `email` / `tag` 是当前的 V2Ray 进程实例的数据,比如在服务器上统计,客户端写的 email 对服务器没有意义;如果在客户端统计,输出的就是客户端本身的数据。

## 配置实例

```json
{
"stats": {},
"api": {
"tag": "api",
"services": [
"StatsService"
]
"stats": {},
"api": {
"tag": "api",
"services": [
"StatsService"
]
},
"policy": {
"levels": {
"0": {
"statsUserUplink": true,
"statsUserDownlink": true
}
},
"policy": {
"levels": {
"0": {
"statsUserUplink": true,
"statsUserDownlink": true
}
},
"system": {
"statsInboundUplink": true,
"statsInboundDownlink": true,
"statsOutboundUplink": true,
"statsOutboundDownlink": true
}
"system": {
"statsInboundUplink": true,
"statsInboundDownlink": true,
"statsOutboundUplink": true,
"statsOutboundDownlink": true
}
},
"inbounds": [
{
"tag": "tcp",
"port": 3307,
"protocol": "vmess",
"settings": {
"clients": [
{
"email": "userA",
"id": "e731f153-4f31-49d3-9e8f-ff8f396135ef",
"level": 0,
"alterId": 0
},
{
"email": "userB",
"id": "e731f153-4f31-49d3-9e8f-ff8f396135ee",
"level": 0,
"alterId": 0
}
]
}
},
"inbounds": [
{
"tag": "tcp",
"port": 3307,
"protocol": "vmess",
"settings": {
"clients": [
{
"email": "auser",
"id": "e731f153-4f31-49d3-9e8f-ff8f396135ef",
"level": 0,
"alterId": 64
},
{
"email": "buser",
"id": "e731f153-4f31-49d3-9e8f-ff8f396135ee",
"level": 0,
"alterId": 64
}
]
}
},
{
"listen": "127.0.0.1",
"port": 10085,
"protocol": "dokodemo-door",
"settings": {
"address": "127.0.0.1"
},
"tag": "api"
}
],
"outbounds": [
{
"tag": "direct",
"protocol": "freedom",
"settings": {}
}
],
"routing": {
"rules": [
{
"inboundTag": [
"api"
],
"outboundTag": "api",
"type": "field"
}
],
"domainStrategy": "AsIs"
{
"listen": "127.0.0.1",
"port": 10085,
"protocol": "dokodemo-door",
"settings": {
"address": "127.0.0.1"
},
"tag": "api"
}
],
"outbounds": [
{
"tag": "direct",
"protocol": "freedom",
"settings": {}
}
],
"routing": {
"rules": [
{
"inboundTag": [
"api"
],
"outboundTag": "api",
"type": "field"
}
],
"domainStrategy": "AsIs"
}
}
```

## 查看流量信息

查看流量信息是 `v2ctl` 的其中一个功能。使用 `v2ctl api -h` 可见查询例子。 配置内设置的 api dokodemo-door 端口,即为 `--server` 参数的端口。

可调用的 api 有两个:

* `QueryStats` 用来查询匹配的记录,可以使用参数 `pattern``reset`;pattern 留空则是匹配所有记录;reset 使匹配的单元数值置零。
* `GetStats` 用来其中一个的记录,接受 `name``reset`,name 可参考 QueryStats 的输出结果构建,reset 使该单元数值置零。

```bash
v2ctl api --server=127.0.0.1:10085 StatsService.QueryStats 'pattern: "" reset: false'
v2ctl api --server=127.0.0.1:10085 StatsService.GetStats 'name: "inbound>>>statin>>>traffic>>>downlink" reset: false'
```

```bash
v2ctl api --server=127.0.0.1:10085 StatsService.GetStats 'name: "inbound>>>api>>>traffic>>>downlink" reset: false'
```

*注:GetStats 参数 name 需做修改,可选值为 QueryStats 的结果。*

注意如果在 Windows 的 CMD 内运行,里面的引号要特别处理:

```cmd
v2ctl.exe api --server="127.0.0.1:10085" StatsService.GetStats "name: """"inbound>>>statin>>>traffic>>>downlink"""" reset: false"
```

可调用的 api 有两个:

* `QueryStats`用来查询匹配的记录,可以使用参数`pattern``reset`;pattern 留空则是匹配所有记录;reset 使匹配的单元数值置零。
* `GetStats`用来其中一个的记录,接受`name``reset`,name 可参考 QueryStats 的输出结果构建,reset 使该单元数值置零。

输出例子:

```text
$ /usr/local/bin/v2ctl api --server=127.0.0.1:10085 StatsService.GetStats 'name:"inbound>>>ws>>>traffic>>>uplink"'
stat: <
name: "inbound>>>ws>>>traffic>>>uplink"
value: 3350713
>
$
$
$ /usr/local/bin/v2ctl api --server=127.0.0.1:10085 StatsService.QueryStats ''
stat: <
name: "inbound>>>ws>>>traffic>>>uplink"
Expand All @@ -149,35 +147,12 @@ stat: <
name: "user>>>u9@ss>>>traffic>>>uplink"
value: 1776
>
...
$
$ /usr/local/bin/v2ctl api --server=127.0.0.1:10085 StatsService.GetStats 'name:"inbound>>>ws>>>traffic>>>uplink"'
stat: <
name: "inbound>>>ss>>>traffic>>>uplink"
value: 2276
>
stat: <
name: "inbound>>>api>>>traffic>>>uplink"
value: 318
>
stat: <
name: "user>>>u9@ss>>>traffic>>>downlink"
value: 1368
>
stat: <
name: "inbound>>>tcp>>>traffic>>>uplink"
>
stat: <
name: "inbound>>>tcp>>>traffic>>>downlink"
>
stat: <
name: "inbound>>>ws>>>traffic>>>downlink"
value: 130637140
>
stat: <
name: "inbound>>>api>>>traffic>>>downlink"
value: 759
>
stat: <
name: "user>>>u3@ws>>>traffic>>>downlink"
value: 126944108
name: "inbound>>>ws>>>traffic>>>uplink"
value: 3350713
>
```

Expand Down Expand Up @@ -269,10 +244,3 @@ SUM->TOTAL: 2.5GB

脚本使用 `reset` 参数让调用的计数单元置零,配合 watch 命令,即可查看流经 v2ray 的每秒实时流量速度:
`watch ./traffic.sh reset`

#### 更新历史

- 2019-08-07 统计脚本识别科学计数法的输出情况
- 2019-08-09 优化流量脚本,增加了 SUM->TOTAL 的累加项
- 2020-07-04 增加了 outbound 的流量统计
- 2020-12-13 修复 v2ctl 路径,脚本添加 outbound 统计
21 changes: 5 additions & 16 deletions zh_CN/basics/vmess.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ $ jq . config.json

不过,最好还是使用 V2Ray 提供的配置检查功能(test 选项),因为可以检查 JSON 语法错误外的问题,比如说突然间手抖把 vmess 写成了 vmss,一下子就检查出来了。
```plain
$ /usr/bin/v2ray/v2ray test -config /etc/v2ray/config.json
$ /usr/local/bin/v2ray -test -config /usr/local/etc/v2ray/config.json
failed to parse json config: Ext|Tools|Conf|Serial: failed to parse json config > Ext|Tools|Conf: failed to load inbound detour config. > Ext|Tools|Conf: unknown config id: vmss
Main: failed to read config file: /etc/v2ray/config.json > Main|Json: failed to execute v2ctl to convert config file. > exit status 255
Main: failed to read config file: /usr/local/etc/v2ray/config.json > Main|Json: failed to execute v2ctl to convert config file. > exit status 255
```

如果是配置文件没问题,则是这样的:

```plain
$ /usr/bin/v2ray/v2ray test -config /etc/v2ray/config.json
$ /usr/local/bin/v2ray -test -config /usr/local/etc/v2ray/config.json
V2Ray v3.15 (die Commanderin) 20180329
An unified platform for anti-censorship.
Configuration OK.
Expand Down Expand Up @@ -234,16 +236,3 @@ VMess 协议的认证基于时间,一定要保证服务器和客户端的系
2). 直接放弃;

3). 向大牛请教。

-----

#### 更新历史

- 2017-08-08 排错指引补充
- 2017-08-06 添加排错指引
- 2018-02-09 补充说明
- 2018-04-05 内容补充
- 2018-09-03 更进一些 V2Ray 的变化,并修改一些描述
- 2018-11-09 跟进新 v4.0+ 的配置格式
- 2018-02-01 domainOverride 改为 sniffing
- 2019-10-27 sniffing 不再影响 tor 的使用

0 comments on commit 169ef71

Please sign in to comment.