Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 26 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save eycorsican/aa8cdc1d39c3fa355c499f89a15b9753 to your computer and use it in GitHub Desktop.
Save eycorsican/aa8cdc1d39c3fa355c499f89a15b9753 to your computer and use it in GitHub Desktop.
{
"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
Copy link

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
Copy link

yukiloh commented Dec 3, 2019

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

@tedjsmeng
Copy link

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

@ZhuccIvan
Copy link

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

@IceCapriccio
Copy link

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

相同的问题,你解决了吗

@malongmedea
Copy link

配置啥的啥问题,为啥总是显示无法查看
v2ray.com/core/infra/control: failed to dial 127.0.0.1:10085 > context deadline exceeded
我10085也是监听的

相同的问题,你解决了吗

我也遇到了相同的问题,你们解决了吗?

@malongmedea
Copy link

我发现问题了,我使用了别人的配置文件,没注意到routing配置中有一条"127.0.0.0/8"的blocked规则。将其删除就可以正常统计了

@rayguo17
Copy link

这个问题,是不是可以单独发个issue啊

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

这个问题有没有单独的issue啊。我的配置里面没有block的规则,但还是不行。但我使用的是v2ray api stats 显示
root@butler-virtual-machine:/etc/resolvconf/resolv.conf.d# v2ray api stats
failed to dial 127.0.0.1:8080

@hnyyghk
Copy link

hnyyghk commented Oct 27, 2022

这个问题,是不是可以单独发个issue啊

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

这个问题有没有单独的issue啊。我的配置里面没有block的规则,但还是不行。但我使用的是v2ray api stats 显示 root@butler-virtual-machine:/etc/resolvconf/resolv.conf.d# v2ray api stats failed to dial 127.0.0.1:8080

你这个报错应该是端口号不对,默认端口8080,要加上--server=127.0.0.1:10085,命令用法也有变化

$ v2ray api stats --server=127.0.0.1:10085
Value Name
1 1.59KB inbound>>>api>>>traffic>>>downlink
2 2.97KB inbound>>>api>>>traffic>>>uplink
3 196.23KB inbound>>>vmess-ws>>>traffic>>>downlink
4 66.02KB inbound>>>vmess-ws>>>traffic>>>uplink
5 182.23KB user>>>love@v2ray.com>>>traffic>>>downlink
6 49.75KB user>>>love@v2ray.com>>>traffic>>>uplink

Total: 498.78KB

$ v2ray api stats --server=127.0.0.1:10085 StatsService.GetStats 'inbound>>>vmess-ws>>>traffic>>>uplink'
Value Name
1 39.59KB inbound>>>vmess-ws>>>traffic>>>uplink

Total: 39.59KB

@rayguo17
Copy link

这个问题,是不是可以单独发个issue啊

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

这个问题有没有单独的issue啊。我的配置里面没有block的规则,但还是不行。但我使用的是v2ray api stats 显示 root@butler-virtual-machine:/etc/resolvconf/resolv.conf.d# v2ray api stats failed to dial 127.0.0.1:8080

你这个报错应该是端口号不对,默认端口8080,要加上--server=127.0.0.1:10085,命令用法也有变化

$ v2ray api stats --server=127.0.0.1:10085 Value Name 1 1.59KB inbound>>>api>>>traffic>>>downlink 2 2.97KB inbound>>>api>>>traffic>>>uplink 3 196.23KB inbound>>>vmess-ws>>>traffic>>>downlink 4 66.02KB inbound>>>vmess-ws>>>traffic>>>uplink 5 182.23KB user>>>love@v2ray.com>>>traffic>>>downlink 6 49.75KB user>>>love@v2ray.com>>>traffic>>>uplink

Total: 498.78KB

$ v2ray api stats --server=127.0.0.1:10085 StatsService.GetStats 'inbound>>>vmess-ws>>>traffic>>>uplink' Value Name 1 39.59KB inbound>>>vmess-ws>>>traffic>>>uplink

Total: 39.59KB

后面解决了,问题如下:
{ "stats": {}, "log": { "loglevel": "debug" }, "api": { "tag": "api", "services": [ "HandlerService", "LoggerService", "StatsService" //开启了stats服务,但是后面的policy,system没有设置 ] }, "policy": { "levels": { "0": { "statsUserUplink": true, "statsUserDownlink": true }, "1": { "statsUserUplink": true, "statsUserDownlink": true } }, "system": { "statsInboundUplink": true, "statsInboundDownlink": true //这里没有设置 } }, }
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
参考上面的链接的“配置统计功能”一栏,要按着里面的配置操作,才能顺利运行

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