Measure traffic from outbounds
With v2ray-core 4.26.0, traffic can be measured from outbounds. Stats is shown separately for proxy and direct traffic. In the future, it is possible to add stats for each server node and even historic usage graph.
This commit is contained in:
@@ -119,7 +119,7 @@ func (v V2RayPoint) QueryStats(tag string, direct string) int64 {
|
||||
if v.statsManager == nil {
|
||||
return 0
|
||||
}
|
||||
counter := v.statsManager.GetCounter(fmt.Sprintf("inbound>>>%s>>>traffic>>>%s", tag, direct))
|
||||
counter := v.statsManager.GetCounter(fmt.Sprintf("outbound>>>%s>>>traffic>>>%s", tag, direct))
|
||||
if counter == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
}
|
||||
},
|
||||
"system": {
|
||||
"statsInboundUplink": true,
|
||||
"statsInboundDownlink": true
|
||||
"statsOutboundUplink": true,
|
||||
"statsOutboundDownlink": true
|
||||
}
|
||||
},
|
||||
"inbounds": [{
|
||||
|
||||
@@ -361,7 +361,7 @@ class V2RayVpnService : VpnService() {
|
||||
|
||||
private fun updateNotification(contentText: String) {
|
||||
if (mBuilder != null) {
|
||||
mBuilder?.setContentTitle(contentText)
|
||||
mBuilder?.setStyle(NotificationCompat.BigTextStyle().bigText(contentText))
|
||||
getNotificationManager().notify(NOTIFICATION_ID, mBuilder?.build())
|
||||
}
|
||||
}
|
||||
@@ -382,13 +382,18 @@ class V2RayVpnService : VpnService() {
|
||||
|
||||
mSubscription = Observable.interval(3, java.util.concurrent.TimeUnit.SECONDS)
|
||||
.subscribe {
|
||||
val uplink = v2rayPoint.queryStats("socks", "uplink")
|
||||
val downlink = v2rayPoint.queryStats("socks", "downlink")
|
||||
val zero_speed = (uplink == 0L && downlink == 0L)
|
||||
val proxyUplink = v2rayPoint.queryStats("proxy", "uplink")
|
||||
val proxyDownlink = v2rayPoint.queryStats("proxy", "downlink")
|
||||
val directUplink = v2rayPoint.queryStats("direct", "uplink")
|
||||
val directDownlink = v2rayPoint.queryStats("direct", "downlink")
|
||||
val zero_speed = (proxyUplink == 0L && proxyDownlink == 0L && directUplink == 0L && directDownlink == 0L)
|
||||
val queryTime = System.currentTimeMillis()
|
||||
if (!zero_speed || !last_zero_speed) {
|
||||
updateNotification("${cf_name} • ${(uplink * 1000 / (queryTime - lastQueryTime)).toSpeedString()}↑" +
|
||||
" ${(downlink * 1000 / (queryTime - lastQueryTime)).toSpeedString()}↓")
|
||||
val sinceLastQueryInSeconds = (queryTime - lastQueryTime) / 1000.0
|
||||
updateNotification("proxy\t• ${(proxyUplink / sinceLastQueryInSeconds).toLong().toSpeedString()}↑ " +
|
||||
"${(proxyDownlink / sinceLastQueryInSeconds).toLong().toSpeedString()}↓\n" +
|
||||
"direct\t• ${(directUplink / sinceLastQueryInSeconds).toLong().toSpeedString()}↑ " +
|
||||
"${(directDownlink / sinceLastQueryInSeconds).toLong().toSpeedString()}↓")
|
||||
}
|
||||
last_zero_speed = zero_speed
|
||||
lastQueryTime = queryTime
|
||||
|
||||
Reference in New Issue
Block a user