diff --git a/framework/Web/ThingsGateway.Gateway.Application/Workers/HardwareInfo/HardwareInfoWorker.cs b/framework/Web/ThingsGateway.Gateway.Application/Workers/HardwareInfo/HardwareInfoWorker.cs index 5ec7a0471..b50cffcd9 100644 --- a/framework/Web/ThingsGateway.Gateway.Application/Workers/HardwareInfo/HardwareInfoWorker.cs +++ b/framework/Web/ThingsGateway.Gateway.Application/Workers/HardwareInfo/HardwareInfoWorker.cs @@ -102,23 +102,28 @@ public class HardwareInfoWorker : BackgroundService string currentPath = Directory.GetCurrentDirectory(); DriveInfo drive = new(Path.GetPathRoot(currentPath)); + var remoteIpEnable = App.GetConfig("HardwareInfo:RemoteIpEnable") ?? true; + var enable = App.GetConfig("HardwareInfo:Enable") ?? true; + var timeInterval = App.GetConfig("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("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) { diff --git a/framework/Web/ThingsGateway.Web.Core/Configuration/App.json b/framework/Web/ThingsGateway.Web.Core/Configuration/App.json index 55d32b2c1..32eecd059 100644 --- a/framework/Web/ThingsGateway.Web.Core/Configuration/App.json +++ b/framework/Web/ThingsGateway.Web.Core/Configuration/App.json @@ -21,7 +21,9 @@ }, "HardwareInfo": { - "Enable": true //启用硬件信息获取,部分系统/硬件不支持相关方法,设为false + "Enable": true, //启用硬件信息获取, 部分系统/硬件不支持相关方法,设为false + "RemoteIpEnable": true, //是否获取外网IP地址 + "TimeInterval": 10000 //更新间隔ms }, //动态API设备