From ff7172c09a253e6b4ccd7b1b2c90cac76c1b2f49 Mon Sep 17 00:00:00 2001 From: BOYPT Date: Sat, 23 Feb 2019 18:30:16 +0800 Subject: [PATCH] add view traffic --- config/server/dynamic/http.json | 42 ++++++++++++++++++++++++++++++++ config/server/dynamic/kcp.json | 42 ++++++++++++++++++++++++++++++++ config/server/dynamic/quic.json | 42 ++++++++++++++++++++++++++++++++ config/server/dynamic/tcp.json | 42 ++++++++++++++++++++++++++++++++ config/server/dynamic/ws.json | 42 ++++++++++++++++++++++++++++++++ config/server/h2.json | 42 ++++++++++++++++++++++++++++++++ config/server/http.json | 42 ++++++++++++++++++++++++++++++++ config/server/include/socks.json | 1 + config/server/include/ss.json | 1 + config/server/kcp.json | 42 ++++++++++++++++++++++++++++++++ config/server/quic.json | 42 ++++++++++++++++++++++++++++++++ config/server/tcp.json | 42 ++++++++++++++++++++++++++++++++ config/server/ws.json | 42 ++++++++++++++++++++++++++++++++ src/v2ray-traffic.sh | 33 +++++++++++++++++++++++++ 14 files changed, 497 insertions(+) create mode 100644 src/v2ray-traffic.sh diff --git a/config/server/dynamic/http.json b/config/server/dynamic/http.json index 4661469..35cb038 100644 --- a/config/server/dynamic/http.json +++ b/config/server/dynamic/http.json @@ -1,4 +1,29 @@ { + "stats": {}, + "api": { + "tag": "api", + "services": [ + "HandlerService", + "LoggerService", + "StatsService" + ] + }, + "policy": { + "levels": { + "0": { + "statsUserUplink": true, + "statsUserDownlink": true + }, + "1": { + "statsUserUplink": true, + "statsUserDownlink": true + } + }, + "system": { + "statsInboundUplink": true, + "statsInboundDownlink": true + } + }, "log": { "access": "/var/log/v2ray/access.log", "error": "/var/log/v2ray/error.log", @@ -6,6 +31,16 @@ }, "inbounds": [ { + "listen": "127.0.0.1", + "port": 10086, + "protocol": "dokodemo-door", + "settings": { + "address": "127.0.0.1" + }, + "tag": "api" + }, + { + "tag": "vmess-in", "port": 2333, "protocol": "vmess", "settings": { @@ -129,6 +164,13 @@ "routing": { "domainStrategy": "IPOnDemand", "rules": [ + { + "inboundTag": [ + "api" + ], + "outboundTag": "api", + "type": "field" + }, { "type": "field", "ip": [ diff --git a/config/server/dynamic/kcp.json b/config/server/dynamic/kcp.json index 48e3b8b..ddf9bd7 100644 --- a/config/server/dynamic/kcp.json +++ b/config/server/dynamic/kcp.json @@ -1,4 +1,29 @@ { + "stats": {}, + "api": { + "tag": "api", + "services": [ + "HandlerService", + "LoggerService", + "StatsService" + ] + }, + "policy": { + "levels": { + "0": { + "statsUserUplink": true, + "statsUserDownlink": true + }, + "1": { + "statsUserUplink": true, + "statsUserDownlink": true + } + }, + "system": { + "statsInboundUplink": true, + "statsInboundDownlink": true + } + }, "log": { "access": "/var/log/v2ray/access.log", "error": "/var/log/v2ray/error.log", @@ -6,6 +31,16 @@ }, "inbounds": [ { + "listen": "127.0.0.1", + "port": 10086, + "protocol": "dokodemo-door", + "settings": { + "address": "127.0.0.1" + }, + "tag": "api" + }, + { + "tag": "vmess-in", "port": 2333, "protocol": "vmess", "settings": { @@ -101,6 +136,13 @@ "routing": { "domainStrategy": "IPOnDemand", "rules": [ + { + "inboundTag": [ + "api" + ], + "outboundTag": "api", + "type": "field" + }, { "type": "field", "ip": [ diff --git a/config/server/dynamic/quic.json b/config/server/dynamic/quic.json index 16911b4..b65a6c6 100644 --- a/config/server/dynamic/quic.json +++ b/config/server/dynamic/quic.json @@ -1,4 +1,29 @@ { + "stats": {}, + "api": { + "tag": "api", + "services": [ + "HandlerService", + "LoggerService", + "StatsService" + ] + }, + "policy": { + "levels": { + "0": { + "statsUserUplink": true, + "statsUserDownlink": true + }, + "1": { + "statsUserUplink": true, + "statsUserDownlink": true + } + }, + "system": { + "statsInboundUplink": true, + "statsInboundDownlink": true + } + }, "log": { "access": "/var/log/v2ray/access.log", "error": "/var/log/v2ray/error.log", @@ -6,6 +31,16 @@ }, "inbounds": [ { + "listen": "127.0.0.1", + "port": 10086, + "protocol": "dokodemo-door", + "settings": { + "address": "127.0.0.1" + }, + "tag": "api" + }, + { + "tag": "vmess-in", "port": 2333, "protocol": "vmess", "settings": { @@ -105,6 +140,13 @@ "routing": { "domainStrategy": "IPOnDemand", "rules": [ + { + "inboundTag": [ + "api" + ], + "outboundTag": "api", + "type": "field" + }, { "type": "field", "ip": [ diff --git a/config/server/dynamic/tcp.json b/config/server/dynamic/tcp.json index 7c4d90b..7662492 100644 --- a/config/server/dynamic/tcp.json +++ b/config/server/dynamic/tcp.json @@ -1,4 +1,29 @@ { + "stats": {}, + "api": { + "tag": "api", + "services": [ + "HandlerService", + "LoggerService", + "StatsService" + ] + }, + "policy": { + "levels": { + "0": { + "statsUserUplink": true, + "statsUserDownlink": true + }, + "1": { + "statsUserUplink": true, + "statsUserDownlink": true + } + }, + "system": { + "statsInboundUplink": true, + "statsInboundDownlink": true + } + }, "log": { "access": "/var/log/v2ray/access.log", "error": "/var/log/v2ray/error.log", @@ -6,6 +31,16 @@ }, "inbounds": [ { + "listen": "127.0.0.1", + "port": 10086, + "protocol": "dokodemo-door", + "settings": { + "address": "127.0.0.1" + }, + "tag": "api" + }, + { + "tag": "vmess-in", "port": 2333, "protocol": "vmess", "settings": { @@ -88,6 +123,13 @@ "routing": { "domainStrategy": "IPOnDemand", "rules": [ + { + "inboundTag": [ + "api" + ], + "outboundTag": "api", + "type": "field" + }, { "type": "field", "ip": [ diff --git a/config/server/dynamic/ws.json b/config/server/dynamic/ws.json index 51c889a..d57d632 100644 --- a/config/server/dynamic/ws.json +++ b/config/server/dynamic/ws.json @@ -1,4 +1,29 @@ { + "stats": {}, + "api": { + "tag": "api", + "services": [ + "HandlerService", + "LoggerService", + "StatsService" + ] + }, + "policy": { + "levels": { + "0": { + "statsUserUplink": true, + "statsUserDownlink": true + }, + "1": { + "statsUserUplink": true, + "statsUserDownlink": true + } + }, + "system": { + "statsInboundUplink": true, + "statsInboundDownlink": true + } + }, "log": { "access": "/var/log/v2ray/access.log", "error": "/var/log/v2ray/error.log", @@ -6,6 +31,16 @@ }, "inbounds": [ { + "listen": "127.0.0.1", + "port": 10086, + "protocol": "dokodemo-door", + "settings": { + "address": "127.0.0.1" + }, + "tag": "api" + }, + { + "tag": "vmess-in", "port": 2333, "protocol": "vmess", "settings": { @@ -91,6 +126,13 @@ "routing": { "domainStrategy": "IPOnDemand", "rules": [ + { + "inboundTag": [ + "api" + ], + "outboundTag": "api", + "type": "field" + }, { "type": "field", "ip": [ diff --git a/config/server/h2.json b/config/server/h2.json index 6be2a38..e49b59f 100644 --- a/config/server/h2.json +++ b/config/server/h2.json @@ -1,4 +1,29 @@ { + "stats": {}, + "api": { + "tag": "api", + "services": [ + "HandlerService", + "LoggerService", + "StatsService" + ] + }, + "policy": { + "levels": { + "0": { + "statsUserUplink": true, + "statsUserDownlink": true + }, + "1": { + "statsUserUplink": true, + "statsUserDownlink": true + } + }, + "system": { + "statsInboundUplink": true, + "statsInboundDownlink": true + } + }, "log": { "access": "/var/log/v2ray/access.log", "error": "/var/log/v2ray/error.log", @@ -6,6 +31,16 @@ }, "inbounds": [ { + "listen": "127.0.0.1", + "port": 10086, + "protocol": "dokodemo-door", + "settings": { + "address": "127.0.0.1" + }, + "tag": "api" + }, + { + "tag": "vmess-in", "port": 2333, "protocol": "vmess", "settings": { @@ -84,6 +119,13 @@ "routing": { "domainStrategy": "IPOnDemand", "rules": [ + { + "inboundTag": [ + "api" + ], + "outboundTag": "api", + "type": "field" + }, { "type": "field", "ip": [ diff --git a/config/server/http.json b/config/server/http.json index 77e1a8b..fe7dcd6 100644 --- a/config/server/http.json +++ b/config/server/http.json @@ -1,4 +1,29 @@ { + "stats": {}, + "api": { + "tag": "api", + "services": [ + "HandlerService", + "LoggerService", + "StatsService" + ] + }, + "policy": { + "levels": { + "0": { + "statsUserUplink": true, + "statsUserDownlink": true + }, + "1": { + "statsUserUplink": true, + "statsUserDownlink": true + } + }, + "system": { + "statsInboundUplink": true, + "statsInboundDownlink": true + } + }, "log": { "access": "/var/log/v2ray/access.log", "error": "/var/log/v2ray/error.log", @@ -6,6 +31,16 @@ }, "inbounds": [ { + "listen": "127.0.0.1", + "port": 10086, + "protocol": "dokodemo-door", + "settings": { + "address": "127.0.0.1" + }, + "tag": "api" + }, + { + "tag": "vmess-in", "port": 2333, "protocol": "vmess", "settings": { @@ -102,6 +137,13 @@ "routing": { "domainStrategy": "IPOnDemand", "rules": [ + { + "inboundTag": [ + "api" + ], + "outboundTag": "api", + "type": "field" + }, { "type": "field", "ip": [ diff --git a/config/server/include/socks.json b/config/server/include/socks.json index 41aa472..070a074 100644 --- a/config/server/include/socks.json +++ b/config/server/include/socks.json @@ -1,4 +1,5 @@ { + "tag": "socks-in", "protocol": "socks", "port": 6666, "settings": { diff --git a/config/server/include/ss.json b/config/server/include/ss.json index 537ceb1..bdba112 100644 --- a/config/server/include/ss.json +++ b/config/server/include/ss.json @@ -1,4 +1,5 @@ { + "tag": "ss-in", "protocol": "shadowsocks", "port": 6666, "settings": { diff --git a/config/server/kcp.json b/config/server/kcp.json index bca8dad..bbdc8dd 100644 --- a/config/server/kcp.json +++ b/config/server/kcp.json @@ -1,4 +1,29 @@ { + "stats": {}, + "api": { + "tag": "api", + "services": [ + "HandlerService", + "LoggerService", + "StatsService" + ] + }, + "policy": { + "levels": { + "0": { + "statsUserUplink": true, + "statsUserDownlink": true + }, + "1": { + "statsUserUplink": true, + "statsUserDownlink": true + } + }, + "system": { + "statsInboundUplink": true, + "statsInboundDownlink": true + } + }, "log": { "access": "/var/log/v2ray/access.log", "error": "/var/log/v2ray/error.log", @@ -6,6 +31,16 @@ }, "inbounds": [ { + "listen": "127.0.0.1", + "port": 10086, + "protocol": "dokodemo-door", + "settings": { + "address": "127.0.0.1" + }, + "tag": "api" + }, + { + "tag": "vmess-in", "port": 2333, "protocol": "vmess", "settings": { @@ -74,6 +109,13 @@ "routing": { "domainStrategy": "IPOnDemand", "rules": [ + { + "inboundTag": [ + "api" + ], + "outboundTag": "api", + "type": "field" + }, { "type": "field", "ip": [ diff --git a/config/server/quic.json b/config/server/quic.json index 2379fd1..b15be9a 100644 --- a/config/server/quic.json +++ b/config/server/quic.json @@ -1,4 +1,29 @@ { + "stats": {}, + "api": { + "tag": "api", + "services": [ + "HandlerService", + "LoggerService", + "StatsService" + ] + }, + "policy": { + "levels": { + "0": { + "statsUserUplink": true, + "statsUserDownlink": true + }, + "1": { + "statsUserUplink": true, + "statsUserDownlink": true + } + }, + "system": { + "statsInboundUplink": true, + "statsInboundDownlink": true + } + }, "log": { "access": "/var/log/v2ray/access.log", "error": "/var/log/v2ray/error.log", @@ -6,6 +31,16 @@ }, "inbounds": [ { + "listen": "127.0.0.1", + "port": 10086, + "protocol": "dokodemo-door", + "settings": { + "address": "127.0.0.1" + }, + "tag": "api" + }, + { + "tag": "vmess-in", "port": 2333, "protocol": "vmess", "settings": { @@ -76,6 +111,13 @@ "routing": { "domainStrategy": "IPOnDemand", "rules": [ + { + "inboundTag": [ + "api" + ], + "outboundTag": "api", + "type": "field" + }, { "type": "field", "ip": [ diff --git a/config/server/tcp.json b/config/server/tcp.json index 01819bf..2b70122 100644 --- a/config/server/tcp.json +++ b/config/server/tcp.json @@ -1,4 +1,29 @@ { + "stats": {}, + "api": { + "tag": "api", + "services": [ + "HandlerService", + "LoggerService", + "StatsService" + ] + }, + "policy": { + "levels": { + "0": { + "statsUserUplink": true, + "statsUserDownlink": true + }, + "1": { + "statsUserUplink": true, + "statsUserDownlink": true + } + }, + "system": { + "statsInboundUplink": true, + "statsInboundDownlink": true + } + }, "log": { "access": "/var/log/v2ray/access.log", "error": "/var/log/v2ray/error.log", @@ -6,6 +31,16 @@ }, "inbounds": [ { + "listen": "127.0.0.1", + "port": 10086, + "protocol": "dokodemo-door", + "settings": { + "address": "127.0.0.1" + }, + "tag": "api" + }, + { + "tag": "vmess-in", "port": 2333, "protocol": "vmess", "settings": { @@ -69,6 +104,13 @@ "routing": { "domainStrategy": "IPOnDemand", "rules": [ + { + "inboundTag": [ + "api" + ], + "outboundTag": "api", + "type": "field" + }, { "type": "field", "ip": [ diff --git a/config/server/ws.json b/config/server/ws.json index 4a45f22..2a5f302 100644 --- a/config/server/ws.json +++ b/config/server/ws.json @@ -1,4 +1,29 @@ { + "stats": {}, + "api": { + "tag": "api", + "services": [ + "HandlerService", + "LoggerService", + "StatsService" + ] + }, + "policy": { + "levels": { + "0": { + "statsUserUplink": true, + "statsUserDownlink": true + }, + "1": { + "statsUserUplink": true, + "statsUserDownlink": true + } + }, + "system": { + "statsInboundUplink": true, + "statsInboundDownlink": true + } + }, "log": { "access": "/var/log/v2ray/access.log", "error": "/var/log/v2ray/error.log", @@ -6,6 +31,16 @@ }, "inbounds": [ { + "listen": "127.0.0.1", + "port": 10086, + "protocol": "dokodemo-door", + "settings": { + "address": "127.0.0.1" + }, + "tag": "api" + }, + { + "tag": "vmess-in", "port": 2333, "protocol": "vmess", "settings": { @@ -69,6 +104,13 @@ "routing": { "domainStrategy": "IPOnDemand", "rules": [ + { + "inboundTag": [ + "api" + ], + "outboundTag": "api", + "type": "field" + }, { "type": "field", "ip": [ diff --git a/src/v2ray-traffic.sh b/src/v2ray-traffic.sh new file mode 100644 index 0000000..46d303c --- /dev/null +++ b/src/v2ray-traffic.sh @@ -0,0 +1,33 @@ + +_V2CTL=/usr/bin/v2ray/v2ctl +_APISERVER=127.0.0.1:10086 + +v2_inbound() { + local inbound=$1 + local direct=$2 + $_V2CTL api --server=$_APISERVER StatsService.GetStats "name: \"inbound>>>${inbound}>>>traffic>>>${direct}\"" \ + | awk '{ + if (match($1, /name:/)){ f=1; gsub(/"$/, "", $2); split($2, p, ">>>"); print p[2]":"p[4] } + else if (match($1, /value:/)){ f=0; print $2} + else if (match($0, /^>$/) && f == 1) print "0" + else {} + }' \ + | sed '$!N;s/\n/ /; s/link//' \ + | numfmt --field=2 --suffix=B --to=iec \ + | sort \ + | column -t +} + +v2_query_all () { + $_V2CTL api --server=$_APISERVER StatsService.QueryStats '' \ + | awk '{ + if (match($1, /name:/)){ f=1; gsub(/"$/, "", $2); split($2, p, ">>>"); print p[2]":"p[4] } + else if (match($1, /value:/)){ f=0; print $2} + else if (match($0, /^>$/) && f == 1) print "0" + else {} + }' \ + | sed '$!N;s/\n/ /; s/link//' \ + | numfmt --field=2 --suffix=B --to=iec \ + | sort \ + | column -t +}