添加监控
This commit is contained in:
parent
2feb295a6a
commit
846d6eb9a0
|
|
@ -107,6 +107,7 @@ public class MonitorBLL : CloudGamingBase
|
|||
return new { Login = userLogin, Registr = userRegistr, Active = userActive };
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取近一月登录人数统计
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -87,3 +87,80 @@ public class UserMonitorProcessor : AppJobBase
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户定时类
|
||||
/// </summary>
|
||||
[QuartzTrigger("UserHourMonitorProcessor", "0 1 * * * ?")]
|
||||
public class UserHourMonitorProcessor : AppJobBase
|
||||
{
|
||||
public UserHourMonitorProcessor(IServiceScopeFactory scopeFactory) : base(scopeFactory)
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task AppConfigProcessLoop(AppConfig appConfig, AppMonitorInfo appMonitorInfo, IServiceProvider serviceProvider, CloudGamingBase cloudGamingBase)
|
||||
{
|
||||
var dao = cloudGamingBase.Dao;
|
||||
var now = DateTime.Now.AddHours(-1);
|
||||
int day = int.Parse(now.ToString("yyyyMMdd"));
|
||||
var newDayHour = now.Date.AddHours(now.Hour);
|
||||
var oldDayHour = now.Date.AddHours(now.AddHours(1).Hour);
|
||||
int dayHour = int.Parse(now.ToString("yyyyMMddHH"));
|
||||
var nowDay = DateOnly.FromDateTime(now);
|
||||
|
||||
// 获取所有用户数据
|
||||
var userLoginData = cloudGamingBase.Dao.DaoExt.Context.T_User_LoginDay_Log
|
||||
.Where(it => it.CreateTimeDay == day && it.CreateTimeHour == dayHour).AsQueryable();
|
||||
//登录数据
|
||||
var todayLoggedInUsers = await userLoginData.GroupBy(it => it.Channel ?? "")
|
||||
.ToDictionaryAsync(g => g.Key, g => g.Count());
|
||||
//注册数据
|
||||
var todayRegisteredUsers = await userLoginData.Where(it => it.IsNew)
|
||||
.GroupBy(it => it.Channel ?? "")
|
||||
.ToDictionaryAsync(g => g.Key, g => g.Count());
|
||||
|
||||
|
||||
// 获取当前统计数据
|
||||
var userStatistics = await dao.DaoExt.Context.T_Statistics_UserHour
|
||||
.Where(it => it.LoginDay == day)
|
||||
.ToDictionaryAsync(it => it.Channel ?? "");
|
||||
|
||||
// 更新或创建统计记录
|
||||
void UpdateStatistics(string channel, int loginCount, int registrCount)
|
||||
{
|
||||
if (!userStatistics.TryGetValue(channel, out var statisticsUser))
|
||||
{
|
||||
statisticsUser = new T_Statistics_UserHour()
|
||||
{
|
||||
LoginHour = dayHour,
|
||||
Channel = channel,
|
||||
CreatedAt = DateTime.Now,
|
||||
LoginCount = 0,
|
||||
RegistrCount = 0,
|
||||
LoginDate = nowDay,
|
||||
LoginDay = day,
|
||||
UpdatedAt = DateTime.Now,
|
||||
};
|
||||
dao.DaoExt.Context.T_Statistics_UserHour.Add(statisticsUser);
|
||||
userStatistics.Add(channel, statisticsUser);
|
||||
}
|
||||
statisticsUser.OnlineCount = appMonitorInfo?.CurrentOnlineUsers ?? 0;
|
||||
statisticsUser.LoginCount = loginCount;
|
||||
statisticsUser.RegistrCount = registrCount;
|
||||
statisticsUser.UpdatedAt = DateTime.Now;
|
||||
}
|
||||
var list = dao.DaoExt.Context.T_App_Channel.ToList();
|
||||
foreach (var item in list)
|
||||
{
|
||||
var key = item.ChannelId;
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
key = "27001";
|
||||
}
|
||||
UpdateStatistics(key, todayLoggedInUsers.GetValueOrDefault(key, 0), todayRegisteredUsers.GetValueOrDefault(key, 0));
|
||||
|
||||
}
|
||||
await dao.DaoExt.Context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -382,10 +382,8 @@ public partial class CloudGamingCBTContext : DbContext
|
|||
entity.Property(e => e.LoginCount).HasComment("用户登录数");
|
||||
entity.Property(e => e.LoginDate).HasComment("日期");
|
||||
entity.Property(e => e.LoginDay).HasComment("天");
|
||||
entity.Property(e => e.LoginHour)
|
||||
.HasMaxLength(255)
|
||||
.IsUnicode(false)
|
||||
.HasComment("小时");
|
||||
entity.Property(e => e.LoginHour).HasComment("小时");
|
||||
entity.Property(e => e.OnlineCount).HasComment("在线人数");
|
||||
entity.Property(e => e.RegistrCount).HasComment("用户注册数");
|
||||
entity.Property(e => e.UpdatedAt)
|
||||
.HasComment("修改时间")
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
|
||||
namespace CloudGaming.GameModel.Db.Db_Ext;
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public partial class T_Statistics_UserHour
|
|||
/// <summary>
|
||||
/// 小时
|
||||
/// </summary>
|
||||
public virtual string LoginHour { get; set; } = null!;
|
||||
public virtual int LoginHour { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户登录数
|
||||
|
|
@ -50,4 +50,9 @@ public partial class T_Statistics_UserHour
|
|||
/// 修改时间
|
||||
/// </summary>
|
||||
public virtual DateTime UpdatedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 在线人数
|
||||
/// </summary>
|
||||
public virtual int OnlineCount { get; set; }
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user