Skip to content

Commit 75c46da

Browse files
committed
add a new dashboard
1 parent 4a830f9 commit 75c46da

7 files changed

Lines changed: 80 additions & 75 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace NSmartProxy.Data.DTOs
6+
{
7+
public class UserStatusDTO
8+
{
9+
public int offlineUsersCount;
10+
public int onlineUsersCount;
11+
public int banUsersCount;
12+
}
13+
}

src/NSmartProxy.Infrastructure/Shared/IDbOperator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ public interface IDbOperator : IDisposable
1818
long GetLength();
1919
void Close();
2020
bool Exist(string key);
21+
int GetCount();
2122
}
2223
}

src/NSmartProxy/Database/LiteDbOperator.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public void UpdateByName(string userName, string newUserName, string value)
8181
// keyCache.TryRemove(userName, out _);
8282
// liteCollection.Update(new KV(userName, value));
8383
//}
84+
public int GetCount()
85+
{
86+
return liteCollection.Count();
87+
}
8488

8589
public List<string> Select(int startIndex, int length)
8690
{

src/NSmartProxy/Database/NSmartDb.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ public bool Exist(string key)
160160
return hashf.Exist(String2Bytes(key));
161161
}
162162

163+
public int GetCount()
164+
{
165+
throw new NotImplementedException();
166+
}
167+
163168
public bool Exist(long key)
164169
{
165170
return hashf.Exist(BitConverter.GetBytes(key));

src/NSmartProxy/Extension/HttpServerStaticFiles/dashboard.js

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,20 @@
3636

3737

3838
function updatedServerStatus(data) {
39-
39+
4040
myChart2.data.datasets[0].data[0] = data.totalReceivedBytes;
4141
myChart2.data.datasets[0].data[1] = data.totalSentBytes;
4242
//myChart.data.datasets[0].data[2] = co;
4343
myChart2.update();
44-
myChart2.lab
44+
}
45+
46+
function updatedUserStatus(data) {
47+
48+
myChart3.data.datasets[0].data[0] = data.onlineUsersCount;
49+
myChart3.data.datasets[0].data[1] = data.offlineUsersCount;
50+
myChart3.data.datasets[0].data[2] = data.banUsersCount;
51+
//myChart.data.datasets[0].data[2] = co;
52+
myChart3.update();
4553
}
4654

4755
function getClientsInfo() {
@@ -58,12 +66,21 @@
5866
$.get(apiUrl,
5967
function (res) {
6068
var data = res.Data;
61-
//var serverStatus = $.parseJSON(data);
6269
updatedServerStatus(data);
6370
}
6471
);
6572
}
6673

74+
function getUserStatus() {
75+
var apiUrl = basepath + "GetUserStatus";
76+
$.get(apiUrl,
77+
function (res) {
78+
var data = res.Data;
79+
updatedUserStatus(data);
80+
}
81+
);
82+
}
83+
6784
//'use strict'
6885
// Graphs
6986
var ctx1 = document.getElementById('myChart');
@@ -97,6 +114,7 @@
97114
getLogFileTable(10);
98115
getClientsInfo();
99116
getServerStatus();
117+
getUserStatus();
100118

101119
var myChart2 = new Chart(ctx2,
102120
{
@@ -124,13 +142,13 @@
124142
{
125143
type: 'doughnut',
126144
data: {
127-
labels: ['活跃用户', '离线用户'/*, 'Yellow', 'Green', 'Purple', 'Orange'*/],
145+
labels: ['活跃用户', '离线用户', '黑名单用户'],
128146
datasets: [
129147
{
130148
label: '活跃用户',
131-
data: [12, 19],
149+
data: [0, 0],
132150
backgroundColor: [
133-
"rgb(255, 99, 132)", "rgb(54, 162, 235)", "rgb(255, 205, 86)"
151+
"rgb(75, 192, 192)", "rgb(255, 99, 132)", "rgb(201, 203, 207)"
134152
]
135153
}
136154
]
@@ -143,27 +161,13 @@
143161
}
144162

145163
});
146-
147-
//$("#myChart").click(
148-
// function (evt) {
149-
// var url = "连接管理";
150-
// //alert(url);
151-
// }
152-
//);
153-
154-
//$("#myChart2").click(
155-
// function (evt) {
156-
// var url = " ";
157-
// //alert(url);
158-
// }
159-
//);
160-
161-
//$("#myChart3").click(
162-
// function (evt) {
163-
// var url = "用户管理";
164-
// //alert(url);
165-
// }
166-
//);
164+
//red: 'rgb(255, 99, 132)',
165+
// orange: 'rgb(255, 159, 64)',
166+
// yellow: 'rgb(255, 205, 86)',
167+
// green: 'rgb(75, 192, 192)',
168+
// blue: 'rgb(54, 162, 235)',
169+
// purple: 'rgb(153, 102, 255)',
170+
// grey: 'rgb(201, 203, 207)'
167171
//定时更新数据
168172
if (window.intevalId) {
169173
window.clearInterval(window.intevalId);
@@ -173,16 +177,7 @@
173177
getClientsInfo();
174178
getServerStatus();
175179
getLogFileTable(10);
176-
//myChart2.data.datasets.pop();
177-
//更新数据
178-
//myChart2.data.datasets[0].data[1] += 3;
179-
//myChart2.data.datasets[1] = 10;
180-
//myChart2.data.datasets.push({
181-
//label: label,
182-
// backgroundColor: color,
183-
// data: [12, 19]
184-
//});
185-
//myChart2.update();
180+
getUserStatus();
186181
}, 5000
187182
);
188183
}());

