From 81e7ef14710849254a3981970bf75f95212537be Mon Sep 17 00:00:00 2001 From: midoks Date: Fri, 11 Jan 2019 00:09:06 +0800 Subject: [PATCH] update --- plugins/redis/index.py | 2 +- plugins/simdht/index.py | 46 +++++---- plugins/simdht/init.d/simdht.tpl | 2 +- plugins/simdht/js/simdht.js | 120 +++++++++++++++--------- plugins/simdht/workers/db.cfg | 6 +- plugins/simdht/workers/simdht_worker.py | 17 ++-- 6 files changed, 119 insertions(+), 74 deletions(-) diff --git a/plugins/redis/index.py b/plugins/redis/index.py index e9923904f..c7c918154 100755 --- a/plugins/redis/index.py +++ b/plugins/redis/index.py @@ -9,7 +9,7 @@ sys.path.append(os.getcwd() + "/class/core") import public app_debug = False -if public.getOs() == 'darwin': +if public.isAppleSystem(): app_debug = True diff --git a/plugins/simdht/index.py b/plugins/simdht/index.py index c6b199038..ac41424cc 100755 --- a/plugins/simdht/index.py +++ b/plugins/simdht/index.py @@ -11,6 +11,11 @@ sys.path.append(os.getcwd() + "/class/core") import public +app_debug = False +if public.isAppleSystem(): + app_debug = True + + def getPluginName(): return 'simdht' @@ -187,30 +192,37 @@ def isSqlError(mysqlMsg): return None -def getMinData(conn, min): +def getMinData(conn, smin): + time_diff = 0 + if public.isAppleSystem(): + time_diff = 3 * 60 + pre = time.strftime("%Y-%m-%d %H:%M:%S", - time.localtime(time.time() - min)) + time.localtime(time.time() - smin - time_diff)) sql = "select count(*) from search_hash where create_time > '" + pre + "'" data = conn.query(sql) return data[0][0] def getTrendData(): - import time - args = getArgs() - data = checkArgs(args, ['interval']) - if not data[0]: - return data[1] - pdb = pMysqlDb() - interval = int(args['interval']) - result = pdb.execute("show tables") - isError = isSqlError(result) - if isError: - return isError - one = getMinData(pdb, interval) - two = getMinData(pdb, interval * 2) - three = getMinData(pdb, interval * 3) - return public.getJson([one, two, three]) + try: + args = getArgs() + data = checkArgs(args, ['interval']) + if not data[0]: + return data[1] + pdb = pMysqlDb() + interval = int(args['interval']) + result = pdb.execute("show tables") + isError = isSqlError(result) + if isError: + return isError + one = getMinData(pdb, interval) + two = getMinData(pdb, interval * 2) + three = getMinData(pdb, interval * 3) + return public.getJson([one, two, three]) + except Exception as e: + return public.getJson([0, 0, 0]) + if __name__ == "__main__": func = sys.argv[1] diff --git a/plugins/simdht/init.d/simdht.tpl b/plugins/simdht/init.d/simdht.tpl index ed1473643..9479e81bf 100644 --- a/plugins/simdht/init.d/simdht.tpl +++ b/plugins/simdht/init.d/simdht.tpl @@ -15,7 +15,7 @@ dht_start(){ cd {$SERVER_PATH}/simdht/workers - nohup python simdht_worker.py >> {$SERVER_PATH}/simdht/logs.pl 2>&1 & + nohup python simdht_worker.py > {$SERVER_PATH}/simdht/logs.pl 2>&1 & } dht_stop(){ echo "Stopping ..." diff --git a/plugins/simdht/js/simdht.js b/plugins/simdht/js/simdht.js index 450053cfc..f61bc38e0 100755 --- a/plugins/simdht/js/simdht.js +++ b/plugins/simdht/js/simdht.js @@ -49,8 +49,9 @@ function dhtTrendData(callback){ function dhtTrendRender() { var myChartNetwork = echarts.init(document.getElementById('dht_trend')); var xData = []; - var yData = []; - var zData = []; + var oneData = []; + var twoData = []; + var threeData = []; function getTime() { var now = new Date(); @@ -78,39 +79,40 @@ function dhtTrendRender() { } function addData(data) { - console.log(data); + // console.log(data); + var rdata = $.parseJSON(data.data); xData.push(getTime()); - yData.push(data[0]); - zData.push(data[1]); - // if (shift) { - // xData.shift(); - // yData.shift(); - // zData.shift(); - // } + oneData.push(rdata[0]); + twoData.push(rdata[1]); + threeData.push(rdata[2]); + + xData.shift(); + oneData.shift(); + twoData.shift(); + threeData.shift(); } for (var i = 8; i >= 0; i--) { var time = (new Date()).getTime(); - xData.push(format(time - (i * 3 * 1000))); - yData.push(0); - zData.push(0); + xData.push(format(time - (i * 5 * 1000))); + oneData.push(0); + twoData.push(0); + threeData.push(0); } // 指定图表的配置项和数据 var option = { title: { - text: lan.index.interface_net, + text: '接口流量实时', left: 'center', textStyle: { - color: '#888888', - fontStyle: 'normal', - fontFamily: lan.index.net_font, - fontSize: 16, + color: '#888888',fontStyle: 'normal', + fontFamily: '宋体',fontSize: 16, } }, tooltip: { trigger: 'axis' }, legend: { - data: [lan.index.net_up, lan.index.net_down], + data: ['5s', '10s', '15s'], bottom: '2%' }, xAxis: { @@ -124,7 +126,7 @@ function dhtTrendRender() { } }, yAxis: { - name: lan.index.unit + 'KB/s', + name: '单位个数', splitLine: { lineStyle: { color: "#eee" @@ -137,38 +139,30 @@ function dhtTrendRender() { } }, series: [{ - name: lan.index.net_up, + name: '5s', type: 'line', - data: yData, + data: oneData, 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) + color: new echarts.graphic.LinearGradient(0, 0, 0, 1, + [{offset: 0,color: 'rgba(205, 51, 51,0.5)'}, + {offset: 1,color: 'rgba(205, 51, 51,0.8)'}], false) } }, itemStyle: { - normal: { - color: '#f7b851' - } + normal: {color: '#cd3333'} }, lineStyle: { - normal: { - width: 1 - } + normal: {width: 1} } }, { - name: lan.index.net_down, + name: '10s', type: 'line', - data: zData, + data: twoData, smooth: true, showSymbol: false, symbol: 'circle', @@ -185,9 +179,34 @@ function dhtTrendRender() { } }, itemStyle: { + normal: {color: '#52a9ff'} + }, + lineStyle: { normal: { - color: '#52a9ff' + width: 1 } + } + },{ + name: '15s', + type: 'line', + data: threeData, + 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: '#C6E2FF'} }, lineStyle: { normal: { @@ -196,23 +215,32 @@ function dhtTrendRender() { } }] }; - setInterval(function() { + + + // 使用刚指定的配置项和数据显示图表。 + myChartNetwork.setOption(option); + window.addEventListener("resize", function() { + myChartNetwork.resize(); + }); + + function render(){ dhtTrendData(function(data){ addData(data); }); myChartNetwork.setOption({ xAxis: {data: xData}, series: [ - {name: '5s',data: yData}, - {name: '10s',data: zData} + {name: '5s',data: oneData}, + {name: '10s',data: twoData}, + {name: '15s',data: threeData} ] }); + } + render(); + + setInterval(function() { + render(); }, 5000); - // 使用刚指定的配置项和数据显示图表。 - myChartNetwork.setOption(option); - window.addEventListener("resize", function() { - myChartNetwork.resize(); - }); } diff --git a/plugins/simdht/workers/db.cfg b/plugins/simdht/workers/db.cfg index fd7551686..bcfbe27b1 100755 --- a/plugins/simdht/workers/db.cfg +++ b/plugins/simdht/workers/db.cfg @@ -3,4 +3,8 @@ DB_HOST = 127.0.0.1 DB_USER = ssbc DB_PORT = 3306 DB_PASS = ssbc -DB_NAME = ssbc \ No newline at end of file +DB_NAME = ssbc + +[queue] +MAX_QUEUE_LT = 30 +MAX_QUEUE_PT = 200 \ No newline at end of file diff --git a/plugins/simdht/workers/simdht_worker.py b/plugins/simdht/workers/simdht_worker.py index 15d9af54e..bc5914b67 100755 --- a/plugins/simdht/workers/simdht_worker.py +++ b/plugins/simdht/workers/simdht_worker.py @@ -49,12 +49,12 @@ from metadata import save_metadata from configparser import ConfigParser cp = ConfigParser() cp.read("db.cfg") -section = cp.sections()[0] -DB_HOST = cp.get(section, "DB_HOST") -DB_USER = cp.get(section, "DB_USER") -DB_PORT = cp.getint(section, "DB_PORT") -DB_PASS = cp.get(section, "DB_PASS") -DB_NAME = cp.get(section, "DB_NAME") +section_db = cp.sections()[0] +DB_HOST = cp.get(section_db, "DB_HOST") +DB_USER = cp.get(section_db, "DB_USER") +DB_PORT = cp.getint(section_db, "DB_PORT") +DB_PASS = cp.get(section_db, "DB_PASS") +DB_NAME = cp.get(section_db, "DB_NAME") BLACK_FILE = 'black_list.txt' BOOTSTRAP_NODES = ( @@ -66,8 +66,9 @@ TID_LENGTH = 2 RE_JOIN_DHT_INTERVAL = 3 TOKEN_LENGTH = 2 -MAX_QUEUE_LT = 30 -MAX_QUEUE_PT = 200 +section_queue = cp.sections()[1] +MAX_QUEUE_LT = cp.getint(section_db, "MAX_QUEUE_LT") +MAX_QUEUE_PT = cp.getint(section_db, "MAX_QUEUE_PT") geoip = pygeoip.GeoIP('GeoIP.dat')