添加项目文件。
This commit is contained in:
46
HT.Cloud.Service/AutoJob/Job/SaveServerStateJob.cs
Normal file
46
HT.Cloud.Service/AutoJob/Job/SaveServerStateJob.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using HT.Cloud.Code;
|
||||
using HT.Cloud.Domain.SystemSecurity;
|
||||
using HT.Cloud.Service.SystemSecurity;
|
||||
|
||||
namespace HT.Cloud.Service.AutoJob
|
||||
{
|
||||
[ServiceDescription("服务器监控")]
|
||||
public class SaveServerStateJob : IJobTask
|
||||
{
|
||||
private IWebHostEnvironment _hostingEnvironment;
|
||||
private ServerStateService _server;
|
||||
|
||||
public SaveServerStateJob(ISqlSugarClient context)
|
||||
{
|
||||
_hostingEnvironment = GlobalContext.HostingEnvironment;
|
||||
_server = new ServerStateService(context);
|
||||
}
|
||||
|
||||
public async Task<AlwaysResult> Start()
|
||||
{
|
||||
AlwaysResult obj = new AlwaysResult();
|
||||
try
|
||||
{
|
||||
ServerStateEntity entity = new ServerStateEntity();
|
||||
var computer = ComputerHelper.GetComputerInfo();
|
||||
entity.F_ARM = computer.RAMRate;
|
||||
entity.F_CPU = computer.CPURate;
|
||||
entity.F_IIS = "0";
|
||||
entity.F_WebSite = _hostingEnvironment.ContentRootPath;
|
||||
await _server.SubmitForm(entity);
|
||||
obj.state = ResultType.success.ToString();
|
||||
obj.message = "服务器状态更新成功!";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
obj.state = ResultType.error.ToString();
|
||||
obj.message = "服务器状态更新失败!" + ex.Message;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user