mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 23:30:41 +09:00
Data collection related to storage IO and graphing
This commit is contained in:
1 parent
994bd09fa7
commit
e91c25557e
10 files changed
+783
-348
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
||||
<title>Clusterio</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
<script src="https://code.jquery.com/jquery.js"></script>
|
||||
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
|
||||
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/canvasjs/1.7.0/canvasjs.js" type="text/javascript"></script>
|
||||
<script src="http://momentjs.com/downloads/moment.min.js" type="text/javascript"></script>
|
||||
<script src="main.js"></script>
|
||||
|
||||
+5
-1
@@ -13,7 +13,11 @@
|
||||
<div id="contents">
|
||||
<table><tbody><!-- populated by js --></tbody></table>
|
||||
</div>
|
||||
<canvas id="contentGraph" width="200" height="200"></canvas>
|
||||
</div>
|
||||
<div id="graphDisplay">
|
||||
<div id="storageGraphContainer">
|
||||
<div id="contentGraph" class="storageGraph" style="width: 100%;"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
@@ -34,6 +34,58 @@ function djb2(str){
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
// callback(err, json)
|
||||
function getJSON(url, callback) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.responseType = 'json';
|
||||
xhr.onload = function() {
|
||||
var status = xhr.status;
|
||||
if (status == 200) {
|
||||
callback(null, xhr.response);
|
||||
} else {
|
||||
callback(status);
|
||||
}
|
||||
};
|
||||
// triggers if connection is refused
|
||||
xhr.onerror = function(e){
|
||||
callback(e);
|
||||
};
|
||||
xhr.send();
|
||||
};
|
||||
// callback(err, json)
|
||||
function postJSON(url, data, callback) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', url, true);
|
||||
xhr.responseType = 'json';
|
||||
xhr.onload = function() {
|
||||
var status = xhr.status;
|
||||
if (status == 200) {
|
||||
callback(null, xhr.response);
|
||||
} else {
|
||||
callback(status);
|
||||
}
|
||||
};
|
||||
// triggers if connection is refused
|
||||
xhr.onerror = function(e){
|
||||
callback(e);
|
||||
};
|
||||
xhr.send(data);
|
||||
};
|
||||
// return Boolean
|
||||
function isJSON(string){
|
||||
let stringIsJson = false;
|
||||
let x
|
||||
try {
|
||||
x = JSON.parse(string);
|
||||
} catch (e){
|
||||
return false;
|
||||
}
|
||||
if(typeof x == "object" || typeof string == "object"){
|
||||
stringIsJson = true;
|
||||
}
|
||||
return stringIsJson;
|
||||
}
|
||||
// hash a string to a color
|
||||
function hashColor(str) {
|
||||
var hash = djb2(str);
|
||||
|
||||
+4
-22
@@ -12,25 +12,6 @@ function post(url, data, callback) {
|
||||
}
|
||||
xhr.send(JSON.stringify(data));
|
||||
}
|
||||
// callback(err, json)
|
||||
function getJSON(url, callback) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.responseType = 'json';
|
||||
xhr.onload = function() {
|
||||
var status = xhr.status;
|
||||
if (status == 200) {
|
||||
callback(null, xhr.response);
|
||||
} else {
|
||||
callback(status);
|
||||
}
|
||||
};
|
||||
// triggers if connection is refused
|
||||
xhr.onerror = function(e){
|
||||
callback(e);
|
||||
};
|
||||
xhr.send();
|
||||
};
|
||||
// function to sort arrays of objects after a keys value
|
||||
function sortByKey(array, key) {
|
||||
return array.sort(function(a, b) {
|
||||
@@ -71,6 +52,7 @@ setInterval(function(){
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
populateSlaveInfo();
|
||||
function populateSlaveInfo(){
|
||||
let slaveID = getParameterByName("slaveID");
|
||||
if(!slaveID){
|
||||
@@ -241,7 +223,6 @@ function maximizeTerminal(instant){
|
||||
setTimeout(() => $('#terminal')[0].style.transition = 'none', (Number(instant) || 200));
|
||||
$('#terminal').draggable('enable');
|
||||
}
|
||||
populateSlaveInfo();
|
||||
|
||||
// ID of slave, ID of canvasjs div without #
|
||||
function makeGraph(slaveID, selector) {
|
||||
@@ -301,7 +282,7 @@ function drawChart(selector, chartData) {
|
||||
console.log(chartData)
|
||||
chartsByID[selector] = new CanvasJS.Chart(selector, {
|
||||
title:{
|
||||
text: "Production graph"
|
||||
text: title || "Production graph"
|
||||
},
|
||||
toolTip:{
|
||||
content: "{name}: {y}"
|
||||
@@ -328,4 +309,5 @@ function drawChart(selector, chartData) {
|
||||
chart = chartsByID[selector];
|
||||
// console.log(chart)
|
||||
chart.render();
|
||||
}
|
||||
return chart;
|
||||
}
|
||||
+101
-1
@@ -32,6 +32,9 @@ function drawcontents(data) {
|
||||
const name = row.querySelector('.name');
|
||||
if(name.textContent !== item.name) {
|
||||
name.textContent = item.name;
|
||||
row.onclick = ()=>{
|
||||
makeItemGraphs(item.name);
|
||||
}
|
||||
}
|
||||
|
||||
const count = row.querySelector('.count');
|
||||
@@ -73,4 +76,101 @@ function sortByKey(array, key) {
|
||||
|
||||
document.querySelector("#search").addEventListener('input', function() {
|
||||
drawcontents();
|
||||
})
|
||||
});
|
||||
|
||||
// Make graph of cluster IO items
|
||||
/*getJSON("/api/getStats", function(err, data){
|
||||
|
||||
}*/
|
||||
function getItemStatData(item, callback){
|
||||
var xhr = new XMLHttpRequest();
|
||||
var url = "/api/getStats";
|
||||
xhr.open("POST", url, true);
|
||||
xhr.setRequestHeader("Content-type", "application/json");
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
var json = JSON.parse(xhr.responseText);
|
||||
console.log(json.email + ", " + json.password);
|
||||
callback(json);
|
||||
}
|
||||
};
|
||||
var requestData = JSON.stringify({
|
||||
"statistic": "place",
|
||||
"itemName": "shit",
|
||||
});
|
||||
xhr.send(data);
|
||||
}
|
||||
////// drawChart("contentGraph", /api/getStats)
|
||||
|
||||
|
||||
function makeItemGraphs(itemName){
|
||||
getJSON("/api/slaves", function(err, slaves){
|
||||
if(err) throw err;
|
||||
if(typeof slaves == "string"){
|
||||
slaves = JSON.parse(slaves);
|
||||
}
|
||||
let slaveIDs = Object.keys(slaves);
|
||||
let HTML = ""
|
||||
// Draw in/out chart for unregistered slaves as well
|
||||
slaveIDs.unshift("unknown");
|
||||
slaveIDs.forEach(function(slaveID){
|
||||
["place", "remove"].forEach(statistic => {
|
||||
console.log("Making chart for "+slaveID+"'s "+statistic+" statistic")
|
||||
HTML += '<div id="contentGraph'+slaveID+'" class="storageGraph" style="width: 100%;"></div>';
|
||||
|
||||
setTimeout(function(){
|
||||
let xmlhttp = new XMLHttpRequest(); // new HttpRequest instance
|
||||
xmlhttp.open("POST", "/api/getStats");
|
||||
xmlhttp.setRequestHeader("Content-Type", "application/json");
|
||||
xmlhttp.onreadystatechange = function(){
|
||||
console.log(xmlhttp.status);
|
||||
if(xmlhttp.readyState === XMLHttpRequest.DONE && xmlhttp.status === 200) {
|
||||
// console.log(xmlhttp.responseText);
|
||||
if(isJSON(xmlhttp.responseText) && JSON.parse(xmlhttp.responseText).statusForDebugging === undefined){
|
||||
drawChart("contentGraph"+slaveID, [JSON.parse(xmlhttp.response).data]);
|
||||
console.log(JSON.parse(xmlhttp.response).data)
|
||||
}
|
||||
}
|
||||
}
|
||||
xmlhttp.send(JSON.stringify({statistic:statistic, itemName:itemName, slaveID:slaveID}));
|
||||
},1000);
|
||||
});
|
||||
});
|
||||
document.querySelector("#graphDisplay > #storageGraphContainer").innerHTML = HTML;
|
||||
});
|
||||
}
|
||||
let chartsByID = {};
|
||||
function drawChart(selector, chartData, title) {
|
||||
// selector is ID of element, ex "chartContainer" or "-123199123"
|
||||
console.log(chartData)
|
||||
chartsByID[selector] = new CanvasJS.Chart(selector, {
|
||||
title:{
|
||||
text: title || "Production graph"
|
||||
},
|
||||
toolTip:{
|
||||
content: "{name}: {y}"
|
||||
},
|
||||
zoomEnabled: true,
|
||||
axisY:{
|
||||
includeZero: true,
|
||||
},
|
||||
legend: {
|
||||
cursor: "pointer",
|
||||
itemclick: function (e) {
|
||||
//console.log("legend click: " + e.dataPointIndex);
|
||||
//console.log(e);
|
||||
if (typeof (e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
|
||||
e.dataSeries.visible = false;
|
||||
} else {
|
||||
e.dataSeries.visible = true;
|
||||
}
|
||||
e.chart.render();
|
||||
}
|
||||
},
|
||||
data: chartData
|
||||
});
|
||||
chart = chartsByID[selector];
|
||||
// console.log(chart)
|
||||
chart.render();
|
||||
return chart;
|
||||
}
|
||||
@@ -19,10 +19,21 @@ button {
|
||||
background-color: #262626;
|
||||
color: #C8C8C8;
|
||||
}
|
||||
#storage {
|
||||
float: left;
|
||||
}
|
||||
/* search field */
|
||||
#storage > input {
|
||||
background-color:black;
|
||||
width:300px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
/* Graphs on the right of storage page */
|
||||
#body > #graphDisplay {
|
||||
float:left;
|
||||
width: calc(100% - 300px);
|
||||
min-height:100px;
|
||||
background-color: red;
|
||||
}
|
||||
/* Navbar on the right */
|
||||
#sidenav {
|
||||
|
||||
Reference in new issue
Block a user