diff --git a/class/core/system_api.py b/class/core/system_api.py
index dd96814fc..c1779b2cf 100755
--- a/class/core/system_api.py
+++ b/class/core/system_api.py
@@ -547,30 +547,30 @@ class system_api:
def getNetWork(self):
# 取网络流量信息
try:
- # 取网络流量信息
- networkIo = self.psutilNetIoCounters()
- if not "otime" in session:
- session['up'] = networkIo[0]
- session['down'] = networkIo[1]
- session['otime'] = time.time()
-
- ntime = time.time()
-
- # print("source",ntime - session['otime'])
networkInfo = {}
- networkInfo['upTotal'] = networkIo[0]
- networkInfo['downTotal'] = networkIo[1]
- networkInfo['up'] = round(float(
- networkIo[0] - session['up']) / (ntime - session['otime']), 2)
- networkInfo['down'] = round(
- float(networkIo[1] - session['down']) / (ntime - session['otime']), 2)
- networkInfo['downPackets'] = networkIo[3]
- networkInfo['upPackets'] = networkIo[2]
+ # 取网络流量信息
+ # networkIo = self.psutilNetIoCounters()
+ # if not "otime" in session:
+ # session['up'] = networkIo[0]
+ # session['down'] = networkIo[1]
+ # session['otime'] = time.time()
- # print networkIo[1], session['down'], ntime, session['otime']
- session['up'] = networkIo[0]
- session['down'] = networkIo[1]
- session['otime'] = time.time()
+ # ntime = time.time()
+ # print("source",ntime - session['otime'])
+
+ # networkInfo['upTotal'] = networkIo[0]
+ # networkInfo['downTotal'] = networkIo[1]
+ # networkInfo['up'] = round(float(
+ # networkIo[0] - session['up']) / (ntime - session['otime']), 2)
+ # networkInfo['down'] = round(
+ # float(networkIo[1] - session['down']) / (ntime - session['otime']), 2)
+ # networkInfo['downPackets'] = networkIo[3]
+ # networkInfo['upPackets'] = networkIo[2]
+
+ # # print networkIo[1], session['down'], ntime, session['otime']
+ # session['up'] = networkIo[0]
+ # session['down'] = networkIo[1]
+ # session['otime'] = time.time()
networkInfo['cpu'] = self.getCpuInfo()
networkInfo['load'] = self.getLoadAverage()
diff --git a/route/static/app/index.js b/route/static/app/index.js
index 8ef4a3b8e..bf48004b7 100755
--- a/route/static/app/index.js
+++ b/route/static/app/index.js
@@ -1,35 +1,3 @@
-$(function() {
- $(".mem-release").hover(function() {
- $(this).addClass("shine_green");
- if (!($(this).hasClass("mem-action"))) {
- $(this).find(".mem-re-min").hide();
- $(this).find(".mask").css({ "color": "#d2edd8" });
- $(this).find(".mem-re-con").css({ "display": "block" });
- $(this).find(".mem-re-con").animate({ "top": "0", opacity: 1 });
- $("#memory").text('内存释放');
- }
- }, function() {
- $(this).removeClass("shine_green");
- $(this).find(".mask").css({ "color": "#20a53a" });
- $(this).find(".mem-re-con").css({ "top": "15px", opacity: 1, "display": "none" });
- $("#memory").text(getCookie("mem-before"));
- $(this).find(".mem-re-min").hide();
- }).click(function() {
- $(this).find(".mem-re-min").hide();
- if (!($(this).hasClass("mem-action"))) {
- reMemory();
- var btlen = $(".mem-release").find(".mask span").text();
- $(this).addClass("mem-action");
- $(this).find(".mask").css({ "color": "#20a53a" });
- $(this).find(".mem-re-con").animate({ "top": "-400px", opacity: 0 });
- $(this).find(".pie_right .right").css({ "transform": "rotate(3deg)" });
- for (var i = 0; i < btlen; i++) {
- setTimeout("rocket(" + btlen + "," + i + ")", i * 30);
- }
- }
- });
-});
-
//获取负载
function getLoad(data) {
$("#LoadList .mask").html("获取中..");
@@ -64,7 +32,7 @@ function getLoad(data) {
}
$('#LoadList .circle').click(function() {
- getNet();
+ // getNet();
});
$('#LoadList .mask').hover(function() {
@@ -81,8 +49,7 @@ $('#LoadList .mask').hover(function() {
function showCpuTips(rdata){
- $('#cpuChart .mask').unbind();
- $('#cpuChart .mask').hover(function() {
+ $('#cpuChart .mask').unbind().hover(function() {
var cpuText = '';
if (rdata.cpu[2].length == 1){
var cpuUse = parseFloat(rdata.cpu[2][0] == 0 ? 0 : rdata.cpu[2][0]).toFixed(1);
@@ -284,6 +251,8 @@ function getNet() {
var up, down;
$.get("/system/network", function(net) {
+ console.log(net);
+
$("#InterfaceSpeed").html(lan.index.interfacespeed + ": 1.0Gbps");
$("#upSpeed").html(toSize(net.up));
$("#downSpeed").html(toSize(net.down));
@@ -310,9 +279,9 @@ function getNet() {
},'json');
}
-//网络Io
+//网络IO
function netImg() {
- var echartsNetImg = echarts.init(document.getElementById('netImg'));
+
var xData = [];
var yData = [];
var zData = [];
@@ -359,7 +328,7 @@ function netImg() {
var downNetTmp = toSize(getCookie("downNet"));
var upNetTmpSize = upNetTmp.split(' ')[0];
- var downNetTmp = downNetTmp.split(' ')[0]
+ var downNetTmp = downNetTmp.split(' ')[0];
yData.push(upNetTmpSize);
zData.push(downNetTmp);
@@ -378,12 +347,12 @@ function netImg() {
// 指定图表的配置项和数据
var option = {
title: {
- text: lan.index.interface_net,
+ text: "接口流量实时",
left: 'center',
textStyle: {
color: '#888888',
fontStyle: 'normal',
- fontFamily: lan.index.net_font,
+ fontFamily: "宋体",
fontSize: 16,
}
},
@@ -474,6 +443,8 @@ function netImg() {
}
}]
};
+
+ var echartsNetImg = echarts.init(document.getElementById('netImg'));
setInterval(function() {
getNet();
addData(true);
@@ -516,8 +487,7 @@ function setImg() {
};
});
- $('.diskbox .mask').unbind();
- $('.diskbox .mask').hover(function() {
+ $('.diskbox .mask').unbind().hover(function() {
layer.closeAll('tips');
var that = this;
var conterError = $(this).attr("data");
@@ -638,7 +608,10 @@ function reBoot() {
area: '330px',
closeBtn: 1,
shadeClose: false,
- content: '
'
+ content: ''
});
$('.rebt-con a').click(function () {
@@ -779,17 +752,18 @@ function showDanger(num, port) {
closeBtn: 1,
shift: 5,
content: '\
-
\
- | 风险类型: | 暴力破解 说明 |
\
- | 累计遭遇攻击总数: | ' + num + ' 详细(数据直接来源本服务器日志) |
\
- | 风险等级: | 较高风险 |
\
- | 风险描述: | ' + atxt + ' |
\
- | 可参考解决方案: | 方案一:修改SSH默认端口,修改SSH验证方式为数字证书,清除近期登陆日志。 方案二:购买宝塔企业运维版,一键部署安全隔离服务,高效且方便。 |
\
-
\
-
\
-
'
+ \
+ \
+ | 风险类型: | 暴力破解 说明 |
\
+ | 累计遭遇攻击总数: | ' + num + ' 详细(数据直接来源本服务器日志) |
\
+ | 风险等级: | 较高风险 |
\
+ | 风险描述: | ' + atxt + ' |
\
+ | 可参考解决方案: | 方案一:修改SSH默认端口,修改SSH验证方式为数字证书,清除近期登陆日志。 方案二:购买宝塔企业运维版,一键部署安全隔离服务,高效且方便。 |
\
+ \
+
\
+ '
});
- $(".showDanger td").css("padding", "8px")
+ $(".showDanger td").css("padding", "8px");
}
function pluginInit(){
@@ -913,3 +887,543 @@ function loadKeyDataCount(){
call(pname);
}
}
+
+$(function() {
+ $(".mem-release").hover(function() {
+ $(this).addClass("shine_green");
+ if (!($(this).hasClass("mem-action"))) {
+ $(this).find(".mem-re-min").hide();
+ $(this).find(".mask").css({ "color": "#d2edd8" });
+ $(this).find(".mem-re-con").css({ "display": "block" });
+ $(this).find(".mem-re-con").animate({ "top": "0", opacity: 1 });
+ $("#memory").text('内存释放');
+ }
+ }, function() {
+ $(this).removeClass("shine_green");
+ $(this).find(".mask").css({ "color": "#20a53a" });
+ $(this).find(".mem-re-con").css({ "top": "15px", opacity: 1, "display": "none" });
+ $("#memory").text(getCookie("mem-before"));
+ $(this).find(".mem-re-min").hide();
+ }).click(function() {
+ $(this).find(".mem-re-min").hide();
+ if (!($(this).hasClass("mem-action"))) {
+ reMemory();
+ var btlen = $(".mem-release").find(".mask span").text();
+ $(this).addClass("mem-action");
+ $(this).find(".mask").css({ "color": "#20a53a" });
+ $(this).find(".mem-re-con").animate({ "top": "-400px", opacity: 0 });
+ $(this).find(".pie_right .right").css({ "transform": "rotate(3deg)" });
+ for (var i = 0; i < btlen; i++) {
+ setTimeout("rocket(" + btlen + "," + i + ")", i * 30);
+ }
+ }
+ });
+
+ $("select[name='network-io'],select[name='disk-io']").change(function () {
+ var key = $(this).val(), type = $(this).attr('name');
+ if (type == 'network-io') {
+ if (key == 'ALL') {
+ key = '';
+ }
+ setCookie('network_io_key', key);
+ } else {
+ if (key == 'ALL') {
+ key = '';
+ }
+ setCookie('disk_io_key', key);
+ }
+ });
+
+ $('.tabs-nav span').click(function () {
+ var indexs = $(this).index();
+ $(this).addClass('active').siblings().removeClass('active');
+ $('.tabs-content .tabs-item:eq(' + indexs + ')').addClass('tabs-active').siblings().removeClass('tabs-active');
+ $('.tabs-down select:eq(' + indexs + ')').removeClass('hide').siblings().addClass('hide');
+ console.log(indexs);
+ switch (indexs) {
+ case 0:
+ index.net.table.resize();
+ break;
+ case 1:
+ index.iostat.table.resize();
+ break;
+ }
+ })
+});
+
+var index = {
+ common:{
+ ts:function (m) { return m < 10 ? '0' + m : m },
+ format:function (sjc) {
+ var time = new Date(sjc);
+ var h = time.getHours();
+ var mm = time.getMinutes();
+ var s = time.getSeconds();
+ return h+ ':' + mm + ':' +s;
+ },
+ getTime:function () {
+ var now = new Date();
+ var hour = now.getHours();
+ var minute = now.getMinutes();
+ var second = now.getSeconds();
+ if (minute < 10) {
+ minute = "0" + minute;
+ }
+ if (second < 10) {
+ second = "0" + second;
+ }
+ var nowdate = hour + ":" + minute + ":" + second;
+ return nowdate;
+ },
+ },
+ net: {
+ table: null,
+ data: {
+ xData: [],
+ yData: [],
+ zData: []
+ },
+ default_unit : 'KB/s',
+ init_select : false,
+ init: function(){
+ for (var i = 8; i >= 0; i--) {
+ var time = (new Date()).getTime();
+ index.net.data.xData.push(index.common.format(time - (i * 3 * 1000)));
+ index.net.data.yData.push(0);
+ index.net.data.zData.push(0);
+ }
+
+ index.net.table = echarts.init(document.getElementById('netImg'));
+ var option = index.net.defaultOption();
+ index.net.table.setOption(option);
+
+ window.addEventListener("resize", function () {
+ index.net.table.resize();
+ });
+ },
+ render:function(){
+ index.net.table.setOption({
+ yAxis: {
+ name: '单位 '+ index.net.default_unit,
+ splitLine: { lineStyle: { color: "#eee" } },
+ axisLine: { lineStyle: { color: "#666" } }
+ },
+ xAxis: {
+ data: index.net.data.xData
+ },
+ series: [{
+ name: lan.index.net_up,
+ data: index.net.data.yData
+ }, {
+ name: lan.index.net_down,
+ data: index.net.data.zData
+ }]
+ });
+ },
+ defaultOption:function(){
+ var option = {
+ title: {
+ text: "",
+ left: 'center',
+ textStyle: {
+ color: '#888888',
+ fontStyle: 'normal',
+ fontFamily: "宋体",
+ fontSize: 16,
+ }
+ },
+ tooltip: {
+ trigger: 'axis'
+ },
+ legend: {
+ data: [lan.index.net_up, lan.index.net_down],
+ bottom: '2%'
+ },
+ xAxis: {
+ type: 'category',
+ boundaryGap: false,
+ data: index.net.data.xData,
+ axisLine: {
+ lineStyle: {
+ color: "#666"
+ }
+ }
+ },
+ yAxis: {
+ name: '单位 '+ index.net.default_unit,
+ splitLine: {
+ lineStyle: { color: "#eee" }
+ },
+ axisLine: {
+ lineStyle: { color: "#666" }
+ }
+ },
+ series: [{
+ name: '上行',
+ type: 'line',
+ data: index.net.data.yData,
+ smooth: true,
+ showSymbol: false,
+ symbol: 'circle',
+ symbolSize: 6,
+ areaStyle: {
+ normal: {
+ color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
+ offset: 0,
+ color: 'rgba(255, 140, 0,0.5)'
+ }, {
+ offset: 1,
+ color: 'rgba(255, 140, 0,0.8)'
+ }], false)
+ }
+ },
+ itemStyle: {
+ normal: {
+ color: '#f7b851'
+ }
+ },
+ lineStyle: {
+ normal: {
+ width: 1
+ }
+ }
+ },
+ {
+ name: '下行',
+ type: 'line',
+ data: index.net.data.zData,
+ smooth: true,
+ showSymbol: false,
+ symbol: 'circle',
+ symbolSize: 6,
+ areaStyle: {
+ normal: {
+ color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
+ offset: 0,
+ color: 'rgba(30, 144, 255,0.5)',
+ }, {
+ offset: 1,
+ color: 'rgba(30, 144, 255,0.8)',
+ }], false)
+ }
+ },
+ itemStyle: {
+ normal: {
+ color: '#52a9ff',
+ }
+ },
+ lineStyle: {
+ normal: {
+ width: 1,
+ }
+ }
+ }]
+ };
+ return option;
+ },
+
+
+ add: function (up, down) {
+ var _net = this;
+ var limit = 8;
+ var d = new Date()
+ if (_net.data.xData.length >= limit) _net.data.xData.splice(0, 1);
+ if (_net.data.yData.length >= limit) _net.data.yData.splice(0, 1);
+ if (_net.data.zData.length >= limit) _net.data.zData.splice(0, 1);
+
+
+ var upTmpSize = toSize(up).split(' ')[0];
+ var downTmpSize = toSize(down).split(' ')[0];
+
+ var tmp = up;
+ if (down>up){
+ tmp = down;
+ }
+ index.net.default_unit = toSize(tmp).split(' ')[1] + '/s';
+
+ _net.data.zData.push(downTmpSize);
+ _net.data.yData.push(upTmpSize);
+ _net.data.xData.push(d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds());
+ },
+ renderSelect:function(net){
+ // console.log(net);
+ if (!index.net.init_select){
+ var option = '';
+ var network = net.network;
+ var network_io_key = getCookie('network_io_key');
+
+ for (var name in network) {
+ if (name == 'ALL'){
+ option += '';
+ } else if (network_io_key == name){
+ option += '';
+ } else {
+ option += '';
+ }
+ }
+ $('select[name="network-io"]').html(option);
+ index.net.init_select = true;
+ }
+ }
+ },
+
+ iostat:{
+ table: null,
+ data: {
+ xData: [],
+ yData: [],
+ zData: []
+ },
+ init_select:false,
+ init:function(){
+ for (var i = 8; i >= 0; i--) {
+ var time = (new Date()).getTime();
+ index.iostat.data.xData.push(index.common.format(time - (i * 3 * 1000)));
+ index.iostat.data.yData.push(0);
+ index.iostat.data.zData.push(0);
+ }
+
+ index.iostat.table = echarts.init(document.getElementById('ioStat'));
+ var option = index.iostat.defaultOption();
+ index.iostat.table.setOption(option);
+
+ window.addEventListener("resize", function () {
+ index.iostat.table.resize();
+ });
+ },
+
+ render:function(){
+ index.iostat.table.setOption({
+ yAxis: {
+ name: '单位 '+ index.iostat.default_unit,
+ splitLine: { lineStyle: { color: "#eee" } },
+ axisLine: { lineStyle: { color: "#666" } }
+ },
+ xAxis: {
+ data: index.iostat.data.xData
+ },
+ series: [{
+ name: "读取",
+ data: index.iostat.data.yData
+ }, {
+ name: "写入",
+ data: index.iostat.data.zData
+ }]
+ });
+ },
+ defaultOption:function(){
+ var option = {
+ title: {
+ text: "",
+ left: 'center',
+ textStyle: {
+ color: '#888888',
+ fontStyle: 'normal',
+ fontFamily: "宋体",
+ fontSize: 16,
+ }
+ },
+ tooltip: {
+ trigger: 'axis'
+ },
+ legend: {
+ data: ["读取", "写入"],
+ bottom: '2%'
+ },
+ xAxis: {
+ type: 'category',
+ boundaryGap: false,
+ data: index.iostat.data.xData,
+ axisLine: {
+ lineStyle: {
+ color: "#666"
+ }
+ }
+ },
+ yAxis: {
+ name: '单位 '+ index.iostat.default_unit,
+ splitLine: {
+ lineStyle: { color: "#eee" }
+ },
+ axisLine: {
+ lineStyle: { color: "#666" }
+ }
+ },
+ series: [{
+ name: '读取',
+ type: 'line',
+ data: index.iostat.data.yData,
+ smooth: true,
+ showSymbol: false,
+ symbol: 'circle',
+ symbolSize: 6,
+ areaStyle: {
+ normal: {
+ color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
+ offset: 0,
+ color: 'rgba(255, 140, 0,0.5)'
+ }, {
+ offset: 1,
+ color: 'rgba(255, 140, 0,0.8)'
+ }], false)
+ }
+ },
+ itemStyle: {
+ normal: {
+ color: '#f7b851'
+ }
+ },
+ lineStyle: {
+ normal: {
+ width: 1
+ }
+ }
+ },
+ {
+ name: '写入',
+ type: 'line',
+ data: index.iostat.data.zData,
+ smooth: true,
+ showSymbol: false,
+ symbol: 'circle',
+ symbolSize: 6,
+ areaStyle: {
+ normal: {
+ color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
+ offset: 0,
+ color: 'rgba(30, 144, 255,0.5)',
+ }, {
+ offset: 1,
+ color: 'rgba(30, 144, 255,0.8)',
+ }], false)
+ }
+ },
+ itemStyle: {
+ normal: {
+ color: '#52a9ff',
+ }
+ },
+ lineStyle: {
+ normal: {
+ width: 1,
+ }
+ }
+ }]
+ };
+ return option;
+ },
+
+ renderSelect:function(data){
+ if (!index.iostat.init_select){
+ var option = '';
+ var iostat = data.iostat;
+ var disk_io_key = getCookie('disk_io_key');
+
+ for (var name in iostat) {
+ if (name == 'ALL'){
+ option += '';
+ } else if (disk_io_key == name){
+ option += '';
+ } else {
+ option += '';
+ }
+ }
+ $('select[name="disk-io"]').html(option);
+ index.iostat.init_select = true;
+ }
+ },
+ add: function (up, down) {
+ var _iostat = this;
+ var limit = 8;
+ var d = new Date()
+ if (_iostat.data.xData.length >= limit) _iostat.data.xData.splice(0, 1);
+ if (_iostat.data.yData.length >= limit) _iostat.data.yData.splice(0, 1);
+ if (_iostat.data.zData.length >= limit) _iostat.data.zData.splice(0, 1);
+
+
+ var upTmpSize = toSize(up).split(' ')[0];
+ var downTmpSize = toSize(down).split(' ')[0];
+
+ var tmp = up;
+ if (down>up){
+ tmp = down;
+ }
+ index.iostat.default_unit = toSize(tmp).split(' ')[1] + '/s';
+
+ _iostat.data.zData.push(downTmpSize);
+ _iostat.data.yData.push(upTmpSize);
+ _iostat.data.xData.push(d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds());
+ },
+
+ },
+ getData:function(){
+
+ $.get("/system/network", function(net) {
+
+ //网络IO
+ var network_io_key = getCookie('network_io_key');
+ var network_data = net.network;
+ var network_select = network_data['ALL'];
+ if (network_io_key != ''){
+ network_select = network_data[network_io_key];
+ }
+
+
+ index.net.add(network_select.up,network_select.down);
+ index.net.render();
+ index.net.renderSelect(net);
+
+
+ $("#upSpeed").html(toSize(network_select.up));
+ $("#downSpeed").html(toSize(network_select.down));
+
+ $("#downAll").html(toSize(network_select.downTotal));
+ $("#downAll").attr('title','数据包:' + network_select.downPackets)
+ $("#upAll").html(toSize(network_select.upTotal));
+ $("#upAll").attr('title','数据包:' + network_select.upPackets)
+
+
+ //磁盘IO
+ var disk_io_key = getCookie('disk_io_key');
+ var iostat_data = net.iostat;
+ var iostat_select = iostat_data['ALL'];
+ if (disk_io_key != ''){
+ iostat_select = iostat_data[disk_io_key];
+ }
+
+ index.iostat.add(iostat_select.read_bytes,iostat_select.write_bytes);
+ index.iostat.render();
+ index.iostat.renderSelect(net);
+
+ $("#readBytes").html(toSize(iostat_select.read_bytes));
+ $("#writeBytes").html(toSize(iostat_select.write_bytes));
+ $("#diskIops").html(iostat_select.read_count);
+ $("#diskTime").html(iostat_select.write_time);
+
+
+ $("#core").html(net.cpu[1] + " " + lan.index.cpu_core);
+ $("#state").html(net.cpu[0]);
+
+ setcolor(net.cpu[0], "#state", 30, 70, 90);
+ //负载
+ getLoad(net.load);
+ //内存
+ setMemImg(net.mem);
+ //绑定hover事件
+ setImg();
+ showCpuTips(net);
+
+ },'json');
+ },
+ task:function(){
+ index.getData();
+ setInterval(function() {
+ index.getData();
+ }, 3000);
+ },
+ init: function(){
+ index.net.init();
+ index.iostat.init();
+ index.task();
+ }
+}
diff --git a/route/templates/default/index.html b/route/templates/default/index.html
index a2c233e85..92574f0fd 100755
--- a/route/templates/default/index.html
+++ b/route/templates/default/index.html
@@ -99,15 +99,45 @@
-
-
流量
-
-
-
-
-
+
+
+
+ 流量
+ 磁盘IO
+
+
+
+
+
+
-
+
+
+
@@ -119,8 +149,8 @@