diff --git a/api/README.md b/api/README.md index 559eb3c..1253caa 100644 --- a/api/README.md +++ b/api/README.md @@ -1,6 +1,6 @@ # JT808 WebApi服务 -基地址:http://localhost:828/jt808api/ +基地址:127.0.0.1:828/jt808api/ 数据格式:只支持Json格式 @@ -34,6 +34,41 @@ [基于Udp流量统计服务](#udp_traffic) +## 6.系统性能数据采集服务 + +[获取当前系统进程使用率](#system_collect) + +## 接口请求对照表 + +### 基于Tcp接口请求 + +|请求Url|请求方式|说明| +|:------|:------|:------| +| 127.0.0.1:828/jt808api/Tcp/UnificationSend| POST| 基于Tcp统一下发设备消息服务| +| 127.0.0.1:828/jt808api/Tcp/Session/GetAll| GET| 基于Tcp管理会话服务-获取会话集合| +| 127.0.0.1:828/jt808api/Tcp/Session/RemoveByTerminalPhoneNo| POST| 基于Tcp管理会话服务-通过设备终端号移除对应会话| +| 127.0.0.1:828/jt808api/Tcp/Transmit/Add| POST| 基于Tcp转发地址过滤服务-添加转发过滤地址| +| 127.0.0.1:828/jt808api/Tcp/Transmit/Remove| POST| 基于Tcp转发地址过滤服务-删除转发过滤地址| +| 127.0.0.1:828/jt808api/Tcp/Transmit/GetAll| GET| 基于Tcp转发地址过滤服务-获取转发过滤地址信息集合| +| 127.0.0.1:828/jt808api/Tcp/GetAtomicCounter| GET| 基于Tcp消息包计数服务| +| 127.0.0.1:828/jt808api/Tcp/Traffic/Get| GET| 基于Tcp流量统计服务| + +### 基于Udp接口请求 + +|请求Url|请求方式|说明| +|:------|:------|:------| +| 127.0.0.1:828/jt808api/Udp/UnificationSend| POST| 基于Udp统一下发设备消息服务| +| 127.0.0.1:828/jt808api/Udp/Session/GetAll| GET| 基于Udp管理会话服务-获取会话集合| +| 127.0.0.1:828/jt808api/Udp/Session/RemoveByTerminalPhoneNo| POST| 基于Udp管理会话服务-通过设备终端号移除对应会话| +| 127.0.0.1:828/jt808api/Udp/GetAtomicCounter| GET| 基于Udp消息包计数服务| +| 127.0.0.1:828/jt808api/Udp/Traffic/Get| GET| 基于Udp流量统计服务| + +### 公共接口请求 + +|请求Url|请求方式|说明| +|:------|:------|:------| +| 127.0.0.1:828/jt808api/SystemCollect/Get| GET| 获取当前系统进程使用情况| + ### 统一对象返回 JT808ResultDto\ |属性|数据类型|参数说明| @@ -442,4 +477,36 @@ "TotalSendSize":0.01953125 } } +``` + +### 系统性能数据采集服务 + +请求地址:SystemCollect/Get + +请求方式:GET + +返回数据: + +|属性|数据类型|参数说明| +|------|:------:|:------| +| ProcessId| int| 进程Id| +| WorkingSet64| double| 进程分配内存(单位MB)| +| PeakWorkingSet64| double| 进程分配内存峰值(单位MB)| +| PrivateMemorySize64| double| 进程分配私有内存(单位MB)| +| CPUTotalProcessorTime| TimeSpan|进程执行CPU总处理时间| + +返回结果: + +``` sc +{ + "Message":"", + "Code":200, + "Data":{ + "ProcessId":101412, + "WorkingSet64":73.0625, + "PeakWorkingSet64":73.0625, + "PrivateMemorySize64":134.6796875, + "CPUTotalProcessorTime":"00:00:14.5625000" + } +} ``` \ No newline at end of file diff --git a/src/JT808.DotNetty.Abstractions/Dtos/JT808SystemCollectInfoDto.cs b/src/JT808.DotNetty.Abstractions/Dtos/JT808SystemCollectInfoDto.cs new file mode 100644 index 0000000..23c883c --- /dev/null +++ b/src/JT808.DotNetty.Abstractions/Dtos/JT808SystemCollectInfoDto.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace JT808.DotNetty.Abstractions.Dtos +{ + public class JT808SystemCollectInfoDto + { + /// + /// 进程Id + /// + public int ProcessId { get; set; } + /// + /// 进程分配内存 + /// 单位MB + /// + public double WorkingSet64 { get; set; } + /// + /// 进程分配内存峰值 + /// 单位MB + /// + public double PeakWorkingSet64 { get; set; } + /// + /// 进程分配私有内存 + /// 单位MB + /// + public double PrivateMemorySize64 { get; set; } + /// + /// 进程执行CPU总处理时间 + /// + public TimeSpan CPUTotalProcessorTime { get; set; } + } +} diff --git a/src/JT808.DotNetty.Abstractions/JT808Constants.cs b/src/JT808.DotNetty.Abstractions/JT808Constants.cs index b331acb..bc65121 100644 --- a/src/JT808.DotNetty.Abstractions/JT808Constants.cs +++ b/src/JT808.DotNetty.Abstractions/JT808Constants.cs @@ -14,12 +14,18 @@ public const string TransmitPrefix = "Transmit"; + public const string SystemCollectPrefix = "SystemCollect"; + public const string TrafficPrefix = "Traffic"; public const string TcpPrefix = "Tcp"; public const string UdpPrefix = "Udp"; + /// + ///获取当前系统进程使用率 + /// + public static string SystemCollectGet = $"{RouteTablePrefix}/{SystemCollectPrefix}/Get"; /// ///基于Tcp的添加转发过滤地址 /// diff --git a/src/JT808.DotNetty.Core/Handlers/JT808MsgIdHttpHandlerBase.cs b/src/JT808.DotNetty.Core/Handlers/JT808MsgIdHttpHandlerBase.cs index 62e8b76..fc7ef74 100644 --- a/src/JT808.DotNetty.Core/Handlers/JT808MsgIdHttpHandlerBase.cs +++ b/src/JT808.DotNetty.Core/Handlers/JT808MsgIdHttpHandlerBase.cs @@ -27,7 +27,15 @@ namespace JT808.DotNetty.Core.Handlers protected void CreateRoute(string url, Func func) { - HandlerDict.Add(url, func); + if (!HandlerDict.ContainsKey(url)) + { + HandlerDict.Add(url, func); + } + else + { + // 替换 + HandlerDict[url] = func; + } } public Dictionary> HandlerDict { get; } diff --git a/src/JT808.DotNetty.Core/JT808CoreDotnettyExtensions.cs b/src/JT808.DotNetty.Core/JT808CoreDotnettyExtensions.cs index 5dd16a3..88396cc 100644 --- a/src/JT808.DotNetty.Core/JT808CoreDotnettyExtensions.cs +++ b/src/JT808.DotNetty.Core/JT808CoreDotnettyExtensions.cs @@ -26,6 +26,7 @@ namespace JT808.DotNetty.Core serviceDescriptors.TryAddSingleton(); serviceDescriptors.TryAddSingleton(); serviceDescriptors.TryAddSingleton(); + serviceDescriptors.TryAddSingleton(); return serviceDescriptors; } } diff --git a/src/JT808.DotNetty.Core/Services/JT808SimpleSystemCollectService.cs b/src/JT808.DotNetty.Core/Services/JT808SimpleSystemCollectService.cs new file mode 100644 index 0000000..2482cff --- /dev/null +++ b/src/JT808.DotNetty.Core/Services/JT808SimpleSystemCollectService.cs @@ -0,0 +1,30 @@ +using JT808.DotNetty.Abstractions.Dtos; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text; + +namespace JT808.DotNetty.Core.Services +{ + /// + /// 简单系统收集服务 + /// + public class JT808SimpleSystemCollectService + { + /// + /// 获取系统当前进程使用情况 + /// + /// + public JT808SystemCollectInfoDto Get() + { + JT808SystemCollectInfoDto jT808SystemCollectInfoDto = new JT808SystemCollectInfoDto(); + var proc = Process.GetCurrentProcess(); + jT808SystemCollectInfoDto.ProcessId = proc.Id; + jT808SystemCollectInfoDto.WorkingSet64 = proc.WorkingSet64 / 1024.0 / 1024.0; + jT808SystemCollectInfoDto.PeakWorkingSet64 = proc.PeakWorkingSet64 / 1024.0 / 1024.0; + jT808SystemCollectInfoDto.PrivateMemorySize64 = proc.PrivateMemorySize64 / 1024.0 / 1024.0; + jT808SystemCollectInfoDto.CPUTotalProcessorTime = proc.TotalProcessorTime; + return jT808SystemCollectInfoDto; + } + } +} diff --git a/src/JT808.DotNetty.Hosting/JT808.DotNetty.Hosting.ini b/src/JT808.DotNetty.Hosting/JT808.DotNetty.Hosting.ini new file mode 100644 index 0000000..75ec140 --- /dev/null +++ b/src/JT808.DotNetty.Hosting/JT808.DotNetty.Hosting.ini @@ -0,0 +1,6 @@ +[program:JT808.DotNetty.Hosting] +command=dotnet JT808.DotNetty.Hosting.dll +directory=/data/dotnetty_test +user=root +stdout_logfile=/data/supervisordlog/JT808.DotNetty.Hosting.log +redirect_stderr=true \ No newline at end of file diff --git a/src/JT808.DotNetty.Tests/JT808.DotNetty.Core.Test/JT808TcpSessionManagerTest.cs b/src/JT808.DotNetty.Tests/JT808.DotNetty.Core.Test/JT808TcpSessionManagerTest.cs index a076428..0baa77a 100644 --- a/src/JT808.DotNetty.Tests/JT808.DotNetty.Core.Test/JT808TcpSessionManagerTest.cs +++ b/src/JT808.DotNetty.Tests/JT808.DotNetty.Core.Test/JT808TcpSessionManagerTest.cs @@ -1,9 +1,5 @@ using DotNetty.Transport.Channels.Embedded; -using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.Collections.Generic; -using System.Text; using System.Threading; diff --git a/src/JT808.DotNetty.WebApi/Handlers/JT808MsgIdDefaultWebApiHandler.cs b/src/JT808.DotNetty.WebApi/Handlers/JT808MsgIdDefaultWebApiHandler.cs index ee0b637..0820b4e 100644 --- a/src/JT808.DotNetty.WebApi/Handlers/JT808MsgIdDefaultWebApiHandler.cs +++ b/src/JT808.DotNetty.WebApi/Handlers/JT808MsgIdDefaultWebApiHandler.cs @@ -31,11 +31,14 @@ namespace JT808.DotNetty.WebApi.Handlers private readonly JT808UdpTrafficService jT808UdpTrafficService; + private readonly JT808SimpleSystemCollectService jT808SimpleSystemCollectService; + /// /// TCP一套注入 /// /// public JT808MsgIdDefaultWebApiHandler( + JT808SimpleSystemCollectService jT808SimpleSystemCollectService, JT808TcpTrafficService jT808TcpTrafficService, IJT808UnificationTcpSendService jT808UnificationTcpSendService, IJT808TcpSessionService jT808TcpSessionService, @@ -43,11 +46,13 @@ namespace JT808.DotNetty.WebApi.Handlers JT808TcpAtomicCounterService jT808TcpAtomicCounterService ) { + this.jT808SimpleSystemCollectService = jT808SimpleSystemCollectService; this.jT808TcpTrafficService = jT808TcpTrafficService; this.jT808UnificationTcpSendService = jT808UnificationTcpSendService; this.jT808TcpSessionService = jT808TcpSessionService; this.jT808TransmitAddressFilterService = jT808TransmitAddressFilterService; this.jT808TcpAtomicCounterService = jT808TcpAtomicCounterService; + InitCommonRoute(); InitTcpRoute(); } @@ -56,16 +61,19 @@ namespace JT808.DotNetty.WebApi.Handlers /// /// public JT808MsgIdDefaultWebApiHandler( + JT808SimpleSystemCollectService jT808SimpleSystemCollectService, JT808UdpTrafficService jT808UdpTrafficService, IJT808UdpSessionService jT808UdpSessionService, IJT808UnificationUdpSendService jT808UnificationUdpSendService, JT808UdpAtomicCounterService jT808UdpAtomicCounterService ) { + this.jT808SimpleSystemCollectService = jT808SimpleSystemCollectService; this.jT808UdpTrafficService = jT808UdpTrafficService; this.jT808UdpSessionService = jT808UdpSessionService; this.jT808UnificationUdpSendService = jT808UnificationUdpSendService; this.jT808UdpAtomicCounterService = jT808UdpAtomicCounterService; + InitCommonRoute(); InitUdpRoute(); } @@ -75,7 +83,8 @@ namespace JT808.DotNetty.WebApi.Handlers /// /// public JT808MsgIdDefaultWebApiHandler( - JT808TcpTrafficService jT808TcpTrafficService, + JT808SimpleSystemCollectService jT808SimpleSystemCollectService, + JT808TcpTrafficService jT808TcpTrafficService, JT808UdpTrafficService jT808UdpTrafficService, IJT808UnificationTcpSendService jT808UnificationTcpSendService, IJT808UnificationUdpSendService jT808UnificationUdpSendService, @@ -86,6 +95,7 @@ namespace JT808.DotNetty.WebApi.Handlers JT808UdpAtomicCounterService jT808UdpAtomicCounterService ) { + this.jT808SimpleSystemCollectService = jT808SimpleSystemCollectService; this.jT808TcpTrafficService = jT808TcpTrafficService; this.jT808UdpTrafficService = jT808UdpTrafficService; this.jT808UdpSessionService = jT808UdpSessionService; @@ -95,6 +105,7 @@ namespace JT808.DotNetty.WebApi.Handlers this.jT808TransmitAddressFilterService = jT808TransmitAddressFilterService; this.jT808TcpAtomicCounterService = jT808TcpAtomicCounterService; this.jT808UdpAtomicCounterService = jT808UdpAtomicCounterService; + InitCommonRoute(); InitTcpRoute(); InitUdpRoute(); } @@ -283,6 +294,21 @@ namespace JT808.DotNetty.WebApi.Handlers return CreateJT808HttpResponse(jT808TrafficInfoDto); } + /// + /// 获取当前系统进程使用率 + /// + /// + /// + public JT808HttpResponse SystemCollectGet(JT808HttpRequest request) + { + return CreateJT808HttpResponse(jT808SimpleSystemCollectService.Get()); + } + + protected virtual void InitCommonRoute() + { + CreateRoute(JT808Constants.JT808WebApiRouteTable.SystemCollectGet, SystemCollectGet); + } + protected virtual void InitTcpRoute() { CreateRoute(JT808Constants.JT808WebApiRouteTable.TransmitAdd, AddTransmitAddress);