修改长时间内存会炸

This commit is contained in:
2026-03-25 17:51:43 +08:00
parent 1840794f40
commit d0c626c189
61 changed files with 82737 additions and 271 deletions

Binary file not shown.

View File

@@ -12,10 +12,17 @@ namespace Common
public static PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
public static double GetCPU()
{
cpuCounter.NextValue(); // 初始化计数器,让它开始计数
System.Threading.Thread.Sleep(1000); // 等待一秒
double cpuUsage = cpuCounter.NextValue(); // 获取CPU使用率
return cpuUsage;
try
{
cpuCounter.NextValue(); // 初始化计数器,让它开始计数
System.Threading.Thread.Sleep(1000); // 等待一秒
double cpuUsage = cpuCounter.NextValue(); // 获取CPU使用率
return cpuUsage;
}
catch (Exception ex)
{
throw;
}
}
[DllImport("kernel32.dll")]
@@ -31,4 +38,50 @@ namespace Common
}
}
public class CpuMonitor
{
// 将静态初始化改为延迟加载,并将异常处理移至初始化时
private static PerformanceCounter _cpuCounter = null;
private static readonly object _lock = new object();
private static Exception _initException = null;
private static void InitializeCounter()
{
if (_initException != null) throw _initException;
if (_cpuCounter != null) return;
lock (_lock)
{
if (_cpuCounter != null) return;
try
{
// 尝试创建计数器
_cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
// 立即调用一次 NextValue 来初始化
_cpuCounter.NextValue();
}
catch (Exception ex)
{
throw _initException;
}
}
}
public static double GetCurrentCpuUsage()
{
try
{
CpuMonitor.InitializeCounter(); // 确保计数器已初始化
_cpuCounter.NextValue(); // 首次调用返回0用于初始化本次采样
System.Threading.Thread.Sleep(1000); // 等待采样间隔
return _cpuCounter.NextValue(); // 返回过去一秒内的平均使用率
}
catch
{
// 记录日志或返回一个错误标识值,例如 -1
return -1;
}
}
}
}

View File

@@ -314,9 +314,9 @@ namespace CommonEntity
}
public class ts_faultitem
{
public short dev_type { get; set; }
public short dev_addr { get; set; }
public short dev_loop { get; set; }
public ushort dev_type { get; set; }
public ushort dev_addr { get; set; }
public ushort dev_loop { get; set; }
public short error_type { get; set; }
public int error_data { get; set; }
}

View File

@@ -28,6 +28,10 @@ namespace CommonEntity
var D = (SecurityProtocolType)3072;
var E = (SecurityProtocolType)12288;
ServicePointManager.SecurityProtocol = A | B | C | D | E;
// 或者方法3使用所有现代TLS协议
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
var client1 = new RestClient(Url);
var request1 = new RestRequest("", Method.POST);
//var jsa= Newtonsoft.Json.JsonConvert.SerializeObject(obj);

View File

@@ -119,12 +119,6 @@ namespace CommonEntity
request1.AddHeader("Authorization", "Bearer " + T.data.access_token);
//Dictionary<string, string> dic = new Dictionary<string, string>();
//dic.Add("cuid", CUID);
//dic.Add("sceneCode", sceneCode);
//dic.Add("botId", skillid);
//dic.Add("params", Newtonsoft.Json.JsonConvert.SerializeObject(extra_params));
TCLBell tsa = new TCLBell();
tsa.cuid = CUID;
tsa.sceneCode = sceneCode;
@@ -139,15 +133,6 @@ namespace CommonEntity
var QQQ = client1.Execute(request1);
string ddd = QQQ.Content;
//string ti1 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
//Dictionary<string, string> dicg1 = new Dictionary<string, string>();
//dicg1.Add("HotelCode", hotelcode);
//dicg1.Add("RoomNumber", roomnum);
//dicg1.Add("RequestId", ID);
//dicg1.Add("ResponseMsg", ddd);
//dicg1.Add("ResponseTime", ti1);
//LogRecorrd.WebAPI_DataSend(dicg1, "api/tcl_tv");
logger.Error("TCL 电视触发了 情景。返回数据为:" + ddd);

View File

