Commit 6ab46729 authored by Vladislav Gumerov's avatar Vladislav Gumerov

added charts

parent 48f0843a
......@@ -3,7 +3,9 @@
"version": "0.0.1",
"description": "test task for Etersoft",
"main": "index.js",
"dependencies": {},
"dependencies": {
"chart.js": "^2.7.3"
},
"devDependencies": {
"gulp": "^4.0.0",
"@babel/core": "^7.2.2",
......
<?php
$cpu = shell_exec('ps aux | awk \'{s += $3} END {print s "%"}\'');
$cpu = shell_exec('ps aux | awk \'{s += $3} END {print s }\'');
$total_mem = shell_exec("cat /proc/meminfo | grep MemTotal | awk '{ print $2 }' ");
$free_mem = shell_exec("cat /proc/meminfo | grep MemFree | awk '{ print $2 }' ");
$free_mem = shell_exec("cat /proc/meminfo | grep Cached | awk '{ print $2 }' ");
$average1 = shell_exec("uptime | awk '{ print $10 }' ");
$average2 = shell_exec("uptime | awk '{ print $11 }' ");
$average3 = shell_exec("uptime | awk '{ print $12 }' ");
$arr = array('CPI' => trim($cpu),
$arr = array('CPU' => trim($cpu),
'TotalMemory' => trim($total_mem),
'FreeMemory' => trim($free_mem),
"5minute" => substr(trim($average1), 0, -1),
"10minute" => substr(trim($average2), 0, -1),
"1minute" => substr(trim($average1), 0, -1),
"5minute" => substr(trim($average2), 0, -1),
"15minute" => substr(trim($average3), 0, -1));
exit (json_encode($arr));
......
table{font-family:"Lucida Sans Unicode","Lucida Grande",Sans-Serif;font-size:14px;border-collapse:collapse;text-align:center}td:first-child,th{background:#AFCDE7;color:#fff;padding:10px 20px}td,th{border-style:solid;border-width:0 1px 1px 0;border-color:#fff}td{background:#D8E6F3}td:first-child,th:first-child{text-align:left}
\ No newline at end of file
table{width:50%;font-family:"Lucida Sans Unicode","Lucida Grande",Sans-Serif;font-size:14px;border-collapse:collapse;text-align:center}td:first-child,th{background:#AFCDE7;color:#fff;padding:10px 20px}td,th{border-style:solid;border-width:0 1px 1px 0;border-color:#fff}td{background:#D8E6F3}.canvas-block{width:500px;height:500px}
\ No newline at end of file
......@@ -10,9 +10,14 @@
<body>
<div id="root">
</div>
<div class='canvas-block'>
<canvas id="cpuChart"></canvas>
<canvas id="memoryChart"></canvas>
</div>
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>
<script src="js/index.js"></script>
</body>
</html>
\ No newline at end of file
function App(e){return React.createElement("table",{className:"system-load-table",width:"100%"},React.createElement("tbody",null,React.createElement("tr",{className:"first_row"},React.createElement("th",null,"CPU"),React.createElement("th",null,"Total memory"),React.createElement("th",null,"Free memory"),React.createElement("th",null,"5 minute"),React.createElement("th",null,"10 minute"),React.createElement("th",null,"15 minute")),React.createElement("tr",{className:"second-row"},React.createElement("th",null,e.data.CPI),React.createElement("th",null,(e.data.TotalMemory/1024).toFixed(2)+" МБ"),React.createElement("th",null,(e.data.FreeMemory/1024).toFixed(2)+" МБ"),React.createElement("th",null,e.data["5minute"]),React.createElement("th",null,e.data["10minute"]),React.createElement("th",null,e.data["15minute"]))))}setInterval(function(){$.get("core/data.php",function(e){e=JSON.parse(e),ReactDOM.render(React.createElement(App,{data:e}),document.getElementById("root"))})},500);
\ No newline at end of file
var cpuCtx=document.getElementById("cpuChart").getContext("2d"),memoryCtx=document.getElementById("memoryChart").getContext("2d");let time=performance.now();var cpuData=[],memoryData=[],timeData=[],cpuChart=new Chart(cpuCtx,{type:"line",data:{labels:timeData,datasets:[{label:"CPU",backgroundColor:"rgb(255, 99, 132)",borderColor:"rgb(255, 99, 132)",data:cpuData}]},options:{}}),memoryChart=new Chart(memoryCtx,{type:"line",data:{labels:timeData,datasets:[{label:"Free memory",backgroundColor:"rgb(255, 99, 132)",borderColor:"rgb(255, 99, 132)",data:memoryData}]},options:{}});function App(e){return React.createElement("table",{className:"system-load-table"},React.createElement("tbod",null,React.createElement("tr",{className:"first_row"},React.createElement("th",null,"CPU"),React.createElement("th",null,"Total memory"),React.createElement("th",null,"Free memory"),React.createElement("th",null,"1 minute"),React.createElement("th",null,"5 minute"),React.createElement("th",null,"15 minute")),React.createElement("tr",{className:"second-row"},React.createElement("th",null,e.data.CPU),React.createElement("th",null,(e.data.TotalMemory/1024).toFixed(2)+" МБ"),React.createElement("th",null,(e.data.FreeMemory/1024).toFixed(2)+" МБ"),React.createElement("th",null,e.data["1minute"]),React.createElement("th",null,e.data["5minute"]),React.createElement("th",null,e.data["15minute"]))))}setInterval(function(){$.get("core/data.php",function(e){e=JSON.parse(e),cpuData.push(e.CPU/1),memoryData.push((e.FreeMemory/1024).toFixed(2)),timeData.push(((performance.now()-time)/1e3).toFixed(2)),cpuChart.update(),memoryChart.update(),ReactDOM.render(React.createElement(App,{data:e}),document.getElementById("root"))})},400);
\ No newline at end of file
<?php
$cpu = shell_exec('ps aux | awk \'{s += $3} END {print s "%"}\'');
$cpu = shell_exec('ps aux | awk \'{s += $3} END {print s }\'');
$total_mem = shell_exec("cat /proc/meminfo | grep MemTotal | awk '{ print $2 }' ");
$free_mem = shell_exec("cat /proc/meminfo | grep MemFree | awk '{ print $2 }' ");
$free_mem = shell_exec("cat /proc/meminfo | grep Cached | awk '{ print $2 }' ");
$average1 = shell_exec("uptime | awk '{ print $10 }' ");
$average2 = shell_exec("uptime | awk '{ print $11 }' ");
$average3 = shell_exec("uptime | awk '{ print $12 }' ");
$arr = array('CPI' => trim($cpu),
$arr = array('CPU' => trim($cpu),
'TotalMemory' => trim($total_mem),
'FreeMemory' => trim($free_mem),
"5minute" => substr(trim($average1), 0, -1),
"10minute" => substr(trim($average2), 0, -1),
"1minute" => substr(trim($average1), 0, -1),
"5minute" => substr(trim($average2), 0, -1),
"15minute" => substr(trim($average3), 0, -1));
exit (json_encode($arr));
......
table {
width: 50%;
font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
font-size: 14px;
border-collapse: collapse;
......@@ -17,6 +18,9 @@ th, td {
td {
background: #D8E6F3;
}
th:first-child, td:first-child {
text-align: left;
}
\ No newline at end of file
.canvas-block {
width: 500px;
height: 500px;
}
var cpuCtx = document.getElementById('cpuChart').getContext('2d');
var memoryCtx = document.getElementById('memoryChart').getContext('2d');
let time = performance.now();
var cpuData = [];
var memoryData = [];
var timeData = [];
var cpuChart = new Chart(cpuCtx, {
type: 'line',
data: {
labels: timeData,
datasets: [{
label: "CPU",
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: cpuData,
}]
},
// Configuration options go here
options: {}
});
var memoryChart = new Chart(memoryCtx, {
type: 'line',
data: {
labels: timeData,
datasets: [{
label: "Free memory",
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: memoryData,
}]
},
// Configuration options go here
options: {}
});
function App(props) {
return (
<table className="system-load-table" width="100%">
<tbody>
<table className="system-load-table">
<tbod>
<tr className="first_row">
<th>CPU</th>
<th>Total memory</th>
<th>Free memory</th>
<th>1 minute</th>
<th>5 minute</th>
<th>10 minute</th>
<th>15 minute</th>
</tr>
<tr className="second-row">
<th>{props.data['CPI']}</th>
<th>{props.data['CPU']}</th>
<th>{(props.data['TotalMemory'] / 1024).toFixed(2) + ' МБ'}</th>
<th>{(props.data['FreeMemory'] / 1024).toFixed(2) + ' МБ'}</th>
<th>{props.data['1minute']}</th>
<th>{props.data['5minute']}</th>
<th>{props.data['10minute']}</th>
<th>{props.data['15minute']}</th>
</tr>
</tbody>
</tbod>
</table>
);
}
......@@ -26,9 +67,14 @@ function App(props) {
setInterval(function () {
$.get('core/data.php', function (data) {
data = JSON.parse(data);
cpuData.push(data['CPU'] / 1);
memoryData.push((data['FreeMemory'] / 1024).toFixed(2));
timeData.push(((performance.now() - time) / 1000).toFixed(2));
cpuChart.update();
memoryChart.update();
ReactDOM.render(<App data={data}/>, document.getElementById('root'));
});
}, 500);
}, 400);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment