초기커밋
This commit is contained in:
88
ServerBase/Monitor/Monitor.cs
Normal file
88
ServerBase/Monitor/Monitor.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
using ServerCore;
|
||||
|
||||
|
||||
namespace ServerBase;
|
||||
|
||||
public class Monitor : Singleton<Monitor>
|
||||
{
|
||||
// 접속중인 유저수 카운터
|
||||
public Counter UserCurrentCount { get; set; } = new Counter();
|
||||
|
||||
// 1분 동안 최대 로그인 처리 횟수
|
||||
private long MaxLoginCounterForMin { get; set; } = 0;
|
||||
private void checkMaxLoginCounter(long loginCounter)
|
||||
{
|
||||
MaxLoginCounterForMin = Math.Max(MaxLoginCounterForMin, loginCounter);
|
||||
NamedPipeMonitor.setContentDetail("분당 최대 로그인 처리 수", Value.ForNumber(MaxLoginCounterForMin));
|
||||
}
|
||||
|
||||
// 1분당 로그인 처리 수
|
||||
private (DateTime setTime, Counter counter) LoginCounter { get; set; } = new ValueTuple<DateTime, Counter>();
|
||||
public void incLoginCounter()
|
||||
{
|
||||
var current = DateTimeHelper.Current;
|
||||
if (current - LoginCounter.setTime > TimeSpan.FromSeconds(60))
|
||||
{
|
||||
LoginCounter = new(current, new Counter());
|
||||
}
|
||||
|
||||
LoginCounter.counter.incCount();
|
||||
checkMaxLoginCounter(LoginCounter.counter.getCount());
|
||||
}
|
||||
|
||||
// DB 최대 응답 지연 시간
|
||||
private long MaxDelayTimeForDBResponse { get; set; }
|
||||
public void setDelayTimeForDBResponse(long delayTimeMs)
|
||||
{
|
||||
MaxDelayTimeForDBResponse = Math.Max(MaxDelayTimeForDBResponse, delayTimeMs);
|
||||
NamedPipeMonitor.setContentDetail("DB 응답 최대 딜레이 시간", Value.ForNumber(MaxDelayTimeForDBResponse));
|
||||
|
||||
if(delayTimeMs >= 1000) incDelayTimeForDBResponseOverSec();
|
||||
}
|
||||
|
||||
// 1초 이상 DB 응답 지연 횟수
|
||||
private Counter DelayTimeForDBResponseOverSec { get; set; } = new Counter();
|
||||
private void incDelayTimeForDBResponseOverSec()
|
||||
{
|
||||
DelayTimeForDBResponseOverSec.incCount();
|
||||
NamedPipeMonitor.setContentDetail("1초 이상 DB 응답 딜레이 수", Value.ForNumber(DelayTimeForDBResponseOverSec.getCount()));
|
||||
}
|
||||
|
||||
// Current Room 갯수
|
||||
private Counter CurrentRoomCounter { get; set; } = new Counter();
|
||||
public void incRoomCounter()
|
||||
{
|
||||
CurrentRoomCounter.incCount();
|
||||
var room_counter = CurrentRoomCounter.getCount();
|
||||
NamedPipeMonitor.setContentDetail("현재 룸 갯수", Value.ForNumber(room_counter));
|
||||
|
||||
setMaxRoomCounterForRunningTime(room_counter);
|
||||
}
|
||||
|
||||
public void decRoomCounter()
|
||||
{
|
||||
CurrentRoomCounter.decCount();
|
||||
NamedPipeMonitor.setContentDetail("현재 룸 갯수", Value.ForNumber(CurrentRoomCounter.getCount()));
|
||||
}
|
||||
|
||||
private long MaxRoomCounterForRunningTime { get; set; }
|
||||
private void setMaxRoomCounterForRunningTime(long roomCounter)
|
||||
{
|
||||
if (MaxRoomCounterForRunningTime < roomCounter )
|
||||
{
|
||||
MaxRoomCounterForRunningTime = roomCounter;
|
||||
}
|
||||
|
||||
NamedPipeMonitor.setContentDetail("러닝 타임 중 최대 룸 갯수", Value.ForNumber(MaxRoomCounterForRunningTime));
|
||||
}
|
||||
|
||||
public void setReceivedP2PDataInfo(long packetDataSize = 0, long packetCount = 0, int receivedUserCount = 0)
|
||||
{
|
||||
NamedPipeMonitor.setContentDetail("P2P 수신 데이터 양", Value.ForNumber(packetDataSize));
|
||||
NamedPipeMonitor.setContentDetail("P2P 수신 패킷 수", Value.ForNumber(packetCount));
|
||||
NamedPipeMonitor.setContentDetail("P2P 수신 유저수", Value.ForNumber(receivedUserCount));
|
||||
}
|
||||
}
|
||||
99
ServerBase/Monitor/NamedPipe/NamedPipeMonitor.cs
Normal file
99
ServerBase/Monitor/NamedPipe/NamedPipeMonitor.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
using ControlCenter.NamedPipe;
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
|
||||
|
||||
using ServerCore; using ServerBase;
|
||||
using ServerControlCenter;
|
||||
|
||||
|
||||
|
||||
namespace ServerBase;
|
||||
|
||||
public static class NamedPipeMonitor
|
||||
{
|
||||
public static async Task ChangeServerStatus(ServerStatus status) =>
|
||||
await NamedPipeClientHelper.Instance.SetServerStatus(status);
|
||||
public static async Task SetStopReason(StopReason reason) =>
|
||||
await NamedPipeClientHelper.Instance.SetStopReason(reason);
|
||||
|
||||
public static NamedPipeResultCode SetUserConnectionBlockStatus(bool user_connection_block_status) =>
|
||||
NamedPipeClientHelper.Instance.SetUserConnectionBlockStatus(user_connection_block_status);
|
||||
|
||||
public static NamedPipeResultCode SetCurrentClientConnection(int connectionCount, ServerType serverType)
|
||||
{
|
||||
var result = NamedPipeClientHelper.Instance.SetCurrentClientConnection(connectionCount);
|
||||
if (serverType != ServerType.Indun)
|
||||
{
|
||||
result = SetCurrentCapacity(connectionCount);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static NamedPipeResultCode setCommonDetail(string key, Value value) =>
|
||||
NamedPipeClientHelper.Instance.SetDetail(key, value);
|
||||
|
||||
public static NamedPipeResultCode setCommonDetails(Dictionary<string, Value> list) =>
|
||||
NamedPipeClientHelper.Instance.SetDetails(list);
|
||||
|
||||
public static NamedPipeResultCode setContentDetail(string key, Value value) =>
|
||||
NamedPipeClientHelper.Instance.SetContentDetail(key, value);
|
||||
|
||||
public static NamedPipeResultCode setContentDetails(Dictionary<string, Value> list) =>
|
||||
NamedPipeClientHelper.Instance.SetContentDetails(list);
|
||||
|
||||
public static NamedPipeResultCode SetCurrentCapacity(int capacity) =>
|
||||
NamedPipeClientHelper.Instance.SetCurrentCapacity(capacity);
|
||||
|
||||
public static async Task<NamedPipeResultCode> SendMessageAsync<T>(T message, string message_id) where T : IMessage =>
|
||||
await NamedPipeClientHelper.Instance.SendMessageAsync(message, message_id);
|
||||
|
||||
public static async Task StopNamedPipeService()
|
||||
{
|
||||
Log.getLogger().debug($"NamedPipeClientHelper : StopNamedPipeService Call !!!");
|
||||
await NamedPipeClientHelper.Instance.StopPipeClient();
|
||||
}
|
||||
public static async Task StartNamedPipeService(bool enable_named_pipe, ServerType server_type, int port, ServiceCategory serviceCategory, int max_connection_count, int? channel_no = null, int? world_id = null)
|
||||
{
|
||||
var ip = NetworkHelper.getEthernetLocalIPv4();
|
||||
var type = server_type switch
|
||||
{
|
||||
ServerType.Auth => ServerControlCenter.ServerType.Login,
|
||||
ServerType.Login => ServerControlCenter.ServerType.Login,
|
||||
ServerType.Channel => ServerControlCenter.ServerType.Channel,
|
||||
ServerType.Indun => ServerControlCenter.ServerType.Indun,
|
||||
ServerType.Chat => ServerControlCenter.ServerType.Chat,
|
||||
ServerType.UgqApi => ServerControlCenter.ServerType.UgqApi,
|
||||
ServerType.UgqAdmin => ServerControlCenter.ServerType.UgqAdmin,
|
||||
ServerType.UgqIngame => ServerControlCenter.ServerType.UgqIngame,
|
||||
ServerType.BrokerApi => ServerControlCenter.ServerType.BrokerApi,
|
||||
_ => ServerControlCenter.ServerType.None
|
||||
};
|
||||
|
||||
if (type == ServerControlCenter.ServerType.None) return;
|
||||
|
||||
var named_pipe_options = new NamedPipeClientHelper.NamedPipeClientOption
|
||||
{
|
||||
m_enable_pipe = enable_named_pipe,
|
||||
m_service_category = serviceCategory.ToString(),
|
||||
m_type = type, m_ip = ip, m_port = port,
|
||||
m_channel_no = channel_no,
|
||||
m_world_id = world_id,
|
||||
m_max_client_connection = max_connection_count,
|
||||
m_assemblies = GetAssemblies().ToList(),
|
||||
m_max_retry_count = 5,
|
||||
m_retry_delay_time_ms = 5_000
|
||||
};
|
||||
|
||||
Log.getLogger().debug($"Start NamedPipe Client - Name[Agent_{named_pipe_options.m_ip}.{named_pipe_options.m_port}]");
|
||||
await NamedPipeClientHelper.Instance.StartNamedPipeClientAsync(named_pipe_options);
|
||||
}
|
||||
|
||||
private static IEnumerable<Assembly> GetAssemblies()
|
||||
=> new List<Assembly>(AppDomain.CurrentDomain.GetAssemblies());
|
||||
}
|
||||
Reference in New Issue
Block a user