添加监控类
This commit is contained in:
parent
e7ab3a8eba
commit
c6db4d9294
|
|
@ -126,7 +126,7 @@ namespace CloudGaming.PayApi.Controllers
|
|||
T_User_OrderItems orderItems = new T_User_OrderItems();
|
||||
orderItems.PayUrl = context.Request.Path;
|
||||
//orderItems.
|
||||
await product.OrderRewardsNoWorkAsync(user, pay, orderId, intentOrder.Price, intentOrder.IntentAt, dao, orderItems);
|
||||
await product.OrderRewardsNoWorkAsync(user, pay, orderId, intentOrder.Price, intentOrder.CreatedAt, dao, orderItems);
|
||||
//intentOrder = await dao.daoDbMiaoYu.context.T_User_IntentOrder.FirstOrDefaultAsync(it => it.OrderId == orderId);
|
||||
intentOrder.Status = (int)OrderState.已完成;
|
||||
await dao.DaoUser.Context.SaveChangesAsync();
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class PlayGameProcessor(IServiceProvider serviceProvider) : ThreadProcess
|
|||
var appConfigs = AppConfigurationExtend.AppConfigs.Where(it => it.Key != "default")
|
||||
.Select(it => it.Value)
|
||||
.ToList();
|
||||
|
||||
|
||||
// 为每个项目启动一个独立的任务
|
||||
foreach (var appConfig in appConfigs)
|
||||
{
|
||||
|
|
@ -74,7 +74,7 @@ public class PlayGameProcessor(IServiceProvider serviceProvider) : ThreadProcess
|
|||
var redisServer = appConfig.GetRedisServer();
|
||||
|
||||
var keyPattern = $"{PlayGameExtend.GetPlayGameKeyPrefix}:*";
|
||||
var keys = await redisServer.ScanKeysAsync(keyPattern, 2000).ConfigureAwait(false);
|
||||
var keys = await redisServer.ScanKeysAsync(keyPattern, 20000).ConfigureAwait(false);
|
||||
|
||||
var tasks = keys.Select(async gameKey =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -73,6 +73,11 @@ public class OrderBLL : CloudGamingBase
|
|||
(var orderId, var order, var payNotifyUrl) = await payment.CreateOrder(product.Id, product.ProductName, price, product, ip);
|
||||
var t = product.ToIntentOrder(paymentMethod, orderId);
|
||||
t.UserId = _UserId;
|
||||
if (payNotifyUrl != null && payNotifyUrl.Length > 200)
|
||||
{
|
||||
payNotifyUrl = payNotifyUrl.Substring(0, 200);
|
||||
}
|
||||
t.Notes = payNotifyUrl;
|
||||
await Dao.DaoUser.Context.AddAsync(t);
|
||||
await Dao.DaoUser.Context.SaveChangesAsync();
|
||||
intentOrderDto = new IntentOrderDto()
|
||||
|
|
@ -81,7 +86,7 @@ public class OrderBLL : CloudGamingBase
|
|||
Payment = order
|
||||
};
|
||||
RedisCache.KeyDelete(redisLock);
|
||||
HttpContextAccessor.HttpContext.Response.Headers.Add("PayNotifyUrl", payNotifyUrl);
|
||||
//HttpContextAccessor.HttpContext.Response.Headers.Add("PayNotifyUrl", payNotifyUrl);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
using Microsoft.Extensions.Hosting;
|
||||
using CloudGaming.Code.DataAccess.MultiTenantUtil;
|
||||
using CloudGaming.DtoModel.Other;
|
||||
|
||||
|
||||
using Quartz;
|
||||
|
||||
using System;
|
||||
|
|
@ -12,6 +12,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace CloudGaming.Code.Monitor;
|
||||
|
||||
|
|
@ -25,7 +26,7 @@ public static class MonitorExtend
|
|||
/// </summary>
|
||||
public static ConcurrentDictionary<string, AppMonitorInfo> AppMonitorConfigs { get; set; } = new ConcurrentDictionary<string, AppMonitorInfo>();
|
||||
|
||||
|
||||
|
||||
public static WebApplicationBuilder AddMonitorConfig(this WebApplicationBuilder builder)
|
||||
{
|
||||
// 添加 Quartz 配置
|
||||
|
|
@ -47,4 +48,26 @@ public static class MonitorExtend
|
|||
|
||||
return builder;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="appMonitorInfo"></param>
|
||||
/// <returns></returns>
|
||||
public static AppBasicStatistics ToAppBasicStatistics(this AppMonitorInfo appMonitorInfo)
|
||||
{
|
||||
return new AppBasicStatistics()
|
||||
{
|
||||
CurrentOnlineUsers= appMonitorInfo.CurrentOnlineUsers,
|
||||
CurrentPlayingUsers = appMonitorInfo.CurrentPlayingUsers,
|
||||
CurrentQueuedUsers = appMonitorInfo.CurrentQueuedUsers,
|
||||
TodayIntendedOrders = appMonitorInfo.TodayIntendedOrders,
|
||||
TodayLoggedInUsers = appMonitorInfo.TodayLoggedInUsers,
|
||||
TodayPaidOrders= appMonitorInfo.TodayPaidOrders,
|
||||
TodayRechargeAmount = appMonitorInfo.TodayRechargeAmount,
|
||||
TodayRegisteredUsers = appMonitorInfo.TodayRegisteredUsers
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
using CloudGaming.DtoModel.Other;
|
||||
using CloudGaming.DtoModel.PlayGame;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using Quartz;
|
||||
|
||||
using System;
|
||||
|
|
@ -10,19 +15,95 @@ namespace CloudGaming.Code.Monitor;
|
|||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// 定时监控
|
||||
/// </summary>
|
||||
public class MonitorProcessor : IJob
|
||||
{
|
||||
public MonitorProcessor(IServiceProvider serviceProvider)
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
private readonly IServiceScopeFactory scopeFactory;
|
||||
public MonitorProcessor(IServiceScopeFactory scopeFactory)
|
||||
{
|
||||
|
||||
this.scopeFactory = scopeFactory;
|
||||
}
|
||||
|
||||
public Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
Console.WriteLine($"MessageService:");
|
||||
if (AppConfigurationExtend.AppConfigs != null && AppConfigurationExtend.AppConfigs.Count > 0)
|
||||
{
|
||||
var appConfigs = AppConfigurationExtend.AppConfigs.Where(it => it.Key != "default")
|
||||
.Select(it => it.Value)
|
||||
.ToList();
|
||||
|
||||
// 为每个项目启动一个独立的任务
|
||||
foreach (var appConfig in appConfigs)
|
||||
{
|
||||
|
||||
AppMonitorInfo appMonitorInfo = MonitorExtend.AppMonitorConfigs.GetOrAdd(appConfig.Identifier, new AppMonitorInfo());
|
||||
_ = Task.Run(() => ProcessAppConfigLoop(appConfig, appMonitorInfo));
|
||||
}
|
||||
}
|
||||
|
||||
//throw new NotImplementedException();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
/// <summary>
|
||||
/// 单个项目的处理循环
|
||||
/// </summary>
|
||||
public async Task ProcessAppConfigLoop(AppConfig appConfig, AppMonitorInfo appMonitorInfo)
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
using var scope = scopeFactory.CreateScope();
|
||||
var scopedProvider = scope.ServiceProvider;
|
||||
int day = int.Parse(DateTime.Now.ToString("yyyyMMdd"));
|
||||
var nowDay = DateOnly.FromDateTime(DateTime.Now);
|
||||
|
||||
|
||||
var app = scopedProvider.GetRequiredService<AppConfig>();
|
||||
appConfig.ToAppConfig(app);
|
||||
CloudGamingBase cloudGamingBase = new CloudGamingBase(scopedProvider);
|
||||
|
||||
//今日登录人数
|
||||
var todayLoggedInUsers = await cloudGamingBase.Dao.DaoExt.Context.T_User_LoginDay_Log.Where(it => it.CreateTimeDay == day).CountAsync();
|
||||
//今日注册人数
|
||||
var todayRegisteredUsers = await cloudGamingBase.Dao.DaoExt.Context.T_User_LoginDay_Log.Where(it => it.CreateTimeDay == day && it.IsNew).CountAsync();
|
||||
//今日意向订单
|
||||
var todayIntendedOrders = await cloudGamingBase.Dao.DaoUser.Context.T_User_IntentOrder.Where(it => it.CreatedDay == day).CountAsync();
|
||||
//今日支付订单
|
||||
var todayPaidOrders = await cloudGamingBase.Dao.DaoUser.Context.T_User_Order.Where(it => it.PaymentDay == nowDay).CountAsync();
|
||||
//今日支付金额
|
||||
var todayRechargeAmount =await cloudGamingBase.Dao.DaoUser.Context.T_User_Order.Where(it => it.PaymentDay == nowDay).SumAsync(it => (decimal?)it.TotalPrice);
|
||||
// 查询游戏数据
|
||||
var playGameStatusStatistics = appMonitorInfo.PlayGameStatusStatistics();
|
||||
//排队数据
|
||||
int currentQueuedUsers = 0;
|
||||
if (playGameStatusStatistics.TryGetValue(PlayGameStatus.排队中, out var _currentQueuedUsers))
|
||||
{
|
||||
currentQueuedUsers += _currentQueuedUsers;
|
||||
}
|
||||
//开始游戏
|
||||
int currentPlayingUsers = 0;
|
||||
if (playGameStatusStatistics.TryGetValue(PlayGameStatus.开始游戏, out var _currentPlayingUsers))
|
||||
{
|
||||
currentPlayingUsers += _currentPlayingUsers;
|
||||
}
|
||||
if (playGameStatusStatistics.TryGetValue(PlayGameStatus.游戏中, out var _currentPlayingUsers1))
|
||||
{
|
||||
currentPlayingUsers += _currentPlayingUsers1;
|
||||
}
|
||||
//appMonitorInfo.CurrentQueuedUsers=
|
||||
sw.Stop();
|
||||
appMonitorInfo.TodayLoggedInUsers = todayLoggedInUsers;
|
||||
appMonitorInfo.TodayRegisteredUsers = todayRegisteredUsers;
|
||||
appMonitorInfo.TodayIntendedOrders = todayIntendedOrders;
|
||||
appMonitorInfo.TodayPaidOrders = todayPaidOrders;
|
||||
appMonitorInfo.TodayRechargeAmount = todayRechargeAmount ?? 0;
|
||||
appMonitorInfo.CurrentOnlineUsers = 0;
|
||||
appMonitorInfo.CurrentQueuedUsers = currentQueuedUsers;
|
||||
appMonitorInfo.CurrentPlayingUsers = currentPlayingUsers;
|
||||
|
||||
var t = appMonitorInfo.ToAppBasicStatistics();
|
||||
Console.WriteLine(JsonConvert.SerializeObject(t));
|
||||
Console.WriteLine($"消耗{sw.Elapsed.TotalMilliseconds.ToString("0.###")}");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -170,7 +170,7 @@ public static class PaymentExtend
|
|||
{
|
||||
Price = productCache.Price,
|
||||
CreatedAt = DateTime.Now,
|
||||
IntentAt = DateTime.Now,
|
||||
CreatedDay = int.Parse(DateTime.Now.ToString("yyyyMMdd")),
|
||||
Method = payment,
|
||||
Notes = "",
|
||||
ProductId = productCache.ProductId,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
namespace CloudGaming.DtoModel.Other
|
||||
{
|
||||
/// <summary>
|
||||
/// app基础统计
|
||||
/// </summary>
|
||||
public class AppBasicStatistics
|
||||
{
|
||||
/// <summary>
|
||||
/// 当前在线人数
|
||||
/// </summary>
|
||||
public int CurrentOnlineUsers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前排队人数
|
||||
/// </summary>
|
||||
public int CurrentQueuedUsers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前玩游戏人数
|
||||
/// </summary>
|
||||
public int CurrentPlayingUsers { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 今日意向订单
|
||||
/// </summary>
|
||||
public int TodayIntendedOrders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 今日登录人数
|
||||
/// </summary>
|
||||
public int TodayLoggedInUsers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 今日支付订单
|
||||
/// </summary>
|
||||
public int TodayPaidOrders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 今日充值金额
|
||||
/// </summary>
|
||||
public decimal TodayRechargeAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 今日注册人数
|
||||
/// </summary>
|
||||
public int TodayRegisteredUsers { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@ namespace CloudGaming.DtoModel.Other;
|
|||
/// <summary>
|
||||
/// app监控数据
|
||||
/// </summary>
|
||||
public class AppMonitorInfo
|
||||
public class AppMonitorInfo : AppBasicStatistics
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户所有的游戏状态
|
||||
|
|
@ -28,45 +28,6 @@ public class AppMonitorInfo
|
|||
/// <summary>
|
||||
/// 用户游戏状态统计
|
||||
/// </summary>
|
||||
public Dictionary<PlayGameStatus, int> PlayGameStatusStatistics() => PlayGameUserInfos.GroupBy(it => it.GameStatus).ToDictionary(it => it.Key, it => it.Count());
|
||||
public Dictionary<PlayGameStatus, int> PlayGameStatusStatistics() => PlayGameUserInfos == null ? new Dictionary<PlayGameStatus, int>() : PlayGameUserInfos.GroupBy(it => it.GameStatus).ToDictionary(it => it.Key, it => it.Count());
|
||||
|
||||
/// <summary>
|
||||
/// 今日注册人数
|
||||
/// </summary>
|
||||
public int TodayRegisteredUsers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 今日登录人数
|
||||
/// </summary>
|
||||
public int TodayLoggedInUsers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前在线人数
|
||||
/// </summary>
|
||||
public int CurrentOnlineUsers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前玩游戏人数
|
||||
/// </summary>
|
||||
public int CurrentPlayingUsers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前排队人数
|
||||
/// </summary>
|
||||
public int CurrentQueuedUsers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 今日意向订单
|
||||
/// </summary>
|
||||
public int TodayIntendedOrders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 今日支付订单
|
||||
/// </summary>
|
||||
public int TodayPaidOrders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 今日充值金额
|
||||
/// </summary>
|
||||
public decimal TodayRechargeAmount { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ public partial class CloudGamingUserContext : MultiTenantDbContext//DbContext
|
|||
public virtual DbSet<T_User_Token> T_User_Token { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{ // => optionsBuilder.UseSqlServer("Server=192.168.195.6;Database=CloudGamingUser;User Id=sa;Password=Dbt@com@123;TrustServerCertificate=true;");
|
||||
{ // => optionsBuilder.UseSqlServer("Server=192.168.195.8;Database=CloudGamingUser;User Id=sa;Password=Dbt@com@123;TrustServerCertificate=true;");
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
|
|
@ -322,9 +322,7 @@ public partial class CloudGamingUserContext : MultiTenantDbContext//DbContext
|
|||
entity.Property(e => e.CreatedAt)
|
||||
.HasComment("创建时间")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.IntentAt)
|
||||
.HasComment("订单创建时间")
|
||||
.HasColumnType("datetime");
|
||||
entity.Property(e => e.CreatedDay).HasComment("创建天");
|
||||
entity.Property(e => e.Method)
|
||||
.HasMaxLength(10)
|
||||
.HasComment("支付方式")
|
||||
|
|
|
|||
|
|
@ -49,11 +49,6 @@ public partial class T_User_IntentOrder: MultiTenantEntity
|
|||
/// </summary>
|
||||
public virtual string? Notes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 订单创建时间
|
||||
/// </summary>
|
||||
public virtual DateTime IntentAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
|
|
@ -73,4 +68,9 @@ public partial class T_User_IntentOrder: MultiTenantEntity
|
|||
/// 订单Id
|
||||
/// </summary>
|
||||
public virtual string OrderId { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 创建天
|
||||
/// </summary>
|
||||
public virtual int CreatedDay { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
```sh
|
||||
--user
|
||||
dotnet ef dbcontext scaffold "Server=192.168.1.17;Database=CloudGamingUser;User Id=sa;Password=Dbt@com@123;TrustServerCertificate=true;" Microsoft.EntityFrameworkCore.SqlServer -o DbSqlServer/Db_User/ --use-database-names --no-pluralize --force
|
||||
dotnet ef dbcontext scaffold "Server=192.168.195.6;Database=CloudGamingUser;User Id=sa;Password=Dbt@com@123;TrustServerCertificate=true;" Microsoft.EntityFrameworkCore.SqlServer -o DbSqlServer/Db_User/ --use-database-names --no-pluralize --force
|
||||
dotnet ef dbcontext scaffold "Server=192.168.195.8;Database=CloudGamingUser;User Id=sa;Password=Dbt@com@123;TrustServerCertificate=true;" Microsoft.EntityFrameworkCore.SqlServer -o DbSqlServer/Db_User/ --use-database-names --no-pluralize --force
|
||||
|
||||
--CloudGamingPhone
|
||||
dotnet ef dbcontext scaffold "Server=192.168.1.17;Database=CloudGamingPhone;User Id=sa;Password=Dbt@com@123;TrustServerCertificate=true;" Microsoft.EntityFrameworkCore.SqlServer -o DbSqlServer/Db_Phone/ --use-database-names --no-pluralize --force
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user