Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{
"stats": {},
"api": {
"services": [
"StatsService"
],
"tag": "api"
},
"policy": {
"levels": {
"0": {
"connIdle": 300,
"downlinkOnly": 30,
"handshake": 4,
"uplinkOnly": 5,
"statsUserDownlink": true,
"statsUserUplink": true
}
}
},
"inbound": {
"port": 8002,
"protocol": "vmess",
"settings": {
"clients": [
{
"alterId": 64,
"email": "123@gmail.com",
"id": "e731f153-4f31-49d3-9e8f-ff8f396135ef",
"level": 0
}
],
"disableInsecureEncryption": true
},
"streamSettings": {
"network": "tcp"
}
},
"inboundDetour": [
{
"listen": "127.0.0.1",
"port": 10085,
"protocol": "dokodemo-door",
"settings": {
"address": "127.0.0.1"
},
"tag": "api"
}
],
"outbound": {
"protocol": "freedom",
"settings": {}
},
"routing": {
"settings": {
"rules": [
{
"inboundTag": [
"api"
],
"outboundTag": "api",
"type": "field"
}
]
},
"strategy": "rules"
}
}
@boypt

This comment has been minimized.

Copy link

@boypt boypt commented Dec 28, 2018

折腾一下午,总结以下,API获得数据统计功能,配置里面必须满足以下条件

  1. "stats":{}对象的存在
  2. "api"配置对象里面有StatsService
  3. "policy"中的统计开关为true,除了各个用户的统计,还有全局统计
  4. 当前进程的clients里面要有email
  5. 有个专用的dokodemo-door协议的入口,tag为api
  6. routing里面有inboundTag:api -> outboundTag:api的规则

另外:

  • inboundDetour在后来的版本(4.9.0测试,不确定哪版本开始)里面不作为一个单独的顶层配置,而是写到inbounds里面,新版的文档已经去掉了inboundDetour,但是配置里面还可以支持。
  • 统计的email/tag是当前的v2ray进程实例的数据,比如在服务器上统计,客户端写的email对服务器没有意义;如果在客户端统计,输出的就是客户端本身的收发数据。
  • 统计API里面除了GetStats,新版本还加入了QueryStats方法,可以列出进程内的所有统计数据,包括各个tag/email的用户。v2ctl源码还没更新支持这个方法,但是API已经支持了(4.9.0)。

最后贴一份我的测试配置

{
	"stats": {},
	"log": {
		"loglevel": "debug"
	},
	"api": {
		"tag": "api",
		"services": [
			"HandlerService",
			"LoggerService",
			"StatsService"
		]
	},
	"policy": {
		"levels": {
			"0": {
				"statsUserUplink": true,
				"statsUserDownlink": true
			},
			"1": {
				"statsUserUplink": true,
				"statsUserDownlink": true
			}
		},
		"system": {
			"statsInboundUplink": true,
			"statsInboundDownlink": true
		}
	},
	"inbounds": [
		{
			"tag": "tcp",
			"port": 3307,
			"protocol": "vmess",
			"settings": {
				"clients": [
					{
						"email": "a@mail",
						"id": "e731f153-4f31-49d3-9e8f-ff8f396135ef",
						"level": 1,
						"alterId": 64
					},
					{
						"email": "b@mail",
						"id": "e731f153-4f31-49d3-9e8f-ff8f396135ee",
						"level": 1,
						"alterId": 64
					}
				]
			}
		},
		{
			"tag": "tls",
			"port": 8443,
			"protocol": "vmess",
			"settings": {
				"clients": [
					{
						"email": "c@mail",
						"id": "e731f153-4f31-49d3-9e8f-ff8f396135ef",
						"level": 1,
						"alterId": 64
					},
					{
						"email": "d@mail",
						"id": "e731f153-4f31-49d3-9e8f-ff8f396135ee",
						"level": 1,
						"alterId": 64
					}
				]
			},
			"streamSettings": {
				"network": "tcp",
				"security": "tls",
				"tlsSettings": {
					"certificates": [
						{
							"certificateFile": "xxx.crt",
							"keyFile": "xxx.key"
						}
					]
				}
			}
		},
		{
			"listen": "127.0.0.1",
			"port": 10085,
			"protocol": "dokodemo-door",
			"settings": {
				"address": "127.0.0.1"
			},
			"tag": "api"
		}
	],
	"outbounds": [
		{
			"protocol": "freedom",
			"settings": {}
		}
	],
	"routing": {
		"settings": {
			"rules": [
				{
					"inboundTag": [
						"api"
					],
					"outboundTag": "api",
					"type": "field"
				}
			]
		},
		"strategy": "rules"
	}
}
@yukiloh

This comment has been minimized.

Copy link

@yukiloh yukiloh commented Dec 3, 2019

笑死,任意门dokodemodoor,程序员的浪漫

@tedjsmeng

This comment has been minimized.

Copy link

@tedjsmeng tedjsmeng commented May 15, 2020

太棒了,你的一个下午帮助我省了不止一个下午!!

@ZhuccIvan

This comment has been minimized.

Copy link

@ZhuccIvan ZhuccIvan commented Dec 19, 2020

配置啥的都没啥问题,为啥总是显示无法连通
v2ray.com/core/infra/control: failed to dial 127.0.0.1:10085 > context deadline exceeded
我看10085端口也是listen的

@IceCapriccio

This comment has been minimized.

Copy link

@IceCapriccio IceCapriccio commented Jan 12, 2021

配置啥的都没啥问题,为啥总是显示无法连通
v2ray.com/core/infra/control: failed to dial 127.0.0.1:10085 > context deadline exceeded
我看10085端口也是listen的

相同的问题,你解决了吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment