Skip to content

Commit

Permalink
add a new dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
tmoonlight committed Oct 3, 2019
1 parent 4a830f9 commit 75c46da
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 75 deletions.
13 changes: 13 additions & 0 deletions src/NSmartProxy.Data/DTOs/UserStatusDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NSmartProxy.Data.DTOs
{
public class UserStatusDTO
{
public int offlineUsersCount;
public int onlineUsersCount;
public int banUsersCount;
}
}
1 change: 1 addition & 0 deletions src/NSmartProxy.Infrastructure/Shared/IDbOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ public interface IDbOperator : IDisposable
long GetLength();
void Close();
bool Exist(string key);
int GetCount();
}
}
4 changes: 4 additions & 0 deletions src/NSmartProxy/Database/LiteDbOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public void UpdateByName(string userName, string newUserName, string value)
// keyCache.TryRemove(userName, out _);
// liteCollection.Update(new KV(userName, value));
//}
public int GetCount()
{
return liteCollection.Count();
}

public List<string> Select(int startIndex, int length)
{
Expand Down
5 changes: 5 additions & 0 deletions src/NSmartProxy/Database/NSmartDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ public bool Exist(string key)
return hashf.Exist(String2Bytes(key));
}

public int GetCount()
{
throw new NotImplementedException();
}

public bool Exist(long key)
{
return hashf.Exist(BitConverter.GetBytes(key));
Expand Down
69 changes: 32 additions & 37 deletions src/NSmartProxy/Extension/HttpServerStaticFiles/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,20 @@


function updatedServerStatus(data) {

myChart2.data.datasets[0].data[0] = data.totalReceivedBytes;
myChart2.data.datasets[0].data[1] = data.totalSentBytes;
//myChart.data.datasets[0].data[2] = co;
myChart2.update();
myChart2.lab
}

function updatedUserStatus(data) {

myChart3.data.datasets[0].data[0] = data.onlineUsersCount;
myChart3.data.datasets[0].data[1] = data.offlineUsersCount;
myChart3.data.datasets[0].data[2] = data.banUsersCount;
//myChart.data.datasets[0].data[2] = co;
myChart3.update();
}

function getClientsInfo() {
Expand All @@ -58,12 +66,21 @@
$.get(apiUrl,
function (res) {
var data = res.Data;
//var serverStatus = $.parseJSON(data);
updatedServerStatus(data);
}
);
}

function getUserStatus() {
var apiUrl = basepath + "GetUserStatus";
$.get(apiUrl,
function (res) {
var data = res.Data;
updatedUserStatus(data);
}
);
}

//'use strict'
// Graphs
var ctx1 = document.getElementById('myChart');
Expand Down Expand Up @@ -97,6 +114,7 @@
getLogFileTable(10);
getClientsInfo();
getServerStatus();
getUserStatus();

var myChart2 = new Chart(ctx2,
{
Expand Down Expand Up @@ -124,13 +142,13 @@
{
type: 'doughnut',
data: {
labels: ['活跃用户', '离线用户'/*, 'Yellow', 'Green', 'Purple', 'Orange'*/],
labels: ['活跃用户', '离线用户', '黑名单用户'],
datasets: [
{
label: '活跃用户',
data: [12, 19],
data: [0, 0],
backgroundColor: [
"rgb(255, 99, 132)", "rgb(54, 162, 235)", "rgb(255, 205, 86)"
"rgb(75, 192, 192)", "rgb(255, 99, 132)", "rgb(201, 203, 207)"
]
}
]
Expand All @@ -143,27 +161,13 @@
}

});

//$("#myChart").click(
// function (evt) {
// var url = "连接管理";
// //alert(url);
// }
//);

//$("#myChart2").click(
// function (evt) {
// var url = " ";
// //alert(url);
// }
//);

//$("#myChart3").click(
// function (evt) {
// var url = "用户管理";
// //alert(url);
// }
//);
//red: 'rgb(255, 99, 132)',
// orange: 'rgb(255, 159, 64)',
// yellow: 'rgb(255, 205, 86)',
// green: 'rgb(75, 192, 192)',
// blue: 'rgb(54, 162, 235)',
// purple: 'rgb(153, 102, 255)',
// grey: 'rgb(201, 203, 207)'
//定时更新数据
if (window.intevalId) {
window.clearInterval(window.intevalId);
Expand All @@ -173,16 +177,7 @@
getClientsInfo();
getServerStatus();
getLogFileTable(10);
//myChart2.data.datasets.pop();
//更新数据
//myChart2.data.datasets[0].data[1] += 3;
//myChart2.data.datasets[1] = 10;
//myChart2.data.datasets.push({
//label: label,
// backgroundColor: color,
// data: [12, 19]
//});
//myChart2.update();
getUserStatus();
}, 5000
);
}());
Expand Down
38 changes: 19 additions & 19 deletions src/NSmartProxy/Extension/HttpServer_APIs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ public ServerStatusDTO GetServerStatus()
return dto;
}

