Browse Source

1.修复获取session集合报错

2.增加tcp测试图表展示
tags/v2.3.1
SmallChi(Koike) 5 years ago
parent
commit
ecda7ce619
10 changed files with 289 additions and 11 deletions
  1. +63
    -0
      src/JT808.DotNetty.CleintBenchmark/Controllers/ReportController.cs
  2. +21
    -1
      src/JT808.DotNetty.CleintBenchmark/JT808.DotNetty.CleintBenchmark.csproj
  3. +28
    -1
      src/JT808.DotNetty.CleintBenchmark/Program.cs
  4. +1
    -1
      src/JT808.DotNetty.CleintBenchmark/Services/CleintBenchmarkHostedService.cs
  5. +5
    -3
      src/JT808.DotNetty.CleintBenchmark/appsettings.json
  6. +13
    -0
      src/JT808.DotNetty.CleintBenchmark/wwwroot/echarts.min.js
  7. +153
    -0
      src/JT808.DotNetty.CleintBenchmark/wwwroot/index.html
  8. +1
    -1
      src/JT808.DotNetty.Client/JT808.DotNetty.Client.csproj
  9. +2
    -2
      src/JT808.DotNetty.Client/JT808TcpClient.cs
  10. +2
    -2
      src/JT808.DotNetty.Core/Session/JT808SessionManager.cs

+ 63
- 0
src/JT808.DotNetty.CleintBenchmark/Controllers/ReportController.cs View File

@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JT808.DotNetty.Client;
using JT808.DotNetty.Client.Metadata;
using JT808.DotNetty.Client.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Primitives;

namespace JT808.DotNetty.CleintBenchmark
{
/// <summary>
/// 车辆控制器
/// </summary>
[Route("JT808WebApi")]
[ApiController]
[EnableCors("Domain")]
public class ReportController : ControllerBase
{
private readonly IJT808TcpClientFactory clientFactory;
private readonly JT808ReceiveAtomicCounterService ReceiveAtomicCounterService;
private readonly JT808SendAtomicCounterService SendAtomicCounterService;

/// <summary>
///
/// </summary>
public ReportController(
IJT808TcpClientFactory factory,
JT808ReceiveAtomicCounterService jT808ReceiveAtomicCounterService,
JT808SendAtomicCounterService jT808SendAtomicCounterService)
{
clientFactory = factory;
ReceiveAtomicCounterService = jT808ReceiveAtomicCounterService;
SendAtomicCounterService = jT808SendAtomicCounterService;
}

[HttpPost]
[HttpGet]
[Route("QueryReport")]
public ActionResult<JT808Report> QueryReport()
{
var clients = clientFactory.GetAll();
JT808Report report = new JT808Report()
{
SendTotalCount = SendAtomicCounterService.MsgSuccessCount,
ReceiveTotalCount = ReceiveAtomicCounterService.MsgSuccessCount,
CurrentDate = DateTime.Now,
Connections = clients.Count,
OnlineConnections = clients.Where(w => w.IsOpen).Count(),
OfflineConnections = clients.Where(w => !w.IsOpen).Count(),
};
return report;
}
}
}

+ 21
- 1
src/JT808.DotNetty.CleintBenchmark/JT808.DotNetty.CleintBenchmark.csproj View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<OutputType>Exe</OutputType>
@@ -6,6 +6,11 @@
<LangVersion>7.3</LangVersion>
</PropertyGroup>

<ItemGroup>
<Content Remove="wwwroot\echarts.min.js" />
<Content Remove="wwwroot\index.html" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.0" />
@@ -18,6 +23,21 @@
<ProjectReference Include="..\JT808.DotNetty.Client\JT808.DotNetty.Client.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="wwwroot\echarts.min.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="wwwroot\index.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<Content Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>


+ 28
- 1
src/JT808.DotNetty.CleintBenchmark/Program.cs View File

