From e80f1c84804ad0a7072bbc6d667b0b4283007d18 Mon Sep 17 00:00:00 2001 From: Newnius Date: Mon, 29 Apr 2019 21:04:19 +0800 Subject: [PATCH] update UI, add pool status --- ajax.php | 4 + job.logic.php | 22 +++++ static/resource.js | 4 +- static/summary.js | 206 +++++++++++++++++++++++++++------------------ 4 files changed, 153 insertions(+), 83 deletions(-) diff --git a/ajax.php b/ajax.php index 5b682d5..fa33431 100644 --- a/ajax.php +++ b/ajax.php @@ -99,6 +99,10 @@ switch ($action) { $res = summary_get(); break; + case 'summary_get_pool_history': + $res = summary_get_pool_history(); + break; + case 'task_logs': $task = new CRObject(); $task->set('job', cr_get_GET('job')); diff --git a/job.logic.php b/job.logic.php index f6a25ee..09587e4 100644 --- a/job.logic.php +++ b/job.logic.php @@ -171,6 +171,28 @@ function summary_get() return $res; } +function summary_get_pool_history() +{ + if (!AccessController::hasAccess(Session::get('role', 'visitor'), 'system.summary')) { + $res['errno'] = Code::NO_PRIVILEGE; + return $res; + } + + $spider = new Spider(); + $spider->doGet(YAO_SCHEDULER_ADDR . '?action=pool_status_history'); + $msg = json_decode($spider->getBody(), true); + + if ($msg['code'] !== 0) { + $res['errno'] = $msg['code'] !== null ? $msg['code'] : Code::UNKNOWN_ERROR; + $res['msg'] = $msg['error']; + return $res; + } + + $res['data'] = $msg['data']; + $res['errno'] = Code::SUCCESS; + return $res; +} + function task_logs(CRObject $job) { if (!AccessController::hasAccess(Session::get('role', 'visitor'), 'job.list')) { diff --git a/static/resource.js b/static/resource.js index 3e086ec..2b6dc76 100755 --- a/static/resource.js +++ b/static/resource.js @@ -72,8 +72,8 @@ function resourceResponseHandler(res) { $.each(res["resources"], function (i, node) { var item = { 'host': node.host, - 'CPU': '-', - 'MEM': '-', + 'CPU': node.cpu_num, + 'MEM': node.mem_available + ' / ' + node.mem_total + ' (GB)', 'GPU': node.status.length, 'status': node.status }; diff --git a/static/summary.js b/static/summary.js index 8501c78..21ddbe2 100644 --- a/static/summary.js +++ b/static/summary.js @@ -21,32 +21,6 @@ function summary_render() { $("#modal-msg").modal('show'); } - /* CPU Load */ - ctx_cpu.canvas.height = 200; - new Chart(ctx_cpu, { - "type": "line", - "data": { - "labels": ["January", "February", "March", "April", "May", "June", "July"], - "datasets": [{ - "label": "My First Data set", - "data": [2, 0.5, 1.5, 0.81, 1.56, 1.55, 1.40], - "fill": true, - "borderColor": "rgb(75, 192, 192)", - "lineTension": 0.1 - }] - }, - "options": { - title: { - display: true, - text: 'GPU Load' - }, - legend: { - display: false - }, - maintainAspectRatio: false - } - }); - /* Jobs */ var data = { @@ -72,58 +46,6 @@ function summary_render() { } }); - /* Mem Using */ - ctx_mem.canvas.height = 200; - new Chart(ctx_mem, { - "type": "line", - "data": { - "labels": ["January", "February", "March", "April", "May", "June", "July"], - "datasets": [{ - "label": "My First Data set", - "data": [2, 0.5, 1.5, 0.81, 1.56, 1.55, 1.40], - "fill": true, - "borderColor": "rgb(75, 192, 192)", - "lineTension": 0.1 - }] - }, - "options": { - title: { - display: true, - text: 'MEM Using' - }, - legend: { - display: false - }, - maintainAspectRatio: false - } - }); - - /* GPU Util */ - ctx_gpu_util.canvas.height = 200; - new Chart(ctx_gpu_util, { - "type": "line", - "data": { - "labels": ["January", "February", "March", "April", "May", "June", "July"], - "datasets": [{ - "label": "My First Data set", - "data": [2, 0.5, 1.5, 0.81, 1.56, 1.55, 1.40], - "fill": true, - "borderColor": "rgb(75, 192, 192)", - "lineTension": 0.1 - }] - }, - "options": { - title: { - display: true, - text: 'GPU Utilization' - }, - legend: { - display: false - }, - maintainAspectRatio: false - } - }); - /* GPUs */ var data2 = { datasets: [{ @@ -148,16 +70,138 @@ function summary_render() { } }); + }); + ajax.fail(function (jqXHR, textStatus) { + $("#modal-msg-content").html("Request failed : " + jqXHR.statusText); + $("#modal-msg").modal('show'); + }); + + + var ajax_pool = $.ajax({ + url: window.config.BASE_URL + "/service?action=summary_get_pool_history", + type: 'GET', + data: {} + }); + ajax_pool.done(function (res) { + if (res["errno"] !== 0) { + $("#modal-msg-content").html(res["msg"]); + $("#modal-msg").modal('show'); + } + + var cpu_util = []; + var cpu_total = []; + var mem_available = []; + var mem_total = []; + var mem_using = []; + var gpu_util = []; + var gpu_total = []; + var gpu_mem_available = []; + var gpu_mem_total = []; + var gpu_mem_using = []; + var timestamps = []; + $.each(res["data"], function (i, item) { + cpu_util.push(item['cpu_util'].toFixed(2)); + cpu_total.push(item['cpu_total']); + mem_available.push(item['mem_available']); + mem_total.push(item['mem_total']); + mem_using.push(item['mem_total'] - item['mem_available']); + gpu_util.push(item['gpu_util']); + gpu_total.push(item['gpu_total']); + gpu_mem_available.push(item['gpu_mem_available']); + gpu_mem_total.push(item['gpu_mem_total']); + gpu_mem_using.push(item['gpu_mem_total'] - item['gpu_mem_available']); + timestamps.push(item['ts']); + }); + + /* CPU Load */ + ctx_cpu.canvas.height = 200; + new Chart(ctx_cpu, { + "type": "line", + "data": { + "labels": timestamps, + "datasets": [{ + "label": "My First Data set", + "data": cpu_util, + "fill": true, + "borderColor": "rgb(75, 192, 192)", + "lineTension": 0.1 + }] + }, + "options": { + title: { + display: true, + text: 'CPU Load' + }, + legend: { + display: false + }, + maintainAspectRatio: false + } + }); + + + /* Mem Using */ + ctx_mem.canvas.height = 200; + new Chart(ctx_mem, { + "type": "line", + "data": { + "labels": timestamps, + "datasets": [{ + "label": "My First Data set", + "data": mem_using, + "fill": true, + "borderColor": "rgb(75, 192, 192)", + "lineTension": 0.1 + }] + }, + "options": { + title: { + display: true, + text: 'MEM Using' + }, + legend: { + display: false + }, + maintainAspectRatio: false + } + }); + + /* GPU Util */ + ctx_gpu_util.canvas.height = 200; + new Chart(ctx_gpu_util, { + "type": "line", + "data": { + "labels": timestamps, + "datasets": [{ + "label": "My First Data set", + "data": gpu_util, + "fill": true, + "borderColor": "rgb(75, 192, 192)", + "lineTension": 0.1 + }] + }, + "options": { + title: { + display: true, + text: 'GPU Utilization' + }, + legend: { + display: false + }, + maintainAspectRatio: false + } + }); + /* GPU Mem Using */ ctx_gpu_mem.canvas.height = 200; new Chart(ctx_gpu_mem, { "type": "line", "data": { - "labels": ["January", "February", "March", "April", "May", "June", "July"], + "labels": timestamps, "datasets": [{ "label": "My First Data set", - "data": [2, 0.5, 1.5, 0.81, 1.56, 1.55, 1.40], + "data": gpu_mem_using, "fill": true, "borderColor": "rgb(75, 192, 192)", "lineTension": 0.1 @@ -175,7 +219,7 @@ function summary_render() { } }); }); - ajax.fail(function (jqXHR, textStatus) { + ajax_pool.fail(function (jqXHR, textStatus) { $("#modal-msg-content").html("Request failed : " + jqXHR.statusText); $("#modal-msg").modal('show'); });