@@ -11,8 +11,24 @@
<RootNamespace>ConsoleApplication4</RootNamespace>
<AssemblyName>ConsoleApplication4</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
@@ -46,6 +62,41 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CommonEntity\CommonEntity.csproj">
<Project>{1D7073B2-4CC3-49F5-9F37-50A21D74A39D}</Project>
<Name>CommonEntity</Name>
</ProjectReference>
<ProjectReference Include="..\Common\Common.csproj">
<Project>{B3F29715-E925-4E56-9248-580F06C3BC11}</Project>
<Name>Common</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4 %28x86 和 x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishUrlHistory />
<InstallUrlHistory />
<SupportUrlHistory />
<UpdateUrlHistory />
<BootstrapperUrlHistory />
<ErrorReportUrlHistory />
<FallbackCulture>zh-CN</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles>
</PropertyGroup>
</Project>

View File

@@ -3,6 +3,9 @@ using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using Common;
using System.Timers;
using CommonEntity;
namespace ConsoleApplication4
{
@@ -21,39 +24,85 @@ namespace ConsoleApplication4
{
private static bool _isRunning = true;
static void Main(string[] args)
public static System.Timers.Timer CPUTimer = null;
public static void StartCPUTongJiTask()
{
Console.CancelKeyPress += (sender, e) =>
{
_isRunning = false;
e.Cancel = true;
};
try
{
var udpClient = new UdpClient(3340);
udpClient.Client.ReceiveBufferSize = 3 * 1024 * 1024;
// 开始接收
udpClient.BeginReceive(ReceiveCallback, new UdpState(udpClient));
Console.WriteLine("UDP服务器已启动按Ctrl+C停止...");
// 保持程序运行
while (_isRunning)
{
Thread.Sleep(100);
}
udpClient.Close();
Console.WriteLine("服务器已停止");
CPUTimer = new System.Timers.Timer();
CPUTimer.Elapsed += new ElapsedEventHandler(CPUtimer_Elapsed);
//10分钟统计一次
//现在修改成20秒
//CPUTimer.Interval = 1 * 60 * 1000;
CPUTimer.Interval = 1000;
CPUTimer.Start();
}
catch (Exception ex)
{
Console.WriteLine($"启动失败: {ex.Message}");
}
}
static private void CPUtimer_Elapsed(object sender, ElapsedEventArgs e)
{
var T = sender as System.Timers.Timer;
try
{
// 防止重入
T.Stop();
double d = CPUData.GetCPU();
DataTongJi.CPU_Data.Add(d);
Console.WriteLine("aaaaaaaaaa");
}
catch (Exception ex)
{
Console.WriteLine("出错了:"+ex.Message);
}
finally
{
// 恢复计时器
T.Start();
}
}
static void Main(string[] args)
{
StartCPUTongJiTask();
var a= CPUData.GetCPU();
Console.WriteLine(a);
var b = CPUData.GetNowPrecise();
Console.WriteLine(b.ToString());
Console.ReadLine();
//Console.CancelKeyPress += (sender, e) =>
//{
// _isRunning = false;
// e.Cancel = true;
//};
//try
//{
// var udpClient = new UdpClient(3340);
// udpClient.Client.ReceiveBufferSize = 3 * 1024 * 1024;
// // 开始接收
// udpClient.BeginReceive(ReceiveCallback, new UdpState(udpClient));
// Console.WriteLine("UDP服务器已启动按Ctrl+C停止...");
// // 保持程序运行
// while (_isRunning)
// {
// Thread.Sleep(100);
// }
// udpClient.Close();
// Console.WriteLine("服务器已停止");
//}
//catch (Exception ex)
//{
// Console.WriteLine($"启动失败: {ex.Message}");
//}
}
public static void ReceiveCallback(IAsyncResult ar)
{
UdpState state = ar.AsyncState as UdpState;

View File

@@ -0,0 +1,3 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,3 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.0", FrameworkDisplayName = ".NET Framework 4")]

View File

@@ -2,3 +2,42 @@ E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\b
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\ConsoleApplication4.pdb
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\obj\x86\Debug\ConsoleApplication4.exe
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\obj\x86\Debug\ConsoleApplication4.pdb
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\obj\x86\Debug\ConsoleApplication4.csprojResolveAssemblyReference.cache
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\ConsoleApplication4.exe.config
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\Common.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\log4net.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\NHibernate.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\M2Mqtt.Net.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\CacheManager.Core.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\NPOI.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\CSRedisCore.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\Newtonsoft.Json.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\aliyun-net-sdk-core.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\aliyun-net-sdk-dysmsapi.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\NPOI.OOXML.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\System.ValueTuple.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\Iesi.Collections.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\Antlr3.Runtime.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\Remotion.Data.Linq.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\ICSharpCode.SharpZipLib.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\NPOI.OpenXmlFormats.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\NPOI.OpenXml4Net.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\Common.pdb
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\M2Mqtt.Net.pdb
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\CacheManager.Core.xml
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\NPOI.xml
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\CSRedisCore.pdb
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\CSRedisCore.xml
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\Newtonsoft.Json.xml
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\NPOI.OOXML.xml
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\System.ValueTuple.xml
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\NPOI.OpenXml4Net.xml
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\CommonEntity.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\Domain.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\jose-jwt.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\RestSharp.dll
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\CommonEntity.pdb
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\Domain.pdb
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\jose-jwt.pdb
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\RestSharp.pdb
E:\tian\chongxin\NewGit\CRICS\CRICS_Web_Server_VS2010_Prod\ConsoleApplication4\bin\Debug\RestSharp.xml

View File

@@ -78,9 +78,7 @@ namespace RCUHost.Implement
StepTongJi.SendInfo(4, "注册命令Task内部开始执行", context.MessageID, context.IsMonitor);
//Reply(context);
string RoomNumber = "";
var OriginalByte = context.Data;
int lll = OriginalByte.Length;
var A1 = OriginalByte.Skip(15).Take(lll - 15 - 2).ToArray();

View File

@@ -461,218 +461,15 @@ namespace RCUHost.Implement
byte[] receiveBuffer111 = state.UdpClient.EndReceive(ar, ref remoteEP111);
state.UdpClient.BeginReceive(ReceiveCallback, state);
if (receiveBuffer111.Length > 0)
// 2. 数据处理逻辑 - 异步处理,不阻塞接收线程
if (receiveBuffer111 != null && receiveBuffer111.Length > 0)
{
#region
Interlocked.Increment(ref YUANZI_TongJi.TotalReceiveCount);
#endregion
ReceiverContext context = new ReceiverContext(receiveBuffer111, remoteEP111, GetNextCustomer());
int length = context.Data.Length;
if (length < 3 || length != BitConverter.ToInt16(context.Data, 2))
// 使用线程池处理数据,避免阻塞接收线程
ThreadPool.QueueUserWorkItem((stateObj) =>
{
//错误数据
Interlocked.Increment(ref YUANZI_TongJi.TotalErrorPackageReceiveCount);
return;//非正确的数据包
}
context.SystemHeader = DecodeSystemHeader(context.Data);
if (context.SystemHeader.HasValue)
{
if (!String.Equals(new String(context.SystemHeader.Value.SystemID), SystemHeader.SYSTEM_ID, StringComparison.OrdinalIgnoreCase))
{
//错误数据
Interlocked.Increment(ref YUANZI_TongJi.TotalErrorPackageReceiveCount);
return;//非系统数据包
}
try
{
//透传是新增加的
var VVV = context.SystemHeader.Value;
string KKKHNH = CacheKey.TouChuanKey;
var HHHostNo = context.SystemHeader.Value.HostNumber.ToString();
var da1 = CSRedisCacheHelper.HMGet<string>(1, KKKHNH, HHHostNo);
if (!string.IsNullOrEmpty(da1[0]))
{
string nns = Tools.ByteToString(context.Data);
if (VVV.CmdType == 0x71)
{
BLWMQTT.MQTTPublishData("blw/touchuan/report/" + HHHostNo, nns);
}
}
#region
if (VVV.CmdType != 0xD6 && VVV.CmdType != 0x0C)
{
var hostnumber1 = VVV.HostNumber;
string hotelCode = hostnumber1.ToHotelCode().ToString();//获取酒店编码
var hostnumber2 = hostnumber1.ToString();
//时间拦截 超过2秒就不再处理
string ShiJianLanJie = CacheKey.TimeIntercept + "_" + hostnumber2;
string ShiJianLanJieSync = CacheKey.SyncTimeIntercept + "_" + hostnumber2;
if (VVV.CmdType == 0x0E)
{
//MemoryCacheHelper.Set(ShiJianLanJie, 1, DateTimeOffset.Now.AddSeconds(DataTongJi.LostPackage_Interval));
//有错误的0x19数据所有的 在0x19数据触发后的5秒内的后续数据就不再接收
string key123 = RoomStatusReceiver.PoolOverFlowKey + "_" + hostnumber2;
var OOObj = MemoryCacheHelper.Get(key123);
if (OOObj != null)
{
//错误数据
Interlocked.Increment(ref YUANZI_TongJi.TotalErrorPackageReceiveCount);
return;
}
}
///消息ID +1
Interlocked.Increment(ref StepTongJi.EveryMessageIDNo);
//因为0E不会被拦截所以可以在这里写
if (VVV.CmdType == 0x0E || VVV.CmdType == 0X01)
{
//StepTongJi.EveryMessageID = Guid.NewGuid().ToString("N");
//计数器+1
Interlocked.Increment(ref StepTongJi.LookDataCounter);
//开始监听
Interlocked.Increment(ref StepTongJi.Every_0E_01_MessageID);
if (StepTongJi.LookDataCounter == 500)
{
//监听的ID
//Interlocked.Exchange(ref StepTongJi.GlobalListenID, StepTongJi.EveryMessageID);
context.MessageID = Guid.NewGuid().ToString("N");
context.IsMonitor = true;
int maxWorker = 0;
int maxIo = 0;
int availWorker = 0;
int availIo = 0;
// 获取最大线程数
ThreadPool.GetMaxThreads(out maxWorker, out maxIo);
// 获取可用线程数
ThreadPool.GetAvailableThreads(out availWorker, out availIo);
// 计算忙碌线程数
int busyWorker = maxWorker - availWorker;
int busyIo = maxIo - availIo;
int minWorker = 0;
int minIo = 0;
// 获取最小线程数
ThreadPool.GetMinThreads(out minWorker, out minIo);
int tid = Thread.CurrentThread.ManagedThreadId;
string NNN1 = string.Format("工作线程{8}: 最小={0}, 最大={1}, 可用={2}, 使用中={3},IO线程: 最小={4}, 最大={5}, 可用={6}, 使用中={7}", minWorker, maxWorker, availWorker, busyWorker, minIo, maxIo, availIo, busyIo, tid);
StepTongJi.SendInfo(0.1, NNN1, context.MessageID, context.IsMonitor);
string NNN7 = string.Format("HostNUMBER:{0},端点:{1}", hostnumber2, context.RemoteEndPoint.ToString());
StepTongJi.SendInfo(0.2, NNN7, context.MessageID, context.IsMonitor);
StepInfo s = new StepInfo();
s.Step = 1;
s.MessageId = context.MessageID;
s.StepDescription = "进入UDPCallBack";
//string ti = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff");
string ti = CPUData.GetNowPrecise().ToString("yyyy-MM-dd HH:mm:ss.ffffff");
s.TriggerTime = ti;
s.Content = context.Data;
s.EveryMessageId = StepTongJi.EveryMessageIDNo;
s.Monitor_0E_01 = StepTongJi.Every_0E_01_MessageID;
s.HotelCode = hotelCode;
s.HostNumber = hostnumber2;
string NNN = Newtonsoft.Json.JsonConvert.SerializeObject(s);
CSRedisCacheHelper.Publish("redis-roomstatus-monitor", NNN);
Interlocked.Exchange(ref StepTongJi.LookDataCounter, 0);
}
}
if (VVV.CmdType == 0x08)
{
MemoryCacheHelper.Set(ShiJianLanJieSync, 1, DateTimeOffset.Now.AddSeconds(DataTongJi.LostPackage_Interval));
}
if (VVV.CmdType == 0x02)
{
MemoryCacheHelper.Set(ShiJianLanJie, 1, DateTimeOffset.Now.AddSeconds(50));
}
string LanJieKey = "Intercept";
ConcurrentBag<string> RoomNumberList = null;
bool isexists = DataTongJi.BlockLowerMachineList.TryGetValue(hotelCode, out RoomNumberList);
//如果存在数据
if (isexists)
{
//如果 设备序号存在就过滤掉
if (RoomNumberList != null && RoomNumberList.Count > 0)
{
//只过滤这些数据
if (RoomNumberList.ToList().Contains(hostnumber1.ToString()))
{
if (VVV.CmdType == 0x0E)
{
string KeyFilter = "StatusFilter";
RCUHost.RCUHostCommon.tools.LanJieData(KeyFilter, hotelCode);
}
LanJieData(LanJieKey, hotelCode);
StepTongJi.SendInfo(1.01, "进入黑名单,不再有后续处理", context.MessageID, context.IsMonitor);
}
//如果不存在就处理
else
{
GaiXie g = new GaiXie();
g.Data = receiveBuffer111;
g.IPEndPoint = remoteEP111.ToString();
var data = Newtonsoft.Json.JsonConvert.SerializeObject(g);
CSRedisCacheHelper.StreamAdd(1, "All_UDPPackage_Data", data);
}
}
else
{
if (VVV.CmdType == 0x0E)
{
string KeyFilter = "StatusFilter";
RCUHost.RCUHostCommon.tools.LanJieData(KeyFilter, hotelCode);
}
//如果存在,且 设备列表为0
LanJieData(LanJieKey, hotelCode);
StepTongJi.SendInfo(1.01, "进入黑名单,不再有后续处理", context.MessageID, context.IsMonitor);
}
}
else
{
GaiXie g = new GaiXie();
g.Data = receiveBuffer111;
g.IPEndPoint = remoteEP111.ToString();
var data = Newtonsoft.Json.JsonConvert.SerializeObject(g);
CSRedisCacheHelper.StreamAdd(1, "All_UDPPackage_Data", data);
var ts1 = new Tuple<ReceiverContext, string>(context, hotelCode);
}
}
#endregion
else
{
//错误数据
Interlocked.Increment(ref YUANZI_TongJi.TotalErrorPackageReceiveCount);
}
}
catch (Exception ex)
{
logger.Error("统计Error:" + ex.Message);
}
}
else
{
Interlocked.Increment(ref YUANZI_TongJi.TotalErrorPackageReceiveCount);
}
var dataState = (Tuple<byte[], IPEndPoint>)stateObj;
ProcessUdpData(dataState.Item1, dataState.Item2);
}, Tuple.Create(receiveBuffer111, remoteEP111));
}
}
catch (Exception ex)
@@ -695,6 +492,226 @@ namespace RCUHost.Implement
}
}
public void ProcessUdpData(byte[] receiveBuffer111, IPEndPoint remoteEP111)
{
if (receiveBuffer111.Length > 0)
{
#region
Interlocked.Increment(ref YUANZI_TongJi.TotalReceiveCount);
#endregion
ReceiverContext context = new ReceiverContext(receiveBuffer111, remoteEP111, GetNextCustomer());
int length = context.Data.Length;
if (length < 3 || length != BitConverter.ToInt16(context.Data, 2))
{
//错误数据
Interlocked.Increment(ref YUANZI_TongJi.TotalErrorPackageReceiveCount);
return;//非正确的数据包
}
context.SystemHeader = DecodeSystemHeader(context.Data);
if (context.SystemHeader.HasValue)
{
if (!String.Equals(new String(context.SystemHeader.Value.SystemID), SystemHeader.SYSTEM_ID, StringComparison.OrdinalIgnoreCase))
{
//错误数据
Interlocked.Increment(ref YUANZI_TongJi.TotalErrorPackageReceiveCount);
return;//非系统数据包
}
try
{
//透传是新增加的
var VVV = context.SystemHeader.Value;
string KKKHNH = CacheKey.TouChuanKey;
var HHHostNo = context.SystemHeader.Value.HostNumber.ToString();
var da1 = CSRedisCacheHelper.HMGet<string>(1, KKKHNH, HHHostNo);
if (!string.IsNullOrEmpty(da1[0]))
{
string nns = Tools.ByteToString(context.Data);
if (VVV.CmdType == 0x71)
{
BLWMQTT.MQTTPublishData("blw/touchuan/report/" + HHHostNo, nns);
}
}
#region
if (VVV.CmdType != 0xD6 && VVV.CmdType != 0x0C)
{
var hostnumber1 = VVV.HostNumber;
string hotelCode = hostnumber1.ToHotelCode().ToString();//获取酒店编码
var hostnumber2 = hostnumber1.ToString();
//时间拦截 超过2秒就不再处理
string ShiJianLanJie = CacheKey.TimeIntercept + "_" + hostnumber2;
string ShiJianLanJieSync = CacheKey.SyncTimeIntercept + "_" + hostnumber2;
if (VVV.CmdType == 0x0E)
{
//有错误的0x19数据所有的 在0x19数据触发后的5秒内的后续数据就不再接收
#region 0x19
string key123 = RoomStatusReceiver.PoolOverFlowKey + "_" + hostnumber2;
var OOObj = MemoryCacheHelper.Get(key123);
if (OOObj != null)
{
//错误数据
Interlocked.Increment(ref YUANZI_TongJi.TotalErrorPackageReceiveCount);
return;
}
#endregion
}
///消息ID +1
Interlocked.Increment(ref StepTongJi.EveryMessageIDNo);
//因为0E不会被拦截所以可以在这里写
bool nenver = false;
if (nenver)
//if (VVV.CmdType == 0x0E || VVV.CmdType == 0X01)
{
//StepTongJi.EveryMessageID = Guid.NewGuid().ToString("N");
//计数器+1
Interlocked.Increment(ref StepTongJi.LookDataCounter);
//开始监听
Interlocked.Increment(ref StepTongJi.Every_0E_01_MessageID);
if (StepTongJi.LookDataCounter == 500)
{
//监听的ID
//Interlocked.Exchange(ref StepTongJi.GlobalListenID, StepTongJi.EveryMessageID);
context.MessageID = Guid.NewGuid().ToString("N");
context.IsMonitor = true;
int maxWorker = 0;
int maxIo = 0;
int availWorker = 0;
int availIo = 0;
// 获取最大线程数
ThreadPool.GetMaxThreads(out maxWorker, out maxIo);
// 获取可用线程数
ThreadPool.GetAvailableThreads(out availWorker, out availIo);
// 计算忙碌线程数
int busyWorker = maxWorker - availWorker;
int busyIo = maxIo - availIo;
int minWorker = 0;
int minIo = 0;
// 获取最小线程数
ThreadPool.GetMinThreads(out minWorker, out minIo);
int tid = Thread.CurrentThread.ManagedThreadId;
string NNN1 = string.Format("工作线程{8}: 最小={0}, 最大={1}, 可用={2}, 使用中={3},IO线程: 最小={4}, 最大={5}, 可用={6}, 使用中={7}", minWorker, maxWorker, availWorker, busyWorker, minIo, maxIo, availIo, busyIo, tid);
StepTongJi.SendInfo(0.1, NNN1, context.MessageID, context.IsMonitor);
string NNN7 = string.Format("HostNUMBER:{0},端点:{1}", hostnumber2, context.RemoteEndPoint.ToString());
StepTongJi.SendInfo(0.2, NNN7, context.MessageID, context.IsMonitor);
StepInfo s = new StepInfo();
s.Step = 1;
s.MessageId = context.MessageID;
s.StepDescription = "进入UDPCallBack";
//string ti = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff");
string ti = CPUData.GetNowPrecise().ToString("yyyy-MM-dd HH:mm:ss.ffffff");
s.TriggerTime = ti;
s.Content = context.Data;
s.EveryMessageId = StepTongJi.EveryMessageIDNo;
s.Monitor_0E_01 = StepTongJi.Every_0E_01_MessageID;
s.HotelCode = hotelCode;
s.HostNumber = hostnumber2;
string NNN = Newtonsoft.Json.JsonConvert.SerializeObject(s);
CSRedisCacheHelper.Publish("redis-roomstatus-monitor", NNN);
Interlocked.Exchange(ref StepTongJi.LookDataCounter, 0);
}
}
if (VVV.CmdType == 0x08)
{
MemoryCacheHelper.Set(ShiJianLanJieSync, 1, DateTimeOffset.Now.AddSeconds(DataTongJi.LostPackage_Interval));
}
if (VVV.CmdType == 0x02)
{
MemoryCacheHelper.Set(ShiJianLanJie, 1, DateTimeOffset.Now.AddSeconds(50));
}
string LanJieKey = "Intercept";
ConcurrentBag<string> RoomNumberList = null;
bool isexists = DataTongJi.BlockLowerMachineList.TryGetValue(hotelCode, out RoomNumberList);
//如果存在数据
if (isexists)
{
//如果 设备序号存在就过滤掉
if (RoomNumberList != null && RoomNumberList.Count > 0)
{
//只过滤这些数据
if (RoomNumberList.Contains(hostnumber1.ToString()))
{
if (VVV.CmdType == 0x0E)
{
string KeyFilter = "StatusFilter";
RCUHost.RCUHostCommon.tools.LanJieData(KeyFilter, hotelCode);
}
LanJieData(LanJieKey, hotelCode);
StepTongJi.SendInfo(1.01, "进入黑名单,不再有后续处理", context.MessageID, context.IsMonitor);
}
//如果不存在就处理
else
{
GaiXie g = new GaiXie();
g.Data = receiveBuffer111;
g.IPEndPoint = remoteEP111.ToString();
var data = Newtonsoft.Json.JsonConvert.SerializeObject(g);
CSRedisCacheHelper.StreamAdd(1, "All_UDPPackage_Data", data);
}
}
else
{
if (VVV.CmdType == 0x0E)
{
string KeyFilter = "StatusFilter";
RCUHost.RCUHostCommon.tools.LanJieData(KeyFilter, hotelCode);
}
//如果存在,且 设备列表为0
LanJieData(LanJieKey, hotelCode);
StepTongJi.SendInfo(1.01, "进入黑名单,不再有后续处理", context.MessageID, context.IsMonitor);
}
}
else
{
GaiXie g = new GaiXie();
g.Data = receiveBuffer111;
g.IPEndPoint = remoteEP111.ToString();
var data = Newtonsoft.Json.JsonConvert.SerializeObject(g);
CSRedisCacheHelper.StreamAdd(1, "All_UDPPackage_Data", data);
var ts1 = new Tuple<ReceiverContext, string>(context, hotelCode);
}
}
#endregion
else
{
//错误数据
Interlocked.Increment(ref YUANZI_TongJi.TotalErrorPackageReceiveCount);
}
}
catch (Exception ex)
{
logger.Error("统计Error:" + ex.Message);
}
}
else
{
Interlocked.Increment(ref YUANZI_TongJi.TotalErrorPackageReceiveCount);
}
}
}
public static void LanJieData(string Key11, string hotelCode)
{
var Key = "UDPPackage_" + Key11.ToString();
@@ -1966,9 +1983,9 @@ namespace RCUHost.Implement
{
string dizhi = item.Value.FaultNo;
ts_faultitem t1 = new ts_faultitem();
t1.dev_type = short.Parse(dizhi.Substring(0, 3));
t1.dev_addr = short.Parse(dizhi.Substring(3, 3));
t1.dev_loop = short.Parse(dizhi.Substring(6, 3));
t1.dev_type = ushort.Parse(dizhi.Substring(0, 3));
t1.dev_addr = ushort.Parse(dizhi.Substring(3, 3));
t1.dev_loop = ushort.Parse(dizhi.Substring(6, 3));
t1.error_type = item.Value.Type;
t1.error_data = item.Value.Data;
lll2.Add(t1);
@@ -2624,7 +2641,7 @@ namespace RCUHost.Implement
CardEvent = NOCardInfo,
PMS_Status = PMS_CurrentStatus,
Bright_G = Bright_Va,
WeiXinSuo_DianLiang=usa
WeiXinSuo_DianLiang = usa
};
string mns = Newtonsoft.Json.JsonConvert.SerializeObject(ns2);

View File

@@ -2012,9 +2012,9 @@ namespace RCUHost.Implement
{
string dizhi = item.Value.FaultNo;
ts_faultitem t1 = new ts_faultitem();
t1.dev_type = short.Parse(dizhi.Substring(0, 3));
t1.dev_addr = short.Parse(dizhi.Substring(3, 3));
t1.dev_loop = short.Parse(dizhi.Substring(6, 3));
t1.dev_type = ushort.Parse(dizhi.Substring(0, 3));
t1.dev_addr = ushort.Parse(dizhi.Substring(3, 3));
t1.dev_loop = ushort.Parse(dizhi.Substring(6, 3));
t1.error_type = item.Value.Type;
t1.error_data = item.Value.Data;
exception_list.Add(t1);

View File

@@ -95,6 +95,10 @@ namespace WebSite.Controllers
if (hostModal != null)
{
item.Status = hostModal.Status;
if (hostModal.ModalType==DeviceType.AirConditioner)
{
item.Status = hostModal.AirConditionData.AirStatus;
}
item.Brightness = hostModal.Brightness;
var aaa = hostModal.AirConditionData;
item.CurrentTemp = aaa.CurrentTemp;

View File

@@ -229,15 +229,11 @@ namespace WebSite
T.Stop();
double d = CPUData.GetCPU();
DataTongJi.CPU_Data.Add(d);
// 简单的上限保护,避免长期积累导致内存膨胀
//if (DataTongJi.CPU_Data.Count > 1000)
//{
// DataTongJi.CPU_Data = new System.Collections.Concurrent.ConcurrentBag<double>();
//}
}
catch (Exception ex)
{
logger.Error("CPU 数量统计出错了:" + ex.Message);
logger.Error("CPU 数量统计出错了:" + ex.StackTrace);
}
finally
{