@@ -7,8 +7,10 @@ using System.Threading.Tasks;
using JT808.Protocol;
using JT808.DotNetty.Client;
using JT808.DotNetty.CleintBenchmark.Configs;
using JT808.DotNetty.CleintBenchmark.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Builder;
using JT808.DotNetty.CleintBenchmark.Services;

namespace JT808.DotNetty.CleintBenchmark
{
@@ -22,6 +24,31 @@ namespace JT808.DotNetty.CleintBenchmark
config.SetBasePath(AppDomain.CurrentDomain.BaseDirectory);
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.Configure(app =>
{
app.UseRouting();
app.UseCors("Domain");
app.UseStaticFiles();
app.UseDefaultFiles("/index.html");
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
})
.ConfigureServices((hostContext, services) =>
{
services.AddControllers();
services.AddCors(options =>
options.AddPolicy("Domain", builder =>
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowAnyOrigin()));

});
})
.ConfigureLogging((context, logging) =>
{
if (Environment.OSVersion.Platform == PlatformID.Unix)


+ 1
- 1
src/JT808.DotNetty.CleintBenchmark/Services/CleintBenchmarkHostedService.cs View File

@@ -71,7 +71,7 @@ namespace JT808.DotNetty.CleintBenchmark.Services
}
catch (Exception ex)
{
logger.LogError(ex, "");
logger.LogError(ex.Message);
}
});
Thread.Sleep(clientBenchmarkOptions.Interval);


+ 5
- 3
src/JT808.DotNetty.CleintBenchmark/appsettings.json View File

@@ -3,20 +3,22 @@
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Trace"
"Default": "Error"
}
},
"Console": {
"LogLevel": {
"Default": "Trace"
"Default": "Error"
}
}
},
"AllowedHosts": "*",
//"urls": "http://*:15004;",
"ClientBenchmarkOptions": {
"IP": "127.0.0.1",
"Port": 808,
"DeviceCount": 100,
"Interval": 1000,
"DeviceTemplate": 300000 //需要多台机器同时访问,那么可以根据这个避开重复终端号 100000-200000-300000
"DeviceTemplate": 100000 //需要多台机器同时访问,那么可以根据这个避开重复终端号 100000-200000-300000
}
}

+ 13
- 0
src/JT808.DotNetty.CleintBenchmark/wwwroot/echarts.min.js
File diff suppressed because it is too large
View File


+ 153
- 0
src/JT808.DotNetty.CleintBenchmark/wwwroot/index.html View File

@@ -0,0 +1,153 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<title>收发查看</title>
<script src="https://unpkg.com/dayjs"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="/echarts.min.js"></script>
</head>

