@@ -1,6 +1,6 @@ | |||
# JT808 WebApi服务 | |||
基地址:<a href="#">http://localhost:828/jt808api/</a> | |||
基地址: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\<T> | |||
|属性|数据类型|参数说明| | |||
@@ -442,4 +477,36 @@ | |||
"TotalSendSize":0.01953125 | |||
} | |||
} | |||
``` | |||
### <span id="system_collect">系统性能数据采集服务</span> | |||
请求地址: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" | |||
} | |||
} | |||
``` |
@@ -0,0 +1,33 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
namespace JT808.DotNetty.Abstractions.Dtos | |||
{ | |||
public class JT808SystemCollectInfoDto | |||
{ | |||
/// <summary> | |||
/// 进程Id | |||
/// </summary> | |||
public int ProcessId { get; set; } | |||
/// <summary> | |||
/// 进程分配内存 | |||
/// 单位MB | |||
/// </summary> | |||
public double WorkingSet64 { get; set; } | |||
/// <summary> | |||
/// 进程分配内存峰值 | |||
/// 单位MB | |||
/// </summary> | |||
public double PeakWorkingSet64 { get; set; } | |||
/// <summary> | |||
/// 进程分配私有内存 | |||
/// 单位MB | |||
/// </summary> | |||
public double PrivateMemorySize64 { get; set; } | |||
/// <summary> | |||
/// 进程执行CPU总处理时间 | |||
/// </summary> | |||
public TimeSpan CPUTotalProcessorTime { get; set; } | |||
} | |||
} |
@@ -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"; | |||
/// <summary> | |||
///获取当前系统进程使用率 | |||
/// </summary> | |||
public static string SystemCollectGet = $"{RouteTablePrefix}/{SystemCollectPrefix}/Get"; | |||
/// <summary> | |||
///基于Tcp的添加转发过滤地址 | |||
/// </summary> | |||
@@ -27,7 +27,15 @@ namespace JT808.DotNetty.Core.Handlers | |||
protected void CreateRoute(string url, Func<JT808HttpRequest, JT808HttpResponse> func) | |||
{ | |||
HandlerDict.Add(url, func); | |||
if (!HandlerDict.ContainsKey(url)) | |||
{ | |||
HandlerDict.Add(url, func); | |||
} | |||
else | |||
{ | |||
// 替换 | |||
HandlerDict[url] = func; | |||
} | |||
} | |||
public Dictionary<string, Func<JT808HttpRequest, JT808HttpResponse>> HandlerDict { get; } | |||
@@ -26,6 +26,7 @@ namespace JT808.DotNetty.Core | |||
serviceDescriptors.TryAddSingleton<IJT808UnificationUdpSendService, JT808UnificationUdpSendService>(); | |||
serviceDescriptors.TryAddSingleton<IJT808TcpSessionService, JT808TcpSessionService>(); | |||
serviceDescriptors.TryAddSingleton<IJT808UdpSessionService, JT808UdpSessionService>(); | |||
serviceDescriptors.TryAddSingleton<JT808SimpleSystemCollectService>(); | |||
return serviceDescriptors; | |||
} | |||
} |
@@ -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 | |||
{ | |||
/// <summary> | |||
/// 简单系统收集服务 | |||
/// </summary> | |||
public class JT808SimpleSystemCollectService | |||
{ | |||
/// <summary> | |||
/// 获取系统当前进程使用情况 | |||
/// </summary> | |||
/// <returns></returns> | |||
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; | |||
} | |||
} | |||
} |
@@ -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 |
@@ -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; | |||
@@ -31,11 +31,14 @@ namespace JT808.DotNetty.WebApi.Handlers | |||
private readonly JT808UdpTrafficService jT808UdpTrafficService; | |||
private readonly JT808SimpleSystemCollectService jT808SimpleSystemCollectService; | |||
/// <summary> | |||
/// TCP一套注入 | |||
/// </summary> | |||
/// <param name="jT808TcpAtomicCounterService"></param> | |||
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 | |||
/// </summary> | |||
/// <param name="jT808UdpAtomicCounterService"></param> | |||
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 | |||
/// <param name="jT808TcpAtomicCounterService"></param> | |||
/// <param name="jT808UdpAtomicCounterService"></param> | |||
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); | |||
} | |||
/// <summary> | |||
/// 获取当前系统进程使用率 | |||
/// </summary> | |||
/// <param name="request"></param> | |||
/// <returns></returns> | |||
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); | |||