diff --git a/class/core/plugin_api.py b/class/core/plugin_api.py index 8ba16dd3f..9b9fa53cf 100755 --- a/class/core/plugin_api.py +++ b/class/core/plugin_api.py @@ -44,6 +44,7 @@ class plugin_api: if not self.__tasks: self.__tasks = public.M('tasks').where( "status!=?", ('1',)).field('status,name').select() + if sName.find('php-') != -1: tmp = sName.split('-') sName = tmp[0] @@ -188,6 +189,7 @@ class plugin_api: pg = self.getPluginInfo(data) plugins_info.append(pg) + # print plugins_info, data return plugins_info def getAllList(self, sType='0'): diff --git a/class/core/system_api.py b/class/core/system_api.py index 7d8887495..845c18517 100755 --- a/class/core/system_api.py +++ b/class/core/system_api.py @@ -336,6 +336,7 @@ class system_api: return networkInfo except Exception, e: + print e return None def getNetWorkApi(self, get=None): @@ -386,34 +387,72 @@ class system_api: '/panel/' + scriptFile) return self.GetMemInfo() - def getNetWorkIo(self, start, end): + def getNetWorkIoData(self, start, end): # 取指定时间段的网络Io data = public.M('network').dbfile('system').where("addtime>=? AND addtime<=?", (start, end)).field( 'id,up,down,total_up,total_down,down_packets,up_packets,addtime').order('id asc').select() - return self.ToAddtime(data) + return self.toAddtime(data) - def getDiskIo(self, start, end): + def getDiskIoData(self, start, end): # 取指定时间段的磁盘Io data = public.M('diskio').dbfile('system').where("addtime>=? AND addtime<=?", (start, end)).field( 'id,read_count,write_count,read_bytes,write_bytes,read_time,write_time,addtime').order('id asc').select() - return self.ToAddtime(data) + return self.toAddtime(data) - def getCpuIo(self, start, end): + def getCpuIoData(self, start, end): # 取指定时间段的CpuIo data = public.M('cpuio').dbfile('system').where("addtime>=? AND addtime<=?", (start, end)).field('id,pro,mem,addtime').order('id asc').select() - return self.ToAddtime(data, True) + return self.toAddtime(data, True) - def getLoadAverage(self, start, end): + def getLoadAverageData(self, start, end): data = public.M('load_average').dbfile('system').where("addtime>=? AND addtime<=?", ( start, end)).field('id,pro,one,five,fifteen,addtime').order('id asc').select() - return self.ToAddtime(data) + return self.toAddtime(data) + + def toAddtime(self, data, tomem=False): + import time + # 格式化addtime列 + + if tomem: + import psutil + mPre = (psutil.virtual_memory().total / 1024 / 1024) / 100 + length = len(data) + he = 1 + if length > 100: + he = 1 + if length > 1000: + he = 3 + if length > 10000: + he = 15 + if he == 1: + for i in range(length): + data[i]['addtime'] = time.strftime( + '%m/%d %H:%M', time.localtime(float(data[i]['addtime']))) + if tomem and data[i]['mem'] > 100: + data[i]['mem'] = data[i]['mem'] / mPre + + return data + else: + count = 0 + tmp = [] + for value in data: + if count < he: + count += 1 + continue + value['addtime'] = time.strftime( + '%m/%d %H:%M', time.localtime(float(value['addtime']))) + if tomem and value['mem'] > 100: + value['mem'] = value['mem'] / mPre + tmp.append(value) + count = 0 + return tmp # 重启面板 def reWeb(self, get): # if not public.IsRestart(): return # public.returnMsg(False,'EXEC_ERR_TASK'); - public.ExecShell('/etc/init.d/bt restart &') + # public.ExecShell('/etc/init.d/bt restart &') return True # 修复面板 diff --git a/route/plugins.py b/route/plugins.py index 4707fb58b..4c2444ae6 100644 --- a/route/plugins.py +++ b/route/plugins.py @@ -1,14 +1,14 @@ # coding:utf-8 -from flask import Blueprint, render_template -from flask import jsonify -from flask import request - -import psutil import time import sys import os import json +import psutil + +from flask import Blueprint, render_template +from flask import jsonify +from flask import request sys.path.append("class/core") import public diff --git a/route/system.py b/route/system.py index 668bc7bb9..c9870f013 100644 --- a/route/system.py +++ b/route/system.py @@ -8,6 +8,7 @@ import sys from flask import Flask, session from flask import Blueprint, render_template from flask import jsonify +from flask import request sys.path.append("class/core") import public @@ -47,23 +48,31 @@ def getControl(): @system.route('/get_load_average', methods=['GET']) def getLoadAverage(): - data = {'status': True, 'day': 30} + start = request.args.get('start', '') + end = request.args.get('end', '') + data = system_api.system_api().getLoadAverageData(start, end) return public.getJson(data) @system.route('/get_cpu_io', methods=['GET']) def getCpuIo(): - data = {'status': True, 'day': 30} + start = request.args.get('start', '') + end = request.args.get('end', '') + data = system_api.system_api().getCpuIoData(start, end) return public.getJson(data) @system.route('/get_disk_io', methods=['GET']) def getDiskIo(): - data = {'status': True, 'day': 30} + start = request.args.get('start', '') + end = request.args.get('end', '') + data = system_api.system_api().getDiskIoData(start, end) return public.getJson(data) @system.route('/get_network_io', methods=['GET']) def getNetworkIo(): - data = {'status': True, 'day': 30} + start = request.args.get('start', '') + end = request.args.get('end', '') + data = system_api.system_api().getNetWorkIoData(start, end) return public.getJson(data) diff --git a/static/js/control.js b/static/js/control.js index c5aec72b9..749df9bbf 100755 --- a/static/js/control.js +++ b/static/js/control.js @@ -14,6 +14,7 @@ setTimeout(function(){ setTimeout(function(){ Wday(0,'network'); },2000); + $(".st").hover(function(){ $(this).next().show(); },function(){ @@ -205,746 +206,746 @@ function getBeforeDate(n){ } //cpu function cpu(b,e){ -$.get('/system/get_cpu_io?start='+b+'&end='+e,function(rdata){ - var myChartCpu = echarts.init(document.getElementById('cupview')); - var xData = []; - var yData = []; - //var zData = []; - - for(var i = 0; i < rdata.length; i++){ - xData.push(rdata[i].addtime); - yData.push(rdata[i].pro); - //zData.push(rdata[i].mem); - } - option = { - tooltip: { - trigger: 'axis', - axisPointer: { - type: 'cross' + $.get('/system/get_cpu_io?start='+b+'&end='+e,function(rdata){ + var myChartCpu = echarts.init(document.getElementById('cupview')); + var xData = []; + var yData = []; + //var zData = []; + + for(var i = 0; i < rdata.length; i++){ + xData.push(rdata[i].addtime); + yData.push(rdata[i].pro); + //zData.push(rdata[i].mem); + } + option = { + tooltip: { + trigger: 'axis', + axisPointer: { + type: 'cross' + }, + formatter: '{b}
{a}: {c}%' }, - formatter: '{b}
{a}: {c}%' - }, - xAxis: { - type: 'category', - boundaryGap: false, - data: xData, - axisLine:{ - lineStyle:{ - color:"#666" - } - } - }, - yAxis: { - type: 'value', - name: lan.public.pre, - boundaryGap: [0, '100%'], - min:0, - max: 100, - splitLine:{ - lineStyle:{ - color:"#ddd" + xAxis: { + type: 'category', + boundaryGap: false, + data: xData, + axisLine:{ + lineStyle:{ + color:"#666" + } } }, - axisLine:{ - lineStyle:{ - color:"#666" - } - } - }, - dataZoom: [{ - type: 'inside', - start: 0, - end: 100, - zoomLock:true - }, { - start: 0, - end: 100, - handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z', - handleSize: '80%', - handleStyle: { - color: '#fff', - shadowBlur: 3, - shadowColor: 'rgba(0, 0, 0, 0.6)', - shadowOffsetX: 2, - shadowOffsetY: 2 - } - }], - series: [ - { - name:'CPU', - type:'line', - smooth:true, - symbol: 'none', - sampling: 'average', - itemStyle: { - normal: { - color: 'rgb(0, 153, 238)' + yAxis: { + type: 'value', + name: lan.public.pre, + boundaryGap: [0, '100%'], + min:0, + max: 100, + splitLine:{ + lineStyle:{ + color:"#ddd" } }, - data: yData - } - ] - }; - myChartCpu.setOption(option); - window.addEventListener("resize",function(){ - myChartCpu.resize(); - }); -}) + axisLine:{ + lineStyle:{ + color:"#666" + } + } + }, + dataZoom: [{ + type: 'inside', + start: 0, + end: 100, + zoomLock:true + }, { + start: 0, + end: 100, + handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z', + handleSize: '80%', + handleStyle: { + color: '#fff', + shadowBlur: 3, + shadowColor: 'rgba(0, 0, 0, 0.6)', + shadowOffsetX: 2, + shadowOffsetY: 2 + } + }], + series: [ + { + name:'CPU', + type:'line', + smooth:true, + symbol: 'none', + sampling: 'average', + itemStyle: { + normal: { + color: 'rgb(0, 153, 238)' + } + }, + data: yData + } + ] + }; + myChartCpu.setOption(option); + window.addEventListener("resize",function(){ + myChartCpu.resize(); + }); + },'json'); } //内存 function mem(b,e){ -$.get('/system/get_cpu_io?start='+b+'&end='+e,function(rdata){ - var myChartMen = echarts.init(document.getElementById('memview')); - var xData = []; - //var yData = []; - var zData = []; - - for(var i = 0; i < rdata.length; i++){ - xData.push(rdata[i].addtime); - //yData.push(rdata[i].pro); - zData.push(rdata[i].mem); - } - option = { - tooltip: { - trigger: 'axis', - axisPointer: { - type: 'cross' + $.get('/system/get_cpu_io?start='+b+'&end='+e,function(rdata){ + var myChartMen = echarts.init(document.getElementById('memview')); + var xData = []; + //var yData = []; + var zData = []; + + for(var i = 0; i < rdata.length; i++){ + xData.push(rdata[i].addtime); + //yData.push(rdata[i].pro); + zData.push(rdata[i].mem); + } + option = { + tooltip: { + trigger: 'axis', + axisPointer: { + type: 'cross' + }, + formatter: '{b}
{a}: {c}%' }, - formatter: '{b}
{a}: {c}%' - }, - xAxis: { - type: 'category', - boundaryGap: false, - data: xData, - axisLine:{ - lineStyle:{ - color:"#666" - } - } - }, - yAxis: { - type: 'value', - name: lan.public.pre, - boundaryGap: [0, '100%'], - min:0, - max: 100, - splitLine:{ - lineStyle:{ - color:"#ddd" + xAxis: { + type: 'category', + boundaryGap: false, + data: xData, + axisLine:{ + lineStyle:{ + color:"#666" + } } }, - axisLine:{ - lineStyle:{ - color:"#666" - } - } - }, - dataZoom: [{ - type: 'inside', - start: 0, - end: 100, - zoomLock:true - }, { - start: 0, - end: 100, - handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z', - handleSize: '80%', - handleStyle: { - color: '#fff', - shadowBlur: 3, - shadowColor: 'rgba(0, 0, 0, 0.6)', - shadowOffsetX: 2, - shadowOffsetY: 2 - } - }], - series: [ - { - name:lan.index.process_mem, - type:'line', - smooth:true, - symbol: 'none', - sampling: 'average', - itemStyle: { - normal: { - color: 'rgb(0, 153, 238)' + yAxis: { + type: 'value', + name: lan.public.pre, + boundaryGap: [0, '100%'], + min:0, + max: 100, + splitLine:{ + lineStyle:{ + color:"#ddd" } }, - data: zData - } - ] - }; - myChartMen.setOption(option); - window.addEventListener("resize",function(){ - myChartMen.resize(); - }); -}) + axisLine:{ + lineStyle:{ + color:"#666" + } + } + }, + dataZoom: [{ + type: 'inside', + start: 0, + end: 100, + zoomLock:true + }, { + start: 0, + end: 100, + handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z', + handleSize: '80%', + handleStyle: { + color: '#fff', + shadowBlur: 3, + shadowColor: 'rgba(0, 0, 0, 0.6)', + shadowOffsetX: 2, + shadowOffsetY: 2 + } + }], + series: [ + { + name:lan.index.process_mem, + type:'line', + smooth:true, + symbol: 'none', + sampling: 'average', + itemStyle: { + normal: { + color: 'rgb(0, 153, 238)' + } + }, + data: zData + } + ] + }; + myChartMen.setOption(option); + window.addEventListener("resize",function(){ + myChartMen.resize(); + }); + },'json'); } //磁盘io function disk(b,e){ -$.get('/system/get_disk_io?start='+b+'&end='+e,function(rdata){ - var myChartDisk = echarts.init(document.getElementById('diskview')); - var rData = []; - var wData = []; - var xData = []; - //var yData = []; - //var zData = []; - - for(var i = 0; i < rdata.length; i++){ - rData.push((rdata[i].read_bytes/1024/60).toFixed(3)); - wData.push((rdata[i].write_bytes/1024/60).toFixed(3)); - xData.push(rdata[i].addtime); - //yData.push(rdata[i].read_count); - //zData.push(rdata[i].write_count); - } - option = { - tooltip: { - trigger: 'axis', - axisPointer: { - type: 'cross' + $.get('/system/get_disk_io?start='+b+'&end='+e,function(rdata){ + var myChartDisk = echarts.init(document.getElementById('diskview')); + var rData = []; + var wData = []; + var xData = []; + //var yData = []; + //var zData = []; + + for(var i = 0; i < rdata.length; i++){ + rData.push((rdata[i].read_bytes/1024/60).toFixed(3)); + wData.push((rdata[i].write_bytes/1024/60).toFixed(3)); + xData.push(rdata[i].addtime); + //yData.push(rdata[i].read_count); + //zData.push(rdata[i].write_count); + } + option = { + tooltip: { + trigger: 'axis', + axisPointer: { + type: 'cross' + }, + formatter:"时间:{b0}
{a0}: {c0} Kb/s
{a1}: {c1} Kb/s", }, - formatter:"时间:{b0}
{a0}: {c0} Kb/s
{a1}: {c1} Kb/s", - }, - legend: { - data:[lan.control.disk_read_bytes,lan.control.disk_write_bytes] - }, - xAxis: { - type: 'category', - boundaryGap: false, - data: xData, - axisLine:{ - lineStyle:{ - color:"#666" - } - } - }, - yAxis: { - type: 'value', - name: lan.index.unit+':KB/s', - boundaryGap: [0, '100%'], - splitLine:{ - lineStyle:{ - color:"#ddd" - } + legend: { + data:[lan.control.disk_read_bytes,lan.control.disk_write_bytes] }, - axisLine:{ - lineStyle:{ - color:"#666" + xAxis: { + type: 'category', + boundaryGap: false, + data: xData, + axisLine:{ + lineStyle:{ + color:"#666" + } } - } - }, - dataZoom: [{ - type: 'inside', - start: 0, - end: 100, - zoomLock:true - }, { - start: 0, - end: 100, - handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z', - handleSize: '80%', - handleStyle: { - color: '#fff', - shadowBlur: 3, - shadowColor: 'rgba(0, 0, 0, 0.6)', - shadowOffsetX: 2, - shadowOffsetY: 2 - } - }], - series: [ - { - name:lan.control.disk_read_bytes, - type:'line', - smooth:true, - symbol: 'none', - sampling: 'average', - itemStyle: { - normal: { - color: 'rgb(255, 70, 131)' + }, + yAxis: { + type: 'value', + name: lan.index.unit+':KB/s', + boundaryGap: [0, '100%'], + splitLine:{ + lineStyle:{ + color:"#ddd" } }, - data: rData - }, - { - name:lan.control.disk_write_bytes, - type:'line', - smooth:true, - symbol: 'none', - sampling: 'average', - itemStyle: { - normal: { - color: 'rgba(46, 165, 186, .7)' + axisLine:{ + lineStyle:{ + color:"#666" } + } + }, + dataZoom: [{ + type: 'inside', + start: 0, + end: 100, + zoomLock:true + }, { + start: 0, + end: 100, + handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z', + handleSize: '80%', + handleStyle: { + color: '#fff', + shadowBlur: 3, + shadowColor: 'rgba(0, 0, 0, 0.6)', + shadowOffsetX: 2, + shadowOffsetY: 2 + } + }], + series: [ + { + name:lan.control.disk_read_bytes, + type:'line', + smooth:true, + symbol: 'none', + sampling: 'average', + itemStyle: { + normal: { + color: 'rgb(255, 70, 131)' + } + }, + data: rData }, - data: wData - } - ] - }; - myChartDisk.setOption(option); - window.addEventListener("resize",function(){ - myChartDisk.resize(); - }); -}) + { + name:lan.control.disk_write_bytes, + type:'line', + smooth:true, + symbol: 'none', + sampling: 'average', + itemStyle: { + normal: { + color: 'rgba(46, 165, 186, .7)' + } + }, + data: wData + } + ] + }; + myChartDisk.setOption(option); + window.addEventListener("resize",function(){ + myChartDisk.resize(); + }); + },'json'); } //网络Io function network(b,e){ -$.get('/system/get_network_io?start='+b+'&end='+e,function(rdata){ - var myChartNetwork = echarts.init(document.getElementById('network')); - var aData = []; - var bData = []; - var cData = []; - var dData = []; - var xData = []; - var yData = []; - var zData = []; - - for(var i = 0; i < rdata.length; i++){ - aData.push(rdata[i].total_up); - bData.push(rdata[i].total_down); - cData.push(rdata[i].down_packets); - dData.push(rdata[i].up_packets); - xData.push(rdata[i].addtime); - yData.push(rdata[i].up); - zData.push(rdata[i].down); - } - option = { - tooltip: { - trigger: 'axis', - axisPointer: { - type: 'cross' - } - }, - legend: { - data:[lan.index.net_up,lan.index.net_down] - }, - xAxis: { - type: 'category', - boundaryGap: false, - data: xData, - axisLine:{ - lineStyle:{ - color:"#666" - } - } - }, - yAxis: { - type: 'value', - name: lan.index.unit+':KB/s', - boundaryGap: [0, '100%'], - splitLine:{ - lineStyle:{ - color:"#ddd" + $.get('/system/get_network_io?start='+b+'&end='+e,function(rdata){ + var myChartNetwork = echarts.init(document.getElementById('network')); + var aData = []; + var bData = []; + var cData = []; + var dData = []; + var xData = []; + var yData = []; + var zData = []; + + for(var i = 0; i < rdata.length; i++){ + aData.push(rdata[i].total_up); + bData.push(rdata[i].total_down); + cData.push(rdata[i].down_packets); + dData.push(rdata[i].up_packets); + xData.push(rdata[i].addtime); + yData.push(rdata[i].up); + zData.push(rdata[i].down); + } + option = { + tooltip: { + trigger: 'axis', + axisPointer: { + type: 'cross' } }, - axisLine:{ - lineStyle:{ - color:"#666" - } - } - }, - dataZoom: [{ - type: 'inside', - start: 0, - end: 100, - zoomLock:true - }, { - start: 0, - end: 100, - handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z', - handleSize: '80%', - handleStyle: { - color: '#fff', - shadowBlur: 3, - shadowColor: 'rgba(0, 0, 0, 0.6)', - shadowOffsetX: 2, - shadowOffsetY: 2 - } - }], - series: [ - { - name:lan.index.net_up, - type:'line', - smooth:true, - symbol: 'none', - sampling: 'average', - itemStyle: { - normal: { - color: 'rgb(255, 140, 0)' - } - }, - data: yData + legend: { + data:[lan.index.net_up,lan.index.net_down] }, - { - name:lan.index.net_down, - type:'line', - smooth:true, - symbol: 'none', - sampling: 'average', - itemStyle: { - normal: { - color: 'rgb(30, 144, 255)' + xAxis: { + type: 'category', + boundaryGap: false, + data: xData, + axisLine:{ + lineStyle:{ + color:"#666" } - }, - data: zData - } - ] - }; - myChartNetwork.setOption(option); - window.addEventListener("resize",function(){ - myChartNetwork.resize(); - }); -}) -} -//负载 -function getload_old(b,e){ -$.get('/system/get_load_average?start='+b+'&end='+e,function(rdata){ - var myChartgetload = echarts.init(document.getElementById('getloadview')); - var aData = []; - var bData = []; - var xData = []; - var yData = []; - var zData = []; - - for(var i = 0; i < rdata.length; i++){ - xData.push(rdata[i].addtime); - yData.push(rdata[i].pro); - zData.push(rdata[i].one); - aData.push(rdata[i].five); - bData.push(rdata[i].fifteen); - } - option = { - tooltip: { - trigger: 'axis' - }, - calculable: true, - legend: { - data:['系统资源使用率','1分钟','5分钟','15分钟'], - selectedMode: 'single', - }, - xAxis: { - type: 'category', - boundaryGap: false, - data: xData, - axisLine:{ - lineStyle:{ - color:"#666" - } - } - }, - yAxis: { - type: 'value', - name: '', - boundaryGap: [0, '100%'], - splitLine:{ - lineStyle:{ - color:"#ddd" } }, - axisLine:{ - lineStyle:{ - color:"#666" - } - } - }, - dataZoom: [{ - type: 'inside', - start: 0, - end: 100, - zoomLock:true - }, { - start: 0, - end: 100, - handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z', - handleSize: '80%', - handleStyle: { - color: '#fff', - shadowBlur: 3, - shadowColor: 'rgba(0, 0, 0, 0.6)', - shadowOffsetX: 2, - shadowOffsetY: 2 - } - }], - series: [ - { - name:'系统资源使用率', - type:'line', - smooth:true, - symbol: 'none', - sampling: 'average', - itemStyle: { - normal: { - color: 'rgb(255, 140, 0)' - } - }, - data: yData - }, - { - name:'1分钟', - type:'line', - smooth:true, - symbol: 'none', - sampling: 'average', - itemStyle: { - normal: { - color: 'rgb(30, 144, 255)' + yAxis: { + type: 'value', + name: lan.index.unit+':KB/s', + boundaryGap: [0, '100%'], + splitLine:{ + lineStyle:{ + color:"#ddd" } }, - data: zData - }, - { - name:'5分钟', - type:'line', - smooth:true, - symbol: 'none', - sampling: 'average', - itemStyle: { - normal: { - color: 'rgb(0, 178, 45)' + axisLine:{ + lineStyle:{ + color:"#666" } - }, - data: aData + } }, - { - name:'15分钟', - type:'line', - smooth:true, - symbol: 'none', - sampling: 'average', - itemStyle: { - normal: { - color: 'rgb(147, 38, 255)' - } + dataZoom: [{ + type: 'inside', + start: 0, + end: 100, + zoomLock:true + }, { + start: 0, + end: 100, + handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z', + handleSize: '80%', + handleStyle: { + color: '#fff', + shadowBlur: 3, + shadowColor: 'rgba(0, 0, 0, 0.6)', + shadowOffsetX: 2, + shadowOffsetY: 2 + } + }], + series: [ + { + name:lan.index.net_up, + type:'line', + smooth:true, + symbol: 'none', + sampling: 'average', + itemStyle: { + normal: { + color: 'rgb(255, 140, 0)' + } + }, + data: yData }, - data: bData - } - ] - }; - myChartgetload.setOption(option); - window.addEventListener("resize",function(){ - myChartgetload.resize(); - }); -}) + { + name:lan.index.net_down, + type:'line', + smooth:true, + symbol: 'none', + sampling: 'average', + itemStyle: { + normal: { + color: 'rgb(30, 144, 255)' + } + }, + data: zData + } + ] + }; + myChartNetwork.setOption(option); + window.addEventListener("resize",function(){ + myChartNetwork.resize(); + }); + },'json'); } -//系统负载 -function getload(b,e){ +//负载 +function getload_old(b,e){ $.get('/system/get_load_average?start='+b+'&end='+e,function(rdata){ - var myChartgetload = echarts.init(document.getElementById('getloadview')); - var aData = []; - var bData = []; - var xData = []; - var yData = []; - var zData = []; - - for(var i = 0; i < rdata.length; i++){ - xData.push(rdata[i].addtime); - yData.push(rdata[i].pro); - zData.push(rdata[i].one); - aData.push(rdata[i].five); - bData.push(rdata[i].fifteen); - } - option = { - animation: false, - tooltip: { - trigger: 'axis', - axisPointer: { - type: 'cross' - } - }, - legend: { - data:['1分钟','5分钟','15分钟'], - right:'16%', - top:'10px' - }, - axisPointer: { - link: {xAxisIndex: 'all'}, - lineStyle: { - color: '#aaaa', - width: 1 - } - }, - grid: [{ // 直角坐标系内绘图网格 - top: '60px', - left: '5%', - right: '55%', - width: '40%', - height: 'auto' + var myChartgetload = echarts.init(document.getElementById('getloadview')); + var aData = []; + var bData = []; + var xData = []; + var yData = []; + var zData = []; + + for(var i = 0; i < rdata.length; i++){ + xData.push(rdata[i].addtime); + yData.push(rdata[i].pro); + zData.push(rdata[i].one); + aData.push(rdata[i].five); + bData.push(rdata[i].fifteen); + } + option = { + tooltip: { + trigger: 'axis' }, - { - top: '60px', - left: '55%', - width: '40%', - height: 'auto' - } - ], - xAxis: [ - - { // 直角坐标系grid的x轴 - type: 'category', - axisLine: { - lineStyle: { - color: '#666' - } - }, - data: xData + calculable: true, + legend: { + data:['系统资源使用率','1分钟','5分钟','15分钟'], + selectedMode: 'single', }, - { // 直角坐标系grid的x轴 + xAxis: { type: 'category', - gridIndex: 1, - axisLine: { - lineStyle: { - color: '#666' + boundaryGap: false, + data: xData, + axisLine:{ + lineStyle:{ + color:"#666" } - }, - data: xData + } }, - ], - yAxis: [{ - scale: true, - name: '资源使用率%', - splitLine: { // y轴网格显示 - show: true, + yAxis: { + type: 'value', + name: '', + boundaryGap: [0, '100%'], + splitLine:{ lineStyle:{ color:"#ddd" } }, - nameTextStyle: { // 坐标轴名样式 - color: '#666', - fontSize: 12, - align: 'left' - }, axisLine:{ lineStyle:{ - color: '#666', + color:"#666" } } }, - { - scale: true, - name: '负载详情', - gridIndex: 1, - splitLine: { // y轴网格显示 - show: true, - lineStyle:{ - color:"#ddd" - } + dataZoom: [{ + type: 'inside', + start: 0, + end: 100, + zoomLock:true + }, { + start: 0, + end: 100, + handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z', + handleSize: '80%', + handleStyle: { + color: '#fff', + shadowBlur: 3, + shadowColor: 'rgba(0, 0, 0, 0.6)', + shadowOffsetX: 2, + shadowOffsetY: 2 + } + }], + series: [ + { + name:'系统资源使用率', + type:'line', + smooth:true, + symbol: 'none', + sampling: 'average', + itemStyle: { + normal: { + color: 'rgb(255, 140, 0)' + } + }, + data: yData }, - nameTextStyle: { // 坐标轴名样式 - color: '#666', - fontSize: 12, - align: 'left' + { + name:'1分钟', + type:'line', + smooth:true, + symbol: 'none', + sampling: 'average', + itemStyle: { + normal: { + color: 'rgb(30, 144, 255)' + } + }, + data: zData }, - axisLine:{ - lineStyle:{ - color: '#666', - } + { + name:'5分钟', + type:'line', + smooth:true, + symbol: 'none', + sampling: 'average', + itemStyle: { + normal: { + color: 'rgb(0, 178, 45)' + } + }, + data: aData + }, + { + name:'15分钟', + type:'line', + smooth:true, + symbol: 'none', + sampling: 'average', + itemStyle: { + normal: { + color: 'rgb(147, 38, 255)' + } + }, + data: bData } + ] + }; + myChartgetload.setOption(option); + window.addEventListener("resize",function(){ + myChartgetload.resize(); + }); + },'json'); +} +//系统负载 +function getload(b,e){ + $.get('/system/get_load_average?start='+b+'&end='+e,function(rdata){ + var myChartgetload = echarts.init(document.getElementById('getloadview')); + var aData = []; + var bData = []; + var xData = []; + var yData = []; + var zData = []; + + for(var i = 0; i < rdata.length; i++){ + xData.push(rdata[i].addtime); + yData.push(rdata[i].pro); + zData.push(rdata[i].one); + aData.push(rdata[i].five); + bData.push(rdata[i].fifteen); + } + option = { + animation: false, + tooltip: { + trigger: 'axis', + axisPointer: { + type: 'cross' + } }, - ], - dataZoom: [{ - type: 'inside', - start: 0, - end: 100, - xAxisIndex:[0,1], - zoomLock:true - }, { - xAxisIndex: [0, 1], - type: 'slider', - start: 0, - end: 100, - handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z', - handleSize: '80%', - handleStyle: { - color: '#fff', - shadowBlur: 3, - shadowColor: 'rgba(0, 0, 0, 0.6)', - shadowOffsetX: 2, - shadowOffsetY: 2 + legend: { + data:['1分钟','5分钟','15分钟'], + right:'16%', + top:'10px' }, - left:'5%', - right:'5%' - }], - series: [ - { - name: '资源使用率%', - type: 'line', + axisPointer: { + link: {xAxisIndex: 'all'}, lineStyle: { - normal: { - width: 2, - color: 'rgb(255, 140, 0)' - } + color: '#aaaa', + width: 1 + } + }, + grid: [{ // 直角坐标系内绘图网格 + top: '60px', + left: '5%', + right: '55%', + width: '40%', + height: 'auto' }, - itemStyle: { - normal: { - color: 'rgb(255, 140, 0)' - } + { + top: '60px', + left: '55%', + width: '40%', + height: 'auto' + } + ], + xAxis: [ + + { // 直角坐标系grid的x轴 + type: 'category', + axisLine: { + lineStyle: { + color: '#666' + } + }, + data: xData }, - data: yData - }, - { - xAxisIndex: 1, - yAxisIndex: 1, - name: '1分钟', - type: 'line', - lineStyle: { - normal: { - width: 2, - color: 'rgb(30, 144, 255)' - } + { // 直角坐标系grid的x轴 + type: 'category', + gridIndex: 1, + axisLine: { + lineStyle: { + color: '#666' + } + }, + data: xData }, - itemStyle: { - normal: { - color: 'rgb(30, 144, 255)' + ], + yAxis: [{ + scale: true, + name: '资源使用率%', + splitLine: { // y轴网格显示 + show: true, + lineStyle:{ + color:"#ddd" + } + }, + nameTextStyle: { // 坐标轴名样式 + color: '#666', + fontSize: 12, + align: 'left' + }, + axisLine:{ + lineStyle:{ + color: '#666', + } } }, - data: zData - }, - { - xAxisIndex: 1, - yAxisIndex: 1, - name: '5分钟', - type: 'line', - lineStyle: { - normal: { - width: 2, - color: 'rgb(0, 178, 45)' + { + scale: true, + name: '负载详情', + gridIndex: 1, + splitLine: { // y轴网格显示 + show: true, + lineStyle:{ + color:"#ddd" + } + }, + nameTextStyle: { // 坐标轴名样式 + color: '#666', + fontSize: 12, + align: 'left' + }, + axisLine:{ + lineStyle:{ + color: '#666', + } } }, - itemStyle: { - normal: { - color: 'rgb(0, 178, 45)' - } + ], + dataZoom: [{ + type: 'inside', + start: 0, + end: 100, + xAxisIndex:[0,1], + zoomLock:true + }, { + xAxisIndex: [0, 1], + type: 'slider', + start: 0, + end: 100, + handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z', + handleSize: '80%', + handleStyle: { + color: '#fff', + shadowBlur: 3, + shadowColor: 'rgba(0, 0, 0, 0.6)', + shadowOffsetX: 2, + shadowOffsetY: 2 }, - data: aData - }, - { - xAxisIndex: 1, - yAxisIndex: 1, - name: '15分钟', - type: 'line', - lineStyle: { - normal: { - width: 2, - color: 'rgb(147, 38, 255)' - } + left:'5%', + right:'5%' + }], + series: [ + { + name: '资源使用率%', + type: 'line', + lineStyle: { + normal: { + width: 2, + color: 'rgb(255, 140, 0)' + } + }, + itemStyle: { + normal: { + color: 'rgb(255, 140, 0)' + } + }, + data: yData }, - itemStyle: { - normal: { - color: 'rgb(147, 38, 255)' - } + { + xAxisIndex: 1, + yAxisIndex: 1, + name: '1分钟', + type: 'line', + lineStyle: { + normal: { + width: 2, + color: 'rgb(30, 144, 255)' + } + }, + itemStyle: { + normal: { + color: 'rgb(30, 144, 255)' + } + }, + data: zData + }, + { + xAxisIndex: 1, + yAxisIndex: 1, + name: '5分钟', + type: 'line', + lineStyle: { + normal: { + width: 2, + color: 'rgb(0, 178, 45)' + } + }, + itemStyle: { + normal: { + color: 'rgb(0, 178, 45)' + } + }, + data: aData }, - data: bData + { + xAxisIndex: 1, + yAxisIndex: 1, + name: '15分钟', + type: 'line', + lineStyle: { + normal: { + width: 2, + color: 'rgb(147, 38, 255)' + } + }, + itemStyle: { + normal: { + color: 'rgb(147, 38, 255)' + } + }, + data: bData + } + ], + textStyle: { + color: '#666', + fontSize: 12 } - ], - textStyle: { - color: '#666', - fontSize: 12 } - } - myChartgetload.setOption(option); - window.addEventListener("resize",function(){ - myChartgetload.resize(); - }) - }) + myChartgetload.setOption(option); + window.addEventListener("resize",function(){ + myChartgetload.resize(); + }) + },'json') } \ No newline at end of file diff --git a/task.py b/task.py index 7d72dc5e2..1593ca6ac 100755 --- a/task.py +++ b/task.py @@ -6,8 +6,10 @@ import sys import os import json -# import psutil import time +print sys.path +sys.path.append("/usr/local/lib/python2.7/site-packages") +import psutil sys.path.append(os.getcwd() + "/class/core") reload(sys) @@ -303,13 +305,13 @@ def systemTask(): 'up,down,total_up,total_down,down_packets,up_packets,addtime', data) sql.table('network').where( "addtime区间检索: 昨天 今天 - 最近30天 - 自定义时间 + 最近7天 + 最近30天
自定义时间