1
0
mirror of https://github.com/newnius/YAO-portal.git synced 2025-06-06 23:21:55 +00:00
YAO-portal/static/summary.js

234 lines
5.0 KiB
JavaScript
Raw Permalink Normal View History

2019-04-03 12:26:25 +00:00
function register_events_summary() {
}
function summary_render() {
var ctx_cpu = document.getElementById('summary-chart-cpu').getContext('2d');
var ctx_mem = document.getElementById('summary-chart-mem').getContext('2d');
var ctx_jobs = document.getElementById('summary-chart-jobs').getContext('2d');
var ctx_gpu = document.getElementById('summary-chart-gpu').getContext('2d');
2019-04-23 08:57:15 +00:00
var ctx_gpu_util = document.getElementById('summary-chart-gpu-util').getContext('2d');
var ctx_gpu_mem = document.getElementById('summary-chart-gpu-mem').getContext('2d');
2019-04-03 12:26:25 +00:00
var ajax = $.ajax({
2019-05-06 06:56:40 +00:00
url: "service?action=summary_get",
2019-04-03 12:26:25 +00:00
type: 'GET',
data: {}
});
ajax.done(function (res) {
if (res["errno"] !== 0) {
$("#modal-msg-content").html(res["msg"]);
$("#modal-msg").modal('show');
}
2019-04-23 08:57:15 +00:00
/* Jobs */
2019-04-03 12:26:25 +00:00
var data = {
datasets: [{
data: Object.values(res['jobs']),
backgroundColor: ["rgb(54, 162, 235)", "rgb(255, 99, 132)", "rgb(255, 205, 86)"]
}],
labels: Object.keys(res['jobs'])
};
var myPieChart = new Chart(ctx_jobs, {
type: 'pie',
data: data,
options: {
2019-04-23 08:57:15 +00:00
title: {
display: true,
text: 'Jobs'
},
2019-04-03 12:26:25 +00:00
legend: {
display: false
}
}
});
2019-04-29 13:04:19 +00:00
/* GPUs */
var data2 = {
datasets: [{
data: Object.values(res['gpu']),
backgroundColor: ["rgb(54, 162, 235)", "rgb(255, 99, 132)"]
}],
labels: Object.keys(res['gpu'])
};
var myPieChart2 = new Chart(ctx_gpu, {
type: 'pie',
data: data2,
options: {
title: {
display: true,
text: 'GPUs'
},
legend: {
display: false
}
}
});
});
ajax.fail(function (jqXHR, textStatus) {
$("#modal-msg-content").html("Request failed : " + jqXHR.statusText);
$("#modal-msg").modal('show');
});
var ajax_pool = $.ajax({
2019-05-06 06:56:40 +00:00
url: "service?action=summary_get_pool_history",
2019-04-29 13:04:19 +00:00
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']);
2019-05-20 07:36:49 +00:00
timestamps.push(moment(item['ts']).format('HH:mm:ss'));
2019-04-29 13:04:19 +00:00
});
/* CPU Load */
ctx_cpu.canvas.height = 200;
new Chart(ctx_cpu, {
2019-04-23 08:57:15 +00:00
"type": "line",
"data": {
2019-04-29 13:04:19 +00:00
"labels": timestamps,
2019-04-23 08:57:15 +00:00
"datasets": [{
2019-05-06 06:56:40 +00:00
"label": "CPU Load",
2019-04-29 13:04:19 +00:00
"data": cpu_util,
2019-04-23 08:57:15 +00:00
"fill": true,
"borderColor": "rgb(75, 192, 192)",
"lineTension": 0.1
}]
},
"options": {
title: {
display: true,
2019-04-29 13:04:19 +00:00
text: 'CPU Load'
2019-04-23 08:57:15 +00:00
},
legend: {
display: false
},
maintainAspectRatio: false
}
});
2019-04-29 13:04:19 +00:00
/* Mem Using */
ctx_mem.canvas.height = 200;
new Chart(ctx_mem, {
2019-04-23 08:57:15 +00:00
"type": "line",
"data": {
2019-04-29 13:04:19 +00:00
"labels": timestamps,
2019-04-23 08:57:15 +00:00
"datasets": [{
2019-05-06 06:56:40 +00:00
"label": "Using",
2019-04-29 13:04:19 +00:00
"data": mem_using,
2019-04-23 08:57:15 +00:00
"fill": true,
"borderColor": "rgb(75, 192, 192)",
"lineTension": 0.1
2019-05-06 06:56:40 +00:00
}, {
"label": "Total",
"data": mem_total,
"fill": true,
"borderColor": "rgb(75, 192, 192)",
"lineTension": 0.1
2019-04-23 08:57:15 +00:00
}]
},
"options": {
title: {
display: true,
2019-04-29 13:04:19 +00:00
text: 'MEM Using'
2019-04-23 08:57:15 +00:00
},
legend: {
2019-05-20 07:34:35 +00:00
display: false
2019-04-23 08:57:15 +00:00
},
maintainAspectRatio: false
}
});
2019-04-29 13:04:19 +00:00
/* GPU Util */
ctx_gpu_util.canvas.height = 200;
new Chart(ctx_gpu_util, {
"type": "line",
"data": {
"labels": timestamps,
"datasets": [{
2019-05-06 06:56:40 +00:00
"label": "GPU Util",
2019-04-29 13:04:19 +00:00
"data": gpu_util,
"fill": true,
"borderColor": "rgb(75, 192, 192)",
"lineTension": 0.1
}]
},
"options": {
2019-04-23 08:57:15 +00:00
title: {
display: true,
2019-04-29 13:04:19 +00:00
text: 'GPU Utilization'
2019-04-23 08:57:15 +00:00
},
2019-04-03 12:26:25 +00:00
legend: {
display: false
2019-04-29 13:04:19 +00:00
},
maintainAspectRatio: false
2019-04-03 12:26:25 +00:00
}
});
2019-04-23 08:57:15 +00:00
/* GPU Mem Using */
ctx_gpu_mem.canvas.height = 200;
new Chart(ctx_gpu_mem, {
"type": "line",
"data": {
2019-04-29 13:04:19 +00:00
"labels": timestamps,
2019-04-23 08:57:15 +00:00
"datasets": [{
2019-05-06 06:56:40 +00:00
"label": "Using",
2019-04-29 13:04:19 +00:00
"data": gpu_mem_using,
2019-04-23 08:57:15 +00:00
"fill": true,
"borderColor": "rgb(75, 192, 192)",
"lineTension": 0.1
2019-05-06 06:56:40 +00:00
}, {
"label": "Total",
"data": gpu_mem_total,
"fill": true,
"borderColor": "rgb(75, 192, 192)",
"lineTension": 0.1
2019-04-23 08:57:15 +00:00
}]
},
"options": {
title: {
display: true,
text: 'GPU MEM Using'
},
legend: {
display: false
},
maintainAspectRatio: false
}
});
2019-04-03 12:26:25 +00:00
});
2019-04-29 13:04:19 +00:00
ajax_pool.fail(function (jqXHR, textStatus) {
2019-04-03 12:26:25 +00:00
$("#modal-msg-content").html("Request failed : " + jqXHR.statusText);
$("#modal-msg").modal('show');
});
}