src/NSmartProxy/Extension/HttpServer_APIs.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,25 @@ public ServerStatusDTO GetServerStatus()
3636
return dto;
3737
}
3838

39+
[Secure]
40+
[API]
41+
public UserStatusDTO GetUserStatus()
42+
{
43+
//Dbop.Close();
44+
int totalCount = Dbop.GetCount();
45+
var banCount = ServerContext.ServerConfig.BoundConfig.UsersBanlist.Count;
46+
var onlineCount = ServerContext.Clients.Count();
47+
var restCount = totalCount - banCount - onlineCount;
48+
49+
UserStatusDTO dto = new UserStatusDTO
50+
{
51+
onlineUsersCount = onlineCount,
52+
offlineUsersCount = restCount,
53+
banUsersCount = banCount
54+
};
55+
return dto;
56+
}
57+
3958
#endregion
4059

4160
#region log
@@ -686,31 +705,12 @@ public string GenerateCA(string hosts)
686705
return fileName;
687706
}
688707

689-
690-
//[FileUpload]
691-
//[Secure]
692-
//public string UploadCA(FileInfo fileInfo, int port)
693-
//{
694-
// string baseLogPath = "./ca";
695-
// string targetPath = baseLogPath + "/" + port + ".pfx";
696-
// DirectoryInfo dir = new DirectoryInfo(baseLogPath);
697-
// if (!dir.Exists)
698-
// {
699-
// dir.Create();
700-
// }
701-
702-
// File.Move(fileInfo.FullName, targetPath);
703-
704-
// return "success";
705-
//}
706-
707708
[FileUpload]
708709
[Secure]
709710
public string UploadTempFile(FileInfo fileInfo)
710711
{
711712
string baseLogPath = "./temp";
712713
string targetPath = baseLogPath + "/" + fileInfo.Name;
713-
///string targetPath = baseLogPath + "/" + port + ".pfx";
714714
DirectoryInfo dir = new DirectoryInfo(baseLogPath);
715715
if (!dir.Exists)
716716
{

src/NSmartProxy/Server.cs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -354,17 +354,6 @@ private async Task ProcessConsumeRequestAsync(int consumerPort, string clientApp
354354
}
355355
finally
356356
{
357-
//if (consumerClient.Client.Connected)
358-
//{
359-
// consumerClient.Client.LingerState = new LingerOption(false, 0);
360-
//}
361-
362-
//if (s2pClient.Client.Connected)
363-
//{
364-
// s2pClient.Client.LingerState = new LingerOption(false, 0);
365-
//}
366-
367-
368357
consumerClient.Close();
369358
s2pClient.Close();
370359
transfering.Cancel();
@@ -714,23 +703,21 @@ await fromStream.ReadAsync(buffer, 0, buffer.Length, ct).ConfigureAwait(false))
714703
{
715704
if (ioe is IOException) { return; } //Suppress this exception.
716705
throw;
717-
//Server.Logger.Info(ioe.Message);
718706
}
719-
720-
721707
}
722-
//Server.Logger.Debug($"{clientApp}对客户端传输关闭。");
723708
}
724709

725710
private void CloseClient(TcpClient client)
726711
{
727-
Logger.Debug("invalid request,Closing client:" + client.Client.RemoteEndPoint.ToString());
728-
client.Close();
729-
Logger.Debug("Closed client:" + client.Client.RemoteEndPoint.ToString());
712+
if (client.Connected)
713+
{
714+
Logger.Debug("invalid request,Closing client:" + client.Client.RemoteEndPoint.ToString());
715+
client.Close();
716+
Logger.Debug("Closed client:" + client.Client.RemoteEndPoint.ToString());
717+
}
730718
}
731719

732720

733-
734721
#endregion
735722

736723
#region http

0 commit comments

Comments
 (0)