增加数据统计

master
fengfei 7 years ago
parent f962187498
commit 7db0805b23
  1. 22
      proxy-server/src/main/java/org/fengfei/lanproxy/server/config/ProxyConfig.java
  2. 9
      proxy-server/webpages/lanproxy-config/html/lan/add.html
  3. 9
      proxy-server/webpages/lanproxy-config/html/lan/edit.html
  4. 46
      proxy-server/webpages/lanproxy-config/html/statistics/list.html
  5. 21
      proxy-server/webpages/lanproxy-config/index.html

@ -158,8 +158,8 @@ public class ProxyConfig implements Serializable {
*/
public void update(String proxyMappingConfigJson) {
File file = new File(CONFIG_FILE);
try {
File file = new File(CONFIG_FILE);
if (proxyMappingConfigJson == null && file.exists()) {
InputStream in = new FileInputStream(file);
byte[] buf = new byte[1024];
@ -171,11 +171,6 @@ public class ProxyConfig implements Serializable {
in.close();
proxyMappingConfigJson = new String(out.toByteArray());
} else if (proxyMappingConfigJson != null) {
FileOutputStream out = new FileOutputStream(file);
out.write(proxyMappingConfigJson.getBytes());
out.flush();
out.close();
}
} catch (Exception e) {
throw new RuntimeException(e);
@ -192,8 +187,10 @@ public class ProxyConfig implements Serializable {
// 构造端口映射关系
for (Client client : clients) {
String clientKey = client.getClientKey();
if (clientInetPortMapping.containsKey(clientKey)) {
throw new IllegalArgumentException("密钥同时作为客户端标识,不能重复: " + clientKey);
}
List<ClientProxyMapping> mappings = client.getProxyMappings();
List<Integer> ports = new ArrayList<Integer>();
clientInetPortMapping.put(clientKey, ports);
@ -201,7 +198,7 @@ public class ProxyConfig implements Serializable {
Integer port = mapping.getInetPort();
ports.add(port);
if (inetPortLanInfoMapping.containsKey(port)) {
throw new IllegalArgumentException("duplicate inet port " + port);
throw new IllegalArgumentException("一个公网端口只能映射一个后端信息,不能重复: " + port);
}
inetPortLanInfoMapping.put(port, mapping.getLan());
@ -213,6 +210,15 @@ public class ProxyConfig implements Serializable {
this.inetPortLanInfoMapping = inetPortLanInfoMapping;
this.clients = clients;
try {
FileOutputStream out = new FileOutputStream(file);
out.write(proxyMappingConfigJson.getBytes());
out.flush();
out.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
notifyconfigChangedListeners();
}

@ -41,11 +41,20 @@ $(".add").click(function(){
layer.alert("请输入公网出口端口");
return;
}
if(!check_port(inetPort)){
layer.alert("端口格式错误");
return;
}
var lan = $("input[name='lan']").val();
if(lan == ""){
layer.alert("请输入后端代理信息");
return;
}
if(!check_lan(lan)){
layer.alert("后端代理信息格式错误");
return;
}
clientList[clientIndex].proxyMappings.push({
name:name,

@ -46,11 +46,20 @@ $(".update").click(function(){
layer.alert("请输入公网出口端口");
return;
}
if(!check_port(inetPort)){
layer.alert("端口格式错误");
return;
}
var lan = $("input[name='lan']").val();
if(lan == ""){
layer.alert("请输入后端代理信息");
return;
}
if(!check_lan(lan)){
layer.alert("后端代理信息格式错误");
return;
}
clientList[clientIndex].proxyMappings[mappingIndex]= {
name:name,

@ -0,0 +1,46 @@
<div class="layui-tab layui-tab-brief">
<ul class="layui-tab-title site-demo-title">
<li class="layui-this tab-title">数据统计</li>
</ul>
<div class="main-content"></div>
</div>
<script>
function bytesToSize(bytes) {
if (bytes === 0)
return '0 B';
var k = 1000, // or 1024
sizes = [ 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' ], i = Math
.floor(Math.log(bytes) / Math.log(k));
return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
}
api_invoke("/metrics/get", {}, function(data) {
var html = template($("#stat-tpl").html(), {
data : data.data
});
$(".main-content").html(html);
});
</script>
<script id="stat-tpl" type="text/html">
<table class="layui-table" lay-skin="line">
<thead>
<tr>
<th>出口端口</th>
<th>流入数据</th>
<th>流出数据</th>
<th>当前连接数</th>
</tr>
</thead>
<tbody>
<%for(var i = 0; i < data.length; i++) {%>
<tr>
<td><%:=data[i].port%></td>
<td><%:=bytesToSize(data[i].readBytes)%></td>
<td><%:=bytesToSize(data[i].wroteBytes)%></td>
<td><%:=data[i].channels%></td>
</tr>
<%}%>
</tbody>
</table>
</script>

@ -69,6 +69,9 @@
location.href="/";
}else{
layer.alert(XMLHttpRequest.responseJSON.message);
api_invoke("/config/detail", {}, function(data) {
clientList = data.data;
});
}
}
});
@ -77,6 +80,21 @@
function load_page(pageUrl) {
$(".layui-body").load(pageUrl);
}
function check_lan(ip)
{
var re = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]):([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])$/
return re.test(ip);
}
function check_port(port)
{
if (port>65535) {
return false;
}
var re = /^[1-9]+[0-9]*]*$/
return re.test(port);
}
$(function() {
if (window.history && window.history.pushState) {
@ -147,6 +165,9 @@
<%}%>
</dl>
</li>
<li class="layui-nav-item layui-nav-itemed"><a class=""
href="javascript:load_page('html/statistics/list.html');">数据统计</a>
</li>
</ul>
</script>
</body>

Loading…
Cancel
Save