[Secure]
[API]
public UserStatusDTO GetUserStatus()
{
//Dbop.Close();
int totalCount = Dbop.GetCount();
var banCount = ServerContext.ServerConfig.BoundConfig.UsersBanlist.Count;
var onlineCount = ServerContext.Clients.Count();
var restCount = totalCount - banCount - onlineCount;

UserStatusDTO dto = new UserStatusDTO
{
onlineUsersCount = onlineCount,
offlineUsersCount = restCount,
banUsersCount = banCount
};
return dto;
}

#endregion

#region log
Expand Down Expand Up @@ -686,31 +705,12 @@ public string GenerateCA(string hosts)
return fileName;
}


//[FileUpload]
//[Secure]
//public string UploadCA(FileInfo fileInfo, int port)
//{
// string baseLogPath = "./ca";
// string targetPath = baseLogPath + "/" + port + ".pfx";
// DirectoryInfo dir = new DirectoryInfo(baseLogPath);
// if (!dir.Exists)
// {
// dir.Create();
// }

// File.Move(fileInfo.FullName, targetPath);

// return "success";
//}

[FileUpload]
[Secure]
public string UploadTempFile(FileInfo fileInfo)
{
string baseLogPath = "./temp";
string targetPath = baseLogPath + "/" + fileInfo.Name;
///string targetPath = baseLogPath + "/" + port + ".pfx";
DirectoryInfo dir = new DirectoryInfo(baseLogPath);
if (!dir.Exists)
{
Expand Down
25 changes: 6 additions & 19 deletions src/NSmartProxy/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,17 +354,6 @@ private async Task ProcessConsumeRequestAsync(int consumerPort, string clientApp
}
finally
{
//if (consumerClient.Client.Connected)
//{
// consumerClient.Client.LingerState = new LingerOption(false, 0);
//}

//if (s2pClient.Client.Connected)
//{
// s2pClient.Client.LingerState = new LingerOption(false, 0);
//}


consumerClient.Close();
s2pClient.Close();
transfering.Cancel();
Expand Down Expand Up @@ -714,23 +703,21 @@ await fromStream.ReadAsync(buffer, 0, buffer.Length, ct).ConfigureAwait(false))
{
if (ioe is IOException) { return; } //Suppress this exception.
throw;
//Server.Logger.Info(ioe.Message);
}


}
//Server.Logger.Debug($"{clientApp}对客户端传输关闭。");
}

private void CloseClient(TcpClient client)
{
Logger.Debug("invalid request,Closing client:" + client.Client.RemoteEndPoint.ToString());
client.Close();
Logger.Debug("Closed client:" + client.Client.RemoteEndPoint.ToString());
if (client.Connected)
{
Logger.Debug("invalid request,Closing client:" + client.Client.RemoteEndPoint.ToString());
client.Close();
Logger.Debug("Closed client:" + client.Client.RemoteEndPoint.ToString());
}
}



#endregion

#region http
Expand Down

0 comments on commit 75c46da

Please sign in to comment.