feat:准备服务监控
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Diagnostics;
|
||||
//using System.Linq;
|
||||
//using System.Runtime.InteropServices;
|
||||
//using System.Text;
|
||||
//using System.Threading.Tasks;
|
||||
//using Furion.Logging;
|
||||
//using Microsoft.AspNetCore.Hosting;
|
||||
//using Microsoft.Extensions.Hosting;
|
||||
//using Microsoft.Extensions.Options;
|
||||
|
||||
//namespace Yi.Furion.Application.Rbac.Services
|
||||
//{
|
||||
|
||||
// public class MonitorServerService
|
||||
// {
|
||||
// private OptionsSetting Options;
|
||||
// private IWebHostEnvironment HostEnvironment;
|
||||
// private NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
// public MonitorServerService(IOptions<OptionsSetting> options, IWebHostEnvironment hostEnvironment)
|
||||
// {
|
||||
// this.HostEnvironment = hostEnvironment;
|
||||
// this.Options = options.Value;
|
||||
// }
|
||||
// public void GGG()
|
||||
// {
|
||||
// int cpuNum = Environment.ProcessorCount;
|
||||
// string computerName = Environment.MachineName;
|
||||
// string osName = RuntimeInformation.OSDescription;
|
||||
// string osArch = RuntimeInformation.OSArchitecture.ToString();
|
||||
// string version = RuntimeInformation.FrameworkDescription;
|
||||
// string appRAM = ((double)Process.GetCurrentProcess().WorkingSet64 / 1048576).ToString("N2") + " MB";
|
||||
// string startTime = Process.GetCurrentProcess().StartTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
// string sysRunTime = ComputerHelper.GetRunTime();
|
||||
// string serverIP = Request.HttpContext.Connection.LocalIpAddress.MapToIPv4().ToString() + ":" + Request.HttpContext.Connection.LocalPort;//获取服务器IP
|
||||
|
||||
// var programStartTime = Process.GetCurrentProcess().StartTime;
|
||||
// string programRunTime = DateTimeHelper.FormatTime((DateTime.Now - programStartTime).TotalMilliseconds.ToString().Split('.')[0].ParseToLong());
|
||||
// var data = new
|
||||
// {
|
||||
// cpu = ComputerHelper.GetComputerInfo(),
|
||||
// disk = ComputerHelper.GetDiskInfos(),
|
||||
// sys = new { cpuNum, computerName, osName, osArch, serverIP, runTime = sysRunTime },
|
||||
// app = new
|
||||
// {
|
||||
// name = HostEnvironment.EnvironmentName,
|
||||
// rootPath = HostEnvironment.ContentRootPath,
|
||||
// webRootPath = HostEnvironment.WebRootPath,
|
||||
// version,
|
||||
// appRAM,
|
||||
// startTime,
|
||||
// runTime = programRunTime,
|
||||
// host = serverIP
|
||||
// },
|
||||
// };
|
||||
|
||||
// return SUCCESS(data);
|
||||
// }
|
||||
|
||||
// }
|
||||
//}
|
||||
@@ -39,7 +39,7 @@ namespace Yi.Furion.Application.Rbac.SignalRHub
|
||||
public override Task OnConnectedAsync()
|
||||
{
|
||||
var name = _currentUser.UserName;
|
||||
var loginUser = GetLoginLogInfo(_httpContext);
|
||||
var loginUser = _httpContext.GetLoginLogInfo();
|
||||
var user = clientUsers.Any(u => u.ConnnectionId == Context.ConnectionId);
|
||||
//判断用户是否存在,否则添加集合
|
||||
if (!user)
|
||||
@@ -60,7 +60,7 @@ namespace Yi.Furion.Application.Rbac.SignalRHub
|
||||
//当有人加入,向全部客户端发送当前总数
|
||||
Clients.All.SendAsync("onlineNum", clientUsers.Count);
|
||||
}
|
||||
|
||||
|
||||
//Clients.All.SendAsync(HubsConstant.OnlineUser, clientUsers);
|
||||
return base.OnConnectedAsync();
|
||||
}
|
||||
@@ -89,46 +89,5 @@ namespace Yi.Furion.Application.Rbac.SignalRHub
|
||||
await Clients.All.SendAsync("ReceiveAllInfo", test);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取客户端信息
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
private static ClientInfo GetClientInfo(HttpContext context)
|
||||
{
|
||||
var str = context.GetUserAgent();
|
||||
var uaParser = Parser.GetDefault();
|
||||
ClientInfo c = uaParser.Parse(str);
|
||||
return c;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录用户登陆信息
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
private static LoginLogEntity GetLoginLogInfo(HttpContext context)
|
||||
{
|
||||
var ipAddr = context.GetClientIp();
|
||||
IpInfo location;
|
||||
if (ipAddr == "127.0.0.1")
|
||||
{
|
||||
location = new IpInfo() { Province = "本地", City = "本机" };
|
||||
}
|
||||
else
|
||||
{
|
||||
location = IpTool.Search(ipAddr);
|
||||
}
|
||||
ClientInfo clientInfo = GetClientInfo(context);
|
||||
LoginLogEntity entity = new()
|
||||
{
|
||||
Browser = clientInfo.Device.Family,
|
||||
Os = clientInfo.OS.ToString(),
|
||||
LoginIp = ipAddr,
|
||||
LoginLocation = location.Province + "-" + location.City
|
||||
};
|
||||
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user