增加硬件信息 相关json配置

This commit is contained in:
Kimdiego2098
2023-10-26 10:54:48 +08:00
parent 329516a61b
commit 0d57e72bbf
2 changed files with 12 additions and 5 deletions
@@ -102,23 +102,28 @@ public class HardwareInfoWorker : BackgroundService
string currentPath = Directory.GetCurrentDirectory();
DriveInfo drive = new(Path.GetPathRoot(currentPath));
var remoteIpEnable = App.GetConfig<bool?>("HardwareInfo:RemoteIpEnable") ?? true;
var enable = App.GetConfig<bool?>("HardwareInfo:Enable") ?? true;
var timeInterval = App.GetConfig<int?>("HardwareInfo:TimeInterval") ?? 10000;
if (timeInterval < 5000) timeInterval = 5000;
APPInfo.DriveInfo = drive;
APPInfo.HostName = Environment.MachineName; // 主机名称
APPInfo.SystemOs = RuntimeInformation.OSDescription; // 操作系统
APPInfo.OsArchitecture = Environment.OSVersion.Platform.ToString() + " " + RuntimeInformation.OSArchitecture.ToString(); // 系统架构
APPInfo.RemoteIp = await GetIpFromOnlineAsync(); // 外网地址
if (remoteIpEnable)
APPInfo.RemoteIp = await GetIpFromOnlineAsync(); // 外网地址
APPInfo.FrameworkDescription = RuntimeInformation.FrameworkDescription; // NET框架
APPInfo.Environment = App.HostEnvironment.IsDevelopment() ? "Development" : "Production";
APPInfo.Stage = App.HostEnvironment.IsStaging() ? "Stage" : "非Stage"; // 是否Stage环境
APPInfo.UpdateTime = DateTimeExtensions.CurrentDateTime.ToDefaultDateTimeFormat();
var enable = App.GetConfig<bool?>("HardwareInfo:Enable") ?? true;
while (!stoppingToken.IsCancellationRequested)
{
try
{
APPInfo.UpdateTime = DateTimeExtensions.CurrentDateTime.ToDefaultDateTimeFormat();
APPInfo.RemoteIp = await GetIpFromOnlineAsync();
if (remoteIpEnable)
APPInfo.RemoteIp = await GetIpFromOnlineAsync();
if (enable)
{
HardwareInfo?.RefreshMemoryStatus();
@@ -127,7 +132,7 @@ public class HardwareInfoWorker : BackgroundService
HardwareInfo?.RefreshCPUList();
}
//10秒更新一次
await Task.Delay(10000, stoppingToken);
await Task.Delay(timeInterval, stoppingToken);
}
catch (TaskCanceledException)
{
@@ -21,7 +21,9 @@
},
"HardwareInfo": {
"Enable": true //启用硬件信息获取,部分系统/硬件不支持相关方法,设为false
"Enable": true, //启用硬件信息获取, 部分系统/硬件不支持相关方法,设为false
"RemoteIpEnable": true, //是否获取外网IP地址
"TimeInterval": 10000 //更新间隔ms
},
//动态API设备