forked from sin365/NoSugarNet
网络计数
This commit is contained in:
parent
d65619db43
commit
a86cd5b1f6
@ -18,9 +18,10 @@ namespace NoSugarNet.ClientCore
|
|||||||
public static UserDataManager user;
|
public static UserDataManager user;
|
||||||
public static System.Timers.Timer _SpeedCheckTimeTimer;//速度检测计时器
|
public static System.Timers.Timer _SpeedCheckTimeTimer;//速度检测计时器
|
||||||
public static int TimerInterval = 1000;//计时器间隔
|
public static int TimerInterval = 1000;//计时器间隔
|
||||||
|
static NetStatus netStatus;
|
||||||
|
|
||||||
#region 委托和事件
|
#region 委托和事件
|
||||||
public delegate void OnUpdateStatusHandler(long resultReciveAllLenght, long resultSendAllLenght);
|
public delegate void OnUpdateStatusHandler(NetStatus Status);
|
||||||
public static event OnUpdateStatusHandler OnUpdateStatus;
|
public static event OnUpdateStatusHandler OnUpdateStatus;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -32,6 +33,7 @@ namespace NoSugarNet.ClientCore
|
|||||||
chat = new AppChat();
|
chat = new AppChat();
|
||||||
local = new AppLocalClient();
|
local = new AppLocalClient();
|
||||||
user = new UserDataManager();
|
user = new UserDataManager();
|
||||||
|
netStatus = new NetStatus();
|
||||||
networkHelper.Init(IP, port);
|
networkHelper.Init(IP, port);
|
||||||
|
|
||||||
_SpeedCheckTimeTimer = new System.Timers.Timer();
|
_SpeedCheckTimeTimer = new System.Timers.Timer();
|
||||||
@ -44,7 +46,24 @@ namespace NoSugarNet.ClientCore
|
|||||||
static void Checktimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
static void Checktimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||||
{
|
{
|
||||||
local.GetCurrLenght(out long resultReciveAllLenght, out long resultSendAllLenght);
|
local.GetCurrLenght(out long resultReciveAllLenght, out long resultSendAllLenght);
|
||||||
OnUpdateStatus?.Invoke(resultReciveAllLenght, resultSendAllLenght);
|
local.GetClientCount(out int ClientUserCount, out int TunnelCount);
|
||||||
|
|
||||||
|
NetStatus resutnetStatus = new NetStatus()
|
||||||
|
{
|
||||||
|
TunnelCount = TunnelCount,
|
||||||
|
ClientUserCount = ClientUserCount,
|
||||||
|
srcSendAllLenght = resultSendAllLenght,
|
||||||
|
srcReciveAllLenght = resultReciveAllLenght,
|
||||||
|
srcReciveSecSpeed = (resultReciveAllLenght - netStatus.srcReciveAllLenght) / (TimerInterval / 1000),
|
||||||
|
srcSendSecSpeed = (resultSendAllLenght - netStatus.srcSendAllLenght) / (TimerInterval / 1000),
|
||||||
|
tSendAllLenght = local.tSendAllLenght,
|
||||||
|
tReciveAllLenght = local.tReciveAllLenght,
|
||||||
|
tSendSecSpeed = (local.tSendAllLenght - netStatus.tSendAllLenght) / (TimerInterval / 1000),
|
||||||
|
tReciveSecSpeed = (local.tReciveAllLenght - netStatus.tReciveAllLenght) / (TimerInterval / 1000),
|
||||||
|
};
|
||||||
|
netStatus = resutnetStatus;
|
||||||
|
|
||||||
|
OnUpdateStatus?.Invoke(resutnetStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,6 +17,9 @@ namespace ServerCore.Manager
|
|||||||
E_CompressAdapter compressAdapterType;
|
E_CompressAdapter compressAdapterType;
|
||||||
public LocalMsgQueuePool _localMsgPool = new LocalMsgQueuePool(1000);
|
public LocalMsgQueuePool _localMsgPool = new LocalMsgQueuePool(1000);
|
||||||
|
|
||||||
|
public long tReciveAllLenght { get; private set; }
|
||||||
|
public long tSendAllLenght { get; private set; }
|
||||||
|
|
||||||
public AppLocalClient()
|
public AppLocalClient()
|
||||||
{
|
{
|
||||||
//注册网络消息
|
//注册网络消息
|
||||||
@ -33,11 +36,19 @@ namespace ServerCore.Manager
|
|||||||
byte[] Keys = mDictTunnelID2Listeners.Keys.ToArray();
|
byte[] Keys = mDictTunnelID2Listeners.Keys.ToArray();
|
||||||
for (int i = 0; i < Keys.Length; i++)
|
for (int i = 0; i < Keys.Length; i++)
|
||||||
{
|
{
|
||||||
resultReciveAllLenght += mDictTunnelID2Listeners[Keys[i]].mReciveAllLenght;
|
//local和转发 收发相反
|
||||||
resultSendAllLenght += mDictTunnelID2Listeners[Keys[i]].mSendAllLenght;
|
resultSendAllLenght += mDictTunnelID2Listeners[Keys[i]].mReciveAllLenght;
|
||||||
|
resultReciveAllLenght += mDictTunnelID2Listeners[Keys[i]].mSendAllLenght;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void GetClientCount(out int ClientUserCount, out int TunnelCount)
|
||||||
|
{
|
||||||
|
TunnelCount = mDictTunnelID2Listeners.Count;
|
||||||
|
ClientUserCount = mDictTunnelID2Listeners.Count;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化连接,先获取到配置
|
/// 初始化连接,先获取到配置
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -241,6 +252,8 @@ namespace ServerCore.Manager
|
|||||||
//AppNoSugarNet.log.Debug($"OnServerLocalDataCallBack {tunnelId},{Idx},Data长度:{data.Length}");
|
//AppNoSugarNet.log.Debug($"OnServerLocalDataCallBack {tunnelId},{Idx},Data长度:{data.Length}");
|
||||||
if (!GetLocalListener(tunnelId, out LocalListener _listener))
|
if (!GetLocalListener(tunnelId, out LocalListener _listener))
|
||||||
return;
|
return;
|
||||||
|
//记录压缩前数据长度
|
||||||
|
tReciveAllLenght += data.Length;
|
||||||
//解压
|
//解压
|
||||||
data = mCompressAdapter.Decompress(data);
|
data = mCompressAdapter.Decompress(data);
|
||||||
_listener.SendSocketByIdx(Idx,data);
|
_listener.SendSocketByIdx(Idx,data);
|
||||||
@ -286,6 +299,8 @@ namespace ServerCore.Manager
|
|||||||
{
|
{
|
||||||
//压缩
|
//压缩
|
||||||
data = mCompressAdapter.Compress(data);
|
data = mCompressAdapter.Compress(data);
|
||||||
|
//记录压缩后数据长度
|
||||||
|
tSendAllLenght += data.Length;
|
||||||
|
|
||||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_C2S_DATA()
|
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_C2S_DATA()
|
||||||
{
|
{
|
||||||
|
@ -45,8 +45,9 @@ namespace ServerCore.Manager
|
|||||||
long[] Keys = mDictCommKey2ServerLocalClients.Keys.ToArray();
|
long[] Keys = mDictCommKey2ServerLocalClients.Keys.ToArray();
|
||||||
for(int i =0; i < Keys.Length; i++)
|
for(int i =0; i < Keys.Length; i++)
|
||||||
{
|
{
|
||||||
resultReciveAllLenght += mDictCommKey2ServerLocalClients[Keys[i]].mReciveAllLenght;
|
//local和转发 收发相反
|
||||||
resultSendAllLenght += mDictCommKey2ServerLocalClients[Keys[i]].mSendAllLenght;
|
resultSendAllLenght += mDictCommKey2ServerLocalClients[Keys[i]].mReciveAllLenght;
|
||||||
|
resultReciveAllLenght += mDictCommKey2ServerLocalClients[Keys[i]].mSendAllLenght;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,7 +285,7 @@ namespace ServerCore.Manager
|
|||||||
if (!GetServerLocalClient(uid, tunnelId, Idx, out ServerLocalClient serverLocalClient))
|
if (!GetServerLocalClient(uid, tunnelId, Idx, out ServerLocalClient serverLocalClient))
|
||||||
return;
|
return;
|
||||||
//记录数据长度
|
//记录数据长度
|
||||||
tSendAllLenght += data.Length;
|
tReciveAllLenght += data.Length;
|
||||||
//解压
|
//解压
|
||||||
data = mCompressAdapter.Decompress(data);
|
data = mCompressAdapter.Decompress(data);
|
||||||
//记录数据长度
|
//记录数据长度
|
||||||
@ -336,11 +337,10 @@ namespace ServerCore.Manager
|
|||||||
if (!ServerManager.g_ClientMgr.GetClientByUID(uid, out ClientInfo client))
|
if (!ServerManager.g_ClientMgr.GetClientByUID(uid, out ClientInfo client))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
//压缩
|
//压缩
|
||||||
data = mCompressAdapter.Compress(data);
|
data = mCompressAdapter.Compress(data);
|
||||||
//记录压缩后数据长度
|
//记录压缩后数据长度
|
||||||
tReciveAllLenght += data.Length;
|
tSendAllLenght += data.Length;
|
||||||
|
|
||||||
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_S2C_DATA()
|
byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_S2C_DATA()
|
||||||
{
|
{
|
||||||
|
@ -20,11 +20,16 @@ namespace NoSugarNet.ClientCli
|
|||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void OnUpdateStatus(long resultReciveAllLenght, long resultSendAllLenght)
|
static void OnUpdateStatus(NetStatus netState)
|
||||||
{
|
{
|
||||||
Console.Title = $"{Title} Recive:{resultReciveAllLenght} Send:{resultSendAllLenght}";
|
//string info = $"User:{netState.ClientUserCount} Tun:{netState.TunnelCount} rec:{netState.srcReciveAllLenght}|{netState.tReciveAllLenght} {ConvertBytesToKilobytes(netState.srcReciveSecSpeed)}K/s|{ConvertBytesToKilobytes(netState.tReciveSecSpeed)}K/s send:{netState.srcSendAllLenght}|{netState.tSendAllLenght} {ConvertBytesToKilobytes(netState.srcSendSecSpeed)}K/s|{ConvertBytesToKilobytes(netState.tSendSecSpeed)}K/s";
|
||||||
Console.WriteLine($"{Title} Recive:{resultReciveAllLenght} Send:{resultSendAllLenght}");
|
string info = $"User:{netState.ClientUserCount} Tun:{netState.TunnelCount} rec: {ConvertBytesToKilobytes(netState.srcReciveSecSpeed)}K/s|{ConvertBytesToKilobytes(netState.tReciveSecSpeed)}K/s send: {ConvertBytesToKilobytes(netState.srcSendSecSpeed)}K/s|{ConvertBytesToKilobytes(netState.tSendSecSpeed)}K/s";
|
||||||
|
Console.Title = Title + info;
|
||||||
|
Console.WriteLine(info);
|
||||||
|
}
|
||||||
|
static string ConvertBytesToKilobytes(long bytes)
|
||||||
|
{
|
||||||
|
return Math.Round((double)bytes / 1024, 2).ToString("F2");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -40,14 +40,14 @@ namespace NoSugarNet.ServerCli
|
|||||||
|
|
||||||
static void OnUpdateStatus(NetStatus netState)
|
static void OnUpdateStatus(NetStatus netState)
|
||||||
{
|
{
|
||||||
string info = $"User:{netState.ClientUserCount} Tun:{netState.TunnelCount} rec:{netState.srcReciveAllLenght}|{netState.tReciveAllLenght} {ConvertBytesToKilobytes(netState.srcReciveSecSpeed)}K/s|{ConvertBytesToKilobytes(netState.tReciveSecSpeed)}K/s send:{netState.srcSendAllLenght}|{netState.tSendAllLenght} {ConvertBytesToKilobytes(netState.srcSendSecSpeed)}K/s|{ConvertBytesToKilobytes(netState.tSendSecSpeed)}K/s";
|
//string info = $"User:{netState.ClientUserCount} Tun:{netState.TunnelCount} rec:{netState.srcReciveAllLenght}|{netState.tReciveAllLenght} {ConvertBytesToKilobytes(netState.srcReciveSecSpeed)}K/s|{ConvertBytesToKilobytes(netState.tReciveSecSpeed)}K/s send:{netState.srcSendAllLenght}|{netState.tSendAllLenght} {ConvertBytesToKilobytes(netState.srcSendSecSpeed)}K/s|{ConvertBytesToKilobytes(netState.tSendSecSpeed)}K/s";
|
||||||
|
string info = $"User:{netState.ClientUserCount} Tun:{netState.TunnelCount} rec: {ConvertBytesToKilobytes(netState.srcReciveSecSpeed)}K/s|{ConvertBytesToKilobytes(netState.tReciveSecSpeed)}K/s send: {ConvertBytesToKilobytes(netState.srcSendSecSpeed)}K/s|{ConvertBytesToKilobytes(netState.tSendSecSpeed)}K/s";
|
||||||
Console.Title = Title + info;
|
Console.Title = Title + info;
|
||||||
Console.WriteLine(info);
|
Console.WriteLine(info);
|
||||||
}
|
}
|
||||||
|
static string ConvertBytesToKilobytes(long bytes)
|
||||||
private static double ConvertBytesToKilobytes(long bytes)
|
|
||||||
{
|
{
|
||||||
return Math.Round((double)bytes / 1024, 2);
|
return Math.Round((double)bytes / 1024, 2).ToString("F2");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user