大版本更新推送
This commit is contained in:
80
HT.Cloud.Service/ReportManage/ApplicationStateService.cs
Normal file
80
HT.Cloud.Service/ReportManage/ApplicationStateService.cs
Normal file
@ -0,0 +1,80 @@
|
||||
using MiniExcelLibs;
|
||||
using Serenity.Services;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using HT.Cloud.Domain.ReportManage;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Data;
|
||||
using HT.Cloud.Code;
|
||||
using HT.Cloud.Domain.ChartsManage;
|
||||
using HT.Cloud.Domain.DevicesManage;
|
||||
using Quartz;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using HT.Cloud.Domain.Entity.ReportManage;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
|
||||
namespace HT.Cloud.Service.ReportManage
|
||||
{
|
||||
public class ApplicationStateService : BaseService<RTApplicationStateEntity>, IDenpendency
|
||||
{
|
||||
/// <summary>
|
||||
/// 绑定数据仓库的数据库ID
|
||||
/// </summary>
|
||||
private string dataDBNumber = GlobalContext.SystemConfig.DataDBNumber;
|
||||
|
||||
public ApplicationStateService(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<string> GetApplicationList(string systemName)
|
||||
{
|
||||
var groupName = _context.AsTenant().QueryableWithAttr<MetaGroupEntity>().Where(x => x.GroupDescription == systemName).First().GroupName;
|
||||
var driverId = _context.AsTenant().QueryableWithAttr<MetaGroupEntity>().Where(x => x.GroupDescription == systemName).First().DriverID;
|
||||
var driverName = _context.AsTenant().QueryableWithAttr<MetaDriverEntity>().Where(x => x.DriverID == driverId).First().DriverName;
|
||||
var list = _context.AsTenant().GetConnection(dataDBNumber).Ado.SqlQuery<RTMainPageEntity>($"SELECT * FROM HT_{driverName}_{groupName}_STATE");
|
||||
|
||||
return list.ToJson();
|
||||
}
|
||||
|
||||
public async Task<string> GetRtApplicationState(string systemName)
|
||||
{
|
||||
var groupName = _context.AsTenant().QueryableWithAttr<MetaGroupEntity>().Where(x => x.GroupDescription == systemName).First().GroupName;
|
||||
var driverId = _context.AsTenant().QueryableWithAttr<MetaGroupEntity>().Where(x => x.GroupDescription == systemName).First().DriverID;
|
||||
var driverName = _context.AsTenant().QueryableWithAttr<MetaDriverEntity>().Where(x => x.DriverID == driverId).First().DriverName;
|
||||
var list = _context.AsTenant().GetConnection(dataDBNumber).Ado.SqlQuery<RTMainPageEntity>($"SELECT * FROM HT_{driverName}_{groupName}_STATE");
|
||||
|
||||
var interval = 1000;
|
||||
|
||||
foreach ( var item in list )
|
||||
{
|
||||
var process = Process.GetProcessesByName("HT.Cloud.Web")[0];
|
||||
var startTime = DateTime.UtcNow;
|
||||
var startCpuUsage = process.TotalProcessorTime;
|
||||
// Perform some work
|
||||
Thread.Sleep(interval);
|
||||
var endTime = DateTime.UtcNow;
|
||||
var endCpuUsage = process.TotalProcessorTime;
|
||||
var cpuUsage = (endCpuUsage - startCpuUsage) / (endTime - startTime) / Environment.ProcessorCount * 100;
|
||||
var memory = process.WorkingSet64 / (1024 * 1024);
|
||||
Console.WriteLine($"CPU usage: {cpuUsage}% Memory: {memory}MB");
|
||||
}
|
||||
return list.ToJson();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class RealTimeDataFormat
|
||||
{
|
||||
public string Description { get; set; }
|
||||
public string Value { get; set; }
|
||||
public string RtTime { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user