<body>
<div id="tcpContainer" style="text-align:center;margin:20px auto;width:80%;height: 300px;"></div>
<div id="connContainer" style="text-align:center;margin:20px auto;width:80%;height: 300px;"></div>
<script type="text/javascript">
var tcpDom = document.getElementById("tcpContainer");
var connDom = document.getElementById("connContainer");
var tcpChart = echarts.init(tcpDom);
var connChart = echarts.init(connDom);
var sendData=[];
var receiveData=[];
var onlineData=[];
var offlineData=[];
var timeData=[];
var tcpOption = {
title: {
text: 'TCP收发数'
},
tooltip: {
trigger: 'axis',
axisPointer: {
animation: true
}
},
legend: {
data:['发送总次数','接收总次数']
},
xAxis: {
type: 'category',
boundaryGap: false,
data: timeData
},
yAxis: {
type: 'value',
boundaryGap: [0, '100%'],
splitLine: {
show: true
}
},
series: [{
name: '发送总次数',
type: 'line',
color: "blue",
data: sendData
},{
name: '接收总次数',
type: 'line',
color: "red",
data: receiveData
}]
};
var connOption = {
title: {
text: 'TCP连接数'
},
tooltip: {
trigger: 'axis',
axisPointer: {
animation: true
}
},
legend: {
data:['tcp在线数','tcp离线数']
},
xAxis: {
type: 'category',
boundaryGap: false,
data: timeData
},
yAxis: {
type: 'value',
boundaryGap: [0, '100%'],
splitLine: {
show: true
}
},
series: [{
name: 'tcp在线数',
type: 'line',
color: "blue",
data: onlineData
},{
name: 'tcp离线数',
type: 'line',
color: "red",
data: offlineData
}]
};
setInterval(function () {
axios.post('http://localhost:5000/JT808WebApi/QueryReport')
.then((response) => {
if (response.data) {
if(sendData.length>16){
sendData.shift();
receiveData.shift();
onlineData.shift();
offlineData.shift();
timeData.shift();
}
//console.log(response.data);
timeData.push(dayjs(response.data.currentDate).format('HH:mm:ss'));
sendData.push(response.data.sendTotalCount);
receiveData.push(response.data.receiveTotalCount);
onlineData.push(response.data.onlineConnections);
offlineData.push(response.data.offlineConnections);
tcpChart.setOption({
series: [{
data: sendData
},{
data: receiveData
}],
xAxis:[{
data: timeData
}]
});
connChart.setOption({
series: [{
data: onlineData
},{
data: offlineData
}],
xAxis:[{
data: timeData
}]
});
} else {
alert("没有数据");
}
})
.catch((error) => {
console.log(error);
});
}, 1000);
if (tcpOption && typeof tcpOption === "object") {
tcpChart.setOption(tcpOption, true);
}
if (connOption && typeof connOption === "object") {
connChart.setOption(connOption, true);
}
</script>
</body>

</html>

+ 1
- 1
src/JT808.DotNetty.Client/JT808.DotNetty.Client.csproj View File

@@ -24,7 +24,7 @@
<PackageReference Include="DotNetty.Handlers" Version="0.6.0" />
<PackageReference Include="DotNetty.Transport.Libuv" Version="0.6.0" />
<PackageReference Include="DotNetty.Codecs" Version="0.6.0" />
<PackageReference Include="JT808" Version="2.2.1" />
<PackageReference Include="JT808" Version="2.2.2" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />


+ 2
- 2
src/JT808.DotNetty.Client/JT808TcpClient.cs View File

@@ -64,14 +64,14 @@ namespace JT808.DotNetty.Client
});
}

public async void Send(JT808ClientRequest request)
public void Send(JT808ClientRequest request)
{
if (disposed) return;
if (clientChannel == null) throw new NullReferenceException("Channel is empty.");
if (request == null) throw new ArgumentNullException("JT808ClientRequest Parameter is empty.");
if (clientChannel.Active && clientChannel.Open)
{
await clientChannel.WriteAndFlushAsync(request);
clientChannel.WriteAndFlushAsync(request);
}
}



+ 2
- 2
src/JT808.DotNetty.Core/Session/JT808SessionManager.cs View File

@@ -294,11 +294,11 @@ namespace JT808.DotNetty.Core.Session
}
public IEnumerable<JT808TcpSession> GetTcpAll()
{
return Sessions.Select(s => (JT808TcpSession)s.Value).Where(w => w.TransportProtocolType == JT808TransportProtocolType.tcp).ToList();
return Sessions.Where(w => w.Value.TransportProtocolType == JT808TransportProtocolType.tcp).Select(s => (JT808TcpSession)s.Value).ToList();
}
public IEnumerable<JT808UdpSession> GetUdpAll()
{
return Sessions.Select(s => (JT808UdpSession)s.Value).Where(w => w.TransportProtocolType == JT808TransportProtocolType.udp).ToList();
return Sessions.Where(w => w.Value.TransportProtocolType == JT808TransportProtocolType.udp).Select(s => (JT808UdpSession)s.Value).ToList();
}
}
}

Loading…
Cancel
Save