mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-10-11 19:56:37 +08:00
修复流量统计问题
This commit is contained in:
@@ -53,6 +53,7 @@ public class FlowController extends BaseController {
|
|||||||
// 用于同步相同用户和隧道的流量更新操作
|
// 用于同步相同用户和隧道的流量更新操作
|
||||||
private static final ConcurrentHashMap<String, Object> USER_LOCKS = new ConcurrentHashMap<>();
|
private static final ConcurrentHashMap<String, Object> USER_LOCKS = new ConcurrentHashMap<>();
|
||||||
private static final ConcurrentHashMap<String, Object> TUNNEL_LOCKS = new ConcurrentHashMap<>();
|
private static final ConcurrentHashMap<String, Object> TUNNEL_LOCKS = new ConcurrentHashMap<>();
|
||||||
|
private static final ConcurrentHashMap<String, Object> FORWARD_LOCKS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping("/test")
|
@RequestMapping("/test")
|
||||||
@@ -147,7 +148,6 @@ public class FlowController extends BaseController {
|
|||||||
if (tunnel != null){
|
if (tunnel != null){
|
||||||
BigDecimal trafficRatio = tunnel.getTrafficRatio();
|
BigDecimal trafficRatio = tunnel.getTrafficRatio();
|
||||||
for (FlowDto flowDto : flowDataList) {
|
for (FlowDto flowDto : flowDataList) {
|
||||||
System.out.println(flowDto);
|
|
||||||
BigDecimal originalD = BigDecimal.valueOf(flowDto.getD());
|
BigDecimal originalD = BigDecimal.valueOf(flowDto.getD());
|
||||||
BigDecimal originalU = BigDecimal.valueOf(flowDto.getU());
|
BigDecimal originalU = BigDecimal.valueOf(flowDto.getU());
|
||||||
|
|
||||||
@@ -156,7 +156,6 @@ public class FlowController extends BaseController {
|
|||||||
|
|
||||||
flowDto.setD(newD.longValue());
|
flowDto.setD(newD.longValue());
|
||||||
flowDto.setU(newU.longValue());
|
flowDto.setU(newU.longValue());
|
||||||
System.out.println(flowDto);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -214,12 +213,15 @@ public class FlowController extends BaseController {
|
|||||||
* 更新转发流量统计 - 使用原子操作避免并发问题
|
* 更新转发流量统计 - 使用原子操作避免并发问题
|
||||||
*/
|
*/
|
||||||
private boolean updateForwardFlow(String forwardId, FlowStatistics flowStats) {
|
private boolean updateForwardFlow(String forwardId, FlowStatistics flowStats) {
|
||||||
UpdateWrapper<Forward> updateWrapper = new UpdateWrapper<>();
|
// 对相同转发的流量更新进行同步,避免并发覆盖
|
||||||
updateWrapper.eq("id", forwardId);
|
synchronized (getForwardLock(forwardId)) {
|
||||||
updateWrapper.setSql("in_flow = in_flow + " + flowStats.getDownload());
|
UpdateWrapper<Forward> updateWrapper = new UpdateWrapper<>();
|
||||||
updateWrapper.setSql("out_flow = out_flow + " + flowStats.getUpload());
|
updateWrapper.eq("id", forwardId);
|
||||||
|
updateWrapper.setSql("in_flow = in_flow + " + flowStats.getDownload());
|
||||||
|
updateWrapper.setSql("out_flow = out_flow + " + flowStats.getUpload());
|
||||||
|
|
||||||
return forwardService.update(null, updateWrapper);
|
return forwardService.update(null, updateWrapper);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -498,6 +500,13 @@ public class FlowController extends BaseController {
|
|||||||
return TUNNEL_LOCKS.computeIfAbsent(userTunnelId, k -> new Object());
|
return TUNNEL_LOCKS.computeIfAbsent(userTunnelId, k -> new Object());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取转发锁对象
|
||||||
|
*/
|
||||||
|
private Object getForwardLock(String forwardId) {
|
||||||
|
return FORWARD_LOCKS.computeIfAbsent(forwardId, k -> new Object());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 流量统计数据类
|
* 流量统计数据类
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -33,16 +33,6 @@
|
|||||||
<div class="tunnel-badges">
|
<div class="tunnel-badges">
|
||||||
<el-tag v-if="tunnel.type === 1" type="primary" size="mini">端口转发</el-tag>
|
<el-tag v-if="tunnel.type === 1" type="primary" size="mini">端口转发</el-tag>
|
||||||
<el-tag v-else type="warning" size="mini">隧道转发</el-tag>
|
<el-tag v-else type="warning" size="mini">隧道转发</el-tag>
|
||||||
<el-tag v-if="tunnel.type === 2 && tunnel.protocol"
|
|
||||||
:type="tunnel.protocol === 'tls' ? 'success' : tunnel.protocol === 'mtls' ? 'danger' : 'info'"
|
|
||||||
size="mini">
|
|
||||||
{{ tunnel.protocol.toUpperCase() }}
|
|
||||||
</el-tag>
|
|
||||||
<el-tag v-if="tunnel.flow === 1" type="success" size="mini">单向计算</el-tag>
|
|
||||||
<el-tag v-else type="info" size="mini">双向计算</el-tag>
|
|
||||||
<el-tag v-if="tunnel.trafficRatio && tunnel.trafficRatio !== 1.0" type="warning" size="mini">
|
|
||||||
{{ tunnel.trafficRatio }}x倍率
|
|
||||||
</el-tag>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user