From b501d62d918496eb3ee015d33591da63580a4597 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 9 May 2024 01:03:41 +0800 Subject: [PATCH 01/15] Update mongodb.js --- plugins/mongodb/js/mongodb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mongodb/js/mongodb.js b/plugins/mongodb/js/mongodb.js index bfbcca450..c0a13318f 100644 --- a/plugins/mongodb/js/mongodb.js +++ b/plugins/mongodb/js/mongodb.js @@ -154,7 +154,7 @@ function mongoReplStatus() { } else{ tbody += '状态' + rdata.status + '主/从\ 同步文档' + rdata.setName + '文档名\ - hosts' + rdata.hosts + '服务器所有节点\ + hosts' + rdata.hosts + '服务器所有节点\ primary' + rdata.primary + '主节点\ me' + rdata.me + '本机'; } From a9ce4f2e23e8a3a50eced164088eb029a90e9be7 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 9 May 2024 01:05:03 +0800 Subject: [PATCH 02/15] Update mongodb.js --- plugins/mongodb/js/mongodb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mongodb/js/mongodb.js b/plugins/mongodb/js/mongodb.js index c0a13318f..70707e0ad 100644 --- a/plugins/mongodb/js/mongodb.js +++ b/plugins/mongodb/js/mongodb.js @@ -154,7 +154,7 @@ function mongoReplStatus() { } else{ tbody += '状态' + rdata.status + '主/从\ 同步文档' + rdata.setName + '文档名\ - hosts' + rdata.hosts + '服务器所有节点\ + hosts' + rdata.hosts + '服务器所有节点\ primary' + rdata.primary + '主节点\ me' + rdata.me + '本机'; } From 57f4162cb8155de34ebfda2649c1a428600a1cfe Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 9 May 2024 01:08:14 +0800 Subject: [PATCH 03/15] Update mongodb.js --- plugins/mongodb/js/mongodb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mongodb/js/mongodb.js b/plugins/mongodb/js/mongodb.js index 70707e0ad..ef370d5af 100644 --- a/plugins/mongodb/js/mongodb.js +++ b/plugins/mongodb/js/mongodb.js @@ -154,7 +154,7 @@ function mongoReplStatus() { } else{ tbody += '状态' + rdata.status + '主/从\ 同步文档' + rdata.setName + '文档名\ - hosts' + rdata.hosts + '服务器所有节点\ + hosts' + rdata.hosts + '服务器所有节点\ primary' + rdata.primary + '主节点\ me' + rdata.me + '本机'; } From dfe7becdb10bc879a717be47b0b6dee0a5d95d09 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 9 May 2024 23:43:16 +0800 Subject: [PATCH 04/15] Update system_api.py --- class/core/system_api.py | 156 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 151 insertions(+), 5 deletions(-) diff --git a/class/core/system_api.py b/class/core/system_api.py index 939b7634b..bd8144c99 100755 --- a/class/core/system_api.py +++ b/class/core/system_api.py @@ -44,10 +44,11 @@ def mw_async(f): class system_api: setupPath = None pids = None - + cache = {} def __init__(self): self.setupPath = mw.getServerDir() + ##### ----- start ----- ### def networkApi(self): data = self.getNetWork() @@ -254,8 +255,7 @@ class system_api: data['load_average'] = self.GetLoadAverage(get) data['title'] = self.GetTitle() data['network'] = self.GetNetWorkApi(get) - data['panel_status'] = not os.path.exists( - '/www/server/mdserver-web/data/close.pl') + data['panel_status'] = not os.path.exists('/www/server/mdserver-web/data/close.pl') import firewalls ssh_info = firewalls.firewalls().GetSshInfo(None) data['enable_ssh_status'] = ssh_info['status'] @@ -488,7 +488,7 @@ class system_api: shutil.rmtree(filename) else: os.remove(filename) - print('mail clear ok') + # print('mail clear ok') num += 1 total += size count += num @@ -555,6 +555,9 @@ class system_api: session['otime'] = time.time() ntime = time.time() + + print("source",ntime - session['otime']) + networkInfo = {} networkInfo['upTotal'] = networkIo[0] networkInfo['downTotal'] = networkIo[1] @@ -573,12 +576,155 @@ class system_api: networkInfo['cpu'] = self.getCpuInfo() networkInfo['load'] = self.getLoadAverage() networkInfo['mem'] = self.getMemInfo() + networkInfo['iostat'] = self.getDiskIostat() + networkInfo['network'] = self.getNetWorkIostat() return networkInfo except Exception as e: - print("getNetWork error:", e) + print(mw.getTracebackInfo()) return None + def getNetWorkIostat(self): + netInfo = {} + + + netInfo['ALL'] = {} + netInfo['ALL']['up'] = 0 + netInfo['ALL']['down'] = 0 + netInfo['ALL']['upTotal'] = 0 + netInfo['ALL']['downTotal'] = 0 + netInfo['ALL']['upPackets'] = 0 + netInfo['ALL']['downPackets'] = 0 + + mtime = time.time() + iokey = 'netstat' + netio = None + if iokey in self.cache: + netio = self.cache[iokey] + + if not netio: + netio = {} + netio['info'] = None + netio['all_io'] = None + netio['time'] = mtime + + stime = mtime - netio['time'] + if not stime: stime = 1 + + print("new:",stime) + + netio_group = psutil.net_io_counters(pernic=True).keys() + + netio_cache = netio['info'] + allio_cache = netio['all_io'] + if not netio_cache: + netio_cache = {} + + netio_group_t = {} + for name in netio_group: + netInfo[name] = {} + + io_data = psutil.net_io_counters(pernic=True).get(name) + if not name in netio_cache: + netio_cache[name] = io_data + + netio_group_t[name] = io_data + + netInfo[name]['up'] = round(float(io_data[0] - netio_cache[name][0] / stime), 2) + netInfo[name]['down'] = round(float(io_data[1] - netio_cache[name][1] / stime), 2) + + netInfo[name]['upTotal'] = io_data[0] + netInfo[name]['downTotal'] = io_data[1] + netInfo[name]['upPackets'] = io_data[2] + netInfo[name]['downPackets'] = io_data[3] + + all_io = psutil.net_io_counters()[:4] + if not allio_cache: + allio_cache = all_io + + netInfo['ALL']['up'] = round(float(all_io[0] - allio_cache[0] / stime), 2) + netInfo['ALL']['down'] = round(float(all_io[1] - allio_cache[1] / stime), 2) + netInfo['ALL']['upTotal'] = all_io[0] + netInfo['ALL']['downTotal'] = all_io[1] + netInfo['ALL']['upPackets'] = all_io[2] + netInfo['ALL']['downPackets'] = all_io[3] + + self.cache[iokey] = {'info':netio_group_t,'all_io':all_io,'time':mtime} + return netInfo + + + def getDiskIostat(self): + iokey = 'iostat' + + diskInfo = {} + diskInfo['ALL'] = {} + diskInfo['ALL']['read_count'] = 0 + diskInfo['ALL']['write_count'] = 0 + diskInfo['ALL']['read_bytes'] = 0 + diskInfo['ALL']['write_bytes'] = 0 + diskInfo['ALL']['read_time'] = 0 + diskInfo['ALL']['write_time'] = 0 + diskInfo['ALL']['read_merged_count'] = 0 + diskInfo['ALL']['write_merged_count'] = 0 + + try: + diskio = None + if iokey in self.cache: + diskio = self.cache[iokey] + + mtime = int(time.time()) + if not diskio: + diskio = {} + diskio['info'] = None + diskio['time'] = mtime + + diskio_cache = diskio['info'] + stime = mtime - diskio['time'] + if not stime: stime = 1 + + diskio_group = psutil.disk_io_counters(perdisk=True) + if not diskio_cache: + diskio_cache = diskio_group + + for disk_name in diskio_group.keys(): + diskInfo[disk_name] = {} + # print('disk_name',disk_name) + # print('diskio_group',diskio_group[disk_name]) + # print('diskio_cache',diskio_cache[disk_name]) + + diskInfo[disk_name]['read_count'] = int((diskio_group[disk_name].read_count - diskio_cache[disk_name].read_count) / stime) + diskInfo[disk_name]['write_count'] = int((diskio_group[disk_name].write_count - diskio_cache[disk_name].write_count) / stime) + diskInfo[disk_name]['read_bytes'] = int((diskio_group[disk_name].read_bytes - diskio_cache[disk_name].read_bytes) / stime) + diskInfo[disk_name]['write_bytes'] = int((diskio_group[disk_name].write_bytes - diskio_cache[disk_name].write_bytes) / stime) + diskInfo[disk_name]['read_time'] = int((diskio_group[disk_name].read_time - diskio_cache[disk_name].read_time) / stime) + diskInfo[disk_name]['write_time'] = int((diskio_group[disk_name].write_time - diskio_cache[disk_name].write_time) / stime) + + if 'read_merged_count' in diskio_group[disk_name] and 'read_merged_count' in diskio_cache[disk_name]: + diskInfo[disk_name]['read_merged_count'] = int((diskio_group[disk_name].read_merged_count - diskio_cache[disk_name].read_merged_count) / stime) + if 'write_merged_count' in diskio_group[disk_name] and 'write_merged_count' in diskio_cache[disk_name]: + diskInfo[disk_name]['write_merged_count'] = int((diskio_group[disk_name].write_merged_count - diskio_cache[disk_name].write_merged_count) / stime) + + diskInfo['ALL']['read_count'] += diskInfo[disk_name]['read_count'] + diskInfo['ALL']['write_count'] += diskInfo[disk_name]['write_count'] + diskInfo['ALL']['read_bytes'] += diskInfo[disk_name]['read_bytes'] + diskInfo['ALL']['write_bytes'] += diskInfo[disk_name]['write_bytes'] + if diskInfo['ALL']['read_time'] < diskInfo[disk_name]['read_time']: + diskInfo['ALL']['read_time'] = diskInfo[disk_name]['read_time'] + if diskInfo['ALL']['write_time'] < diskInfo[disk_name]['write_time']: + diskInfo['ALL']['write_time'] = diskInfo[disk_name]['write_time'] + + if 'read_merged_count' in diskInfo[disk_name] and 'read_merged_count' in diskInfo[disk_name]: + diskInfo['ALL']['read_merged_count'] += diskInfo[disk_name]['read_merged_count'] + if 'write_merged_count' in diskInfo[disk_name] and 'write_merged_count' in diskInfo[disk_name]: + diskInfo['ALL']['write_merged_count'] += diskInfo[disk_name]['write_merged_count'] + + self.cache[iokey] = {'info':diskio_group,'time':mtime} + except Exception as e: + # print(mw.getTracebackInfo()) + pass + + return diskInfo + def getNetWorkIoData(self, start, end): # 取指定时间段的网络Io data = mw.M('network').dbfile('system').where("addtime>=? AND addtime<=?", (start, end)).field( From d6f43a86c910e4ab4ac217111ccc5dce2e9699a8 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 10 May 2024 02:16:39 +0800 Subject: [PATCH 05/15] Update system_api.py --- class/core/system_api.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/class/core/system_api.py b/class/core/system_api.py index bd8144c99..1e21b85ee 100755 --- a/class/core/system_api.py +++ b/class/core/system_api.py @@ -556,8 +556,7 @@ class system_api: ntime = time.time() - print("source",ntime - session['otime']) - + # print("source",ntime - session['otime']) networkInfo = {} networkInfo['upTotal'] = networkIo[0] networkInfo['downTotal'] = networkIo[1] @@ -587,7 +586,6 @@ class system_api: def getNetWorkIostat(self): netInfo = {} - netInfo['ALL'] = {} netInfo['ALL']['up'] = 0 netInfo['ALL']['down'] = 0 @@ -611,8 +609,7 @@ class system_api: stime = mtime - netio['time'] if not stime: stime = 1 - print("new:",stime) - + # print("new:",stime) netio_group = psutil.net_io_counters(pernic=True).keys() netio_cache = netio['info'] From e0ebdd922de38dcd2dd8bfb7d9fbcff7c8abbc24 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 10 May 2024 02:16:49 +0800 Subject: [PATCH 06/15] Update site.css --- route/static/css/site.css | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/route/static/css/site.css b/route/static/css/site.css index 235c870b7..6e097f777 100755 --- a/route/static/css/site.css +++ b/route/static/css/site.css @@ -5096,4 +5096,44 @@ select[disabled]{ white-space: nowrap; overflow: hidden; text-overflow: ellipsis; +} + + +.title.tabs-nav { + padding: 0; + position: relative; +} + +.title.tabs-nav span { + display: inline-block; + height: 50px; + min-width: 100px; + padding: 0 20px; + line-height: 50px; + font-size: 15px; + cursor: pointer; + position: relative; + text-align: center; +} + +.title.tabs-nav span.active { + color: #20a53a; + background: #20a53a08; +} + + +.title.tabs-nav select { + position: absolute; + right: 5px; + top: 50%; + margin-top: -12px; +} + +select[name="network-io"], select[name="disk-io"] { + font-size: 13px; + height: 24px; + line-height: 24px; + padding: 2px; + border-radius: 0; + border-color: #ececec; } \ No newline at end of file From cb0027e9035467b7644fa0d628b86efcc0c36fe5 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 10 May 2024 04:23:48 +0800 Subject: [PATCH 07/15] Update system_api.py --- class/core/system_api.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/class/core/system_api.py b/class/core/system_api.py index 1e21b85ee..dd96814fc 100755 --- a/class/core/system_api.py +++ b/class/core/system_api.py @@ -627,8 +627,8 @@ class system_api: netio_group_t[name] = io_data - netInfo[name]['up'] = round(float(io_data[0] - netio_cache[name][0] / stime), 2) - netInfo[name]['down'] = round(float(io_data[1] - netio_cache[name][1] / stime), 2) + netInfo[name]['up'] = round(float((io_data[0] - netio_cache[name][0]) / stime), 2) + netInfo[name]['down'] = round(float((io_data[1] - netio_cache[name][1])/ stime), 2) netInfo[name]['upTotal'] = io_data[0] netInfo[name]['downTotal'] = io_data[1] @@ -639,8 +639,8 @@ class system_api: if not allio_cache: allio_cache = all_io - netInfo['ALL']['up'] = round(float(all_io[0] - allio_cache[0] / stime), 2) - netInfo['ALL']['down'] = round(float(all_io[1] - allio_cache[1] / stime), 2) + netInfo['ALL']['up'] = round(float((all_io[0] - allio_cache[0]) /stime), 2) + netInfo['ALL']['down'] = round(float((all_io[1] - allio_cache[1]) /stime), 2) netInfo['ALL']['upTotal'] = all_io[0] netInfo['ALL']['downTotal'] = all_io[1] netInfo['ALL']['upPackets'] = all_io[2] From 7f8ffbf178ed15dd44f6ea3ab21e0e3daafbf011 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 10 May 2024 04:36:43 +0800 Subject: [PATCH 08/15] Update site.css --- route/static/css/site.css | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/route/static/css/site.css b/route/static/css/site.css index 6e097f777..48ae0babb 100755 --- a/route/static/css/site.css +++ b/route/static/css/site.css @@ -5136,4 +5136,15 @@ select[name="network-io"], select[name="disk-io"] { padding: 2px; border-radius: 0; border-color: #ececec; +} + +.tabs-content .tabs-item { + display: none; + height: 100%; + width: 100%; + background-color: #fff; +} + +.tabs-content .tabs-active.tabs-item { + display: inline-block; } \ No newline at end of file From 8eb728defa5d64b1af43f9bb9689dc5ed5260215 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 10 May 2024 12:04:21 +0800 Subject: [PATCH 09/15] =?UTF-8?q?index=E5=8A=A0=E5=85=A5io=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/core/system_api.py | 44 +- route/static/app/index.js | 620 ++++++++++++++++++++++++++--- route/templates/default/index.html | 50 ++- 3 files changed, 629 insertions(+), 85 deletions(-) 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 @@
-
-
流量
-
-

上行

0
-

下行

0
-

总发送

0
-

总接收

0
+
+
+
+ 流量 + 磁盘IO +
+ +
+ + +
-
+ +
+
+
+

上行

0
+

下行

0
+

总发送

0
+

总接收

0
+
+
+
+ +
+
+

读取

0
+

写入

0
+

每秒读写

0
+

IO延迟

0
+
+
+
+
+
@@ -119,8 +149,8 @@