Skip to content
Snippets Groups Projects
Commit 70883dab authored by Tibo's avatar Tibo
Browse files

refactor sensors js code

parent f5ba9ab7
No related branches found
No related tags found
No related merge requests found
Pipeline #3828 passed
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
"laravel/helpers": "^1.2", "laravel/helpers": "^1.2",
"laravel/tinker": "~1.0", "laravel/tinker": "~1.0",
"mongodb/mongodb": "1.3.*", "mongodb/mongodb": "1.3.*",
"php-ai/php-ml": "^0.9.0",
"tdebatty/laravel-resource-generator": "^6.1" "tdebatty/laravel-resource-generator": "^6.1"
}, },
"require-dev": { "require-dev": {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "3030c52212d3e825435b5d8d49d078b2", "content-hash": "22a23f462add10e30e1d4f3f58b6fe65",
"packages": [ "packages": [
{ {
"name": "composer/ca-bundle", "name": "composer/ca-bundle",
...@@ -2036,6 +2036,60 @@ ...@@ -2036,6 +2036,60 @@
], ],
"time": "2018-07-02T15:55:56+00:00" "time": "2018-07-02T15:55:56+00:00"
}, },
{
"name": "php-ai/php-ml",
"version": "0.9.0",
"source": {
"type": "git",
"url": "https://gitlab.com/php-ai/php-ml.git",
"reference": "fd8b70629e16ed67307fe150ba25738449b9a6b2"
},
"dist": {
"type": "zip",
"url": "https://gitlab.com/api/v4/projects/php-ai%2Fphp-ml/repository/archive.zip?sha=fd8b70629e16ed67307fe150ba25738449b9a6b2",
"reference": "fd8b70629e16ed67307fe150ba25738449b9a6b2",
"shasum": ""
},
"require": {
"php": "^7.2"
},
"require-dev": {
"phpbench/phpbench": "^0.16.0",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"phpstan/phpstan-strict-rules": "^0.12",
"phpunit/phpunit": "^8.0",
"symplify/easy-coding-standard": "^6.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Phpml\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Arkadiusz Kondas",
"email": "arkadiusz.kondas@gmail.com"
}
],
"description": "PHP-ML - Machine Learning library for PHP",
"homepage": "https://github.com/php-ai/php-ml",
"keywords": [
"Neural network",
"artificial intelligence",
"computational learning theory",
"data science",
"feature extraction",
"machine learning",
"pattern recognition"
],
"time": "2020-05-27T09:52:59+00:00"
},
{ {
"name": "phpoption/phpoption", "name": "phpoption/phpoption",
"version": "1.7.4", "version": "1.7.4",
......
window.monitorIfconfigChart = function(element) {
var ctx = element.getContext('2d');
var config = {
type: 'line',
data: {
datasets: []
},
options: {
legend: {
display: true,
},
scales: {
xAxes: [{
type: 'time',
display: true,
scaleLabel: {
display: true,
labelString: 'Time'
}
}],
yAxes: [{
ticks: {
beginAtZero:true
},
scaleLabel: {
display: true,
labelString: '[Kbits / sec]'
}
}]
},
annotation: {
annotations: []
}
}
};
window.ifconfigChart = new Chart(ctx, config);
if (typeof window.monitorURL === 'undefined') {
window.monitorURL = "https://monitor.web-d.be";
}
var api_url = window.monitorURL + "/api/sensor/"
+ window.monitorServerID + "/" + window.monitorServerToken
+ "/ifconfig";
$.getJSON(api_url, function(data) {
$.each(data, function(key, dataset){
// console.log(dataset);
var new_color_name = window.colorNames[key];
var new_color = window.chartColors[new_color_name];
var new_dataset = {
label: dataset.name,
backgroundColor: "rgba(255, 255, 255, 0.0)", // transparent
borderColor: new_color,
data: dataset.points
};
config.data.datasets.push(new_dataset);
});
window.ifconfigChart.update();
});
};
\ No newline at end of file
window.monitorLoadChart = function(element) {
var ctx = element.getContext('2d');
var config = {
type: 'line',
data: {
datasets: []
},
options: {
legend: {
display: false,
},
scales: {
xAxes: [{
type: 'time',
display: true,
scaleLabel: {
display: true,
labelString: 'Time'
}
}],
yAxes: [{
ticks: {
beginAtZero:true
},
scaleLabel: {
display: true,
labelString: 'Load'
}
}]
},
annotation: {
annotations: []
}
}
};
window.loadChart = new Chart(ctx, config);
if (typeof window.monitorURL === 'undefined') {
window.monitorURL = "https://monitor.web-d.be";
}
var load_url = window.monitorURL + "/api/sensor/"
+ window.monitorServerID + "/" + window.monitorServerToken
+ "/load";
$.getJSON(load_url, function( data ) {
var new_dataset = {
label: 'Load',
data: data.points
};
config.data.datasets.push(new_dataset);
var new_annotation = {
drawTime: 'afterDraw', // overrides annotation.drawTime if set
type: 'line',
mode: 'horizontal',
scaleID: 'y-axis-0',
value: data.max,
borderColor: 'red',
borderWidth: 2
};
config.options.annotation.annotations.push(new_annotation);
window.loadChart.update();
});
};
\ No newline at end of file
window.monitorMemChart = function(element) {
var ctx = element.getContext('2d');
var config = {
type: 'line',
data: {
datasets: []
},
options: {
legend: {
display: true,
},
scales: {
xAxes: [{
type: 'time',
display: true,
scaleLabel: {
display: true,
labelString: 'Time'
}
}],
yAxes: [{
stacked: true,
ticks: {
beginAtZero:true
},
scaleLabel: {
display: true,
labelString: 'Memory [MB]'
}
}]
},
annotation: {
annotations: []
}
}
};
window.memChart = new Chart(ctx, config);
if (typeof window.monitorURL === 'undefined') {
window.monitorURL = "https://monitor.web-d.be";
}
var meminfo_url = window.monitorURL + "/api/sensor/"
+ window.monitorServerID + "/" + window.monitorServerToken
+ "/memory";
$.getJSON(meminfo_url, function(data) {
var new_dataset = {
label: 'Used',
backgroundColor: 'rgba(0, 178, 0, 0.3)',
borderColor: 'rgba(0, 178, 0, 0.3)',
data: data.used
};
config.data.datasets.push(new_dataset);
new_dataset = {
label: 'Cached',
backgroundColor: 'rgba(255, 165, 0, 0.3)',
borderColor: 'rgba(255, 165, 0, 0.3)',
data: data.cached
};
config.data.datasets.push(new_dataset);
var new_annotation = {
drawTime: 'afterDraw', // overrides annotation.drawTime if set
type: 'line',
mode: 'horizontal',
scaleID: 'y-axis-0',
value: data.total,
borderColor: 'red',
borderWidth: 2
};
config.options.annotation.annotations.push(new_annotation);
window.memChart.update();
});
};
\ No newline at end of file
This diff is collapsed.
require('chart.js');
require('chartjs-plugin-annotation');
/* /*
* Common stuff for all sensors * Common stuff for all sensors
*/ */
require('chart.js');
require('chartjs-plugin-annotation');
window.chartColors = { window.chartColors = {
red: 'rgba(255, 99, 132, 0.2)', red: 'rgba(255, 99, 132, 0.2)',
orange: 'rgba(255, 165, 0, 0.3)', orange: 'rgba(255, 165, 0, 0.3)',
...@@ -19,6 +18,220 @@ window.chartColors = { ...@@ -19,6 +18,220 @@ window.chartColors = {
window.colorNames = Object.keys(window.chartColors); window.colorNames = Object.keys(window.chartColors);
/*
* Ifconfig
*/
window.monitorIfconfigChart = function(element) {
var ctx = element.getContext('2d');
var config = {
type: 'line',
data: {
datasets: []
},
options: {
legend: {
display: true,
},
scales: {
xAxes: [{
type: 'time',
display: true,
scaleLabel: {
display: true,
labelString: 'Time'
}
}],
yAxes: [{
ticks: {
beginAtZero:true
},
scaleLabel: {
display: true,
labelString: '[Kbits / sec]'
}
}]
},
annotation: {
annotations: []
}
}
};
window.ifconfigChart = new Chart(ctx, config);
if (typeof window.monitorURL === 'undefined') {
window.monitorURL = "https://monitor.web-d.be";
}
var api_url = window.monitorURL + "/api/sensor/"
+ window.monitorServerID + "/" + window.monitorServerToken
+ "/ifconfig";
$.getJSON(api_url, function(data) {
$.each(data, function(key, dataset){
// console.log(dataset);
var new_color_name = window.colorNames[key];
var new_color = window.chartColors[new_color_name];
var new_dataset = {
label: dataset.name,
backgroundColor: "rgba(255, 255, 255, 0.0)", // transparent
borderColor: new_color,
data: dataset.points
};
config.data.datasets.push(new_dataset);
});
window.ifconfigChart.update();
});
};
/*
* CPU load
*/
window.monitorLoadChart = function(element) {
var ctx = element.getContext('2d');
var config = {
type: 'line',
data: {
datasets: []
},
options: {
legend: {
display: false,
},
scales: {
xAxes: [{
type: 'time',
display: true,
scaleLabel: {
display: true,
labelString: 'Time'
}
}],
yAxes: [{
ticks: {
beginAtZero:true
},
scaleLabel: {
display: true,
labelString: 'Load'
}
}]
},
annotation: {
annotations: []
}
}
};
window.loadChart = new Chart(ctx, config);
if (typeof window.monitorURL === 'undefined') {
window.monitorURL = "https://monitor.web-d.be";
}
var load_url = window.monitorURL + "/api/sensor/"
+ window.monitorServerID + "/" + window.monitorServerToken
+ "/load";
$.getJSON(load_url, function( data ) {
var new_dataset = {
label: 'Load',
data: data.points
};
config.data.datasets.push(new_dataset);
var new_annotation = {
drawTime: 'afterDraw', // overrides annotation.drawTime if set
type: 'line',
mode: 'horizontal',
scaleID: 'y-axis-0',
value: data.max,
borderColor: 'red',
borderWidth: 2
};
config.options.annotation.annotations.push(new_annotation);
window.loadChart.update();
});
};
/*
* Memory
*/
window.monitorMemChart = function(element) {
var ctx = element.getContext('2d');
var config = {
type: 'line',
data: {
datasets: []
},
options: {
legend: {
display: true,
},
scales: {
xAxes: [{
type: 'time',
display: true,
scaleLabel: {
display: true,
labelString: 'Time'
}
}],
yAxes: [{
stacked: true,
ticks: {
beginAtZero:true
},
scaleLabel: {
display: true,
labelString: 'Memory [MB]'
}
}]
},
annotation: {
annotations: []
}
}
};
window.memChart = new Chart(ctx, config);
if (typeof window.monitorURL === 'undefined') {
window.monitorURL = "https://monitor.web-d.be";
}
var meminfo_url = window.monitorURL + "/api/sensor/"
+ window.monitorServerID + "/" + window.monitorServerToken
+ "/memory";
$.getJSON(meminfo_url, function(data) {
var new_dataset = {
label: 'Used',
backgroundColor: 'rgba(0, 178, 0, 0.3)',
borderColor: 'rgba(0, 178, 0, 0.3)',
data: data.used
};
config.data.datasets.push(new_dataset);
new_dataset = {
label: 'Cached',
backgroundColor: 'rgba(255, 165, 0, 0.3)',
borderColor: 'rgba(255, 165, 0, 0.3)',
data: data.cached
};
config.data.datasets.push(new_dataset);
var new_annotation = {
drawTime: 'afterDraw', // overrides annotation.drawTime if set
type: 'line',
mode: 'horizontal',
scaleID: 'y-axis-0',
value: data.total,
borderColor: 'red',
borderWidth: 2
};
config.options.annotation.annotations.push(new_annotation);
window.memChart.update();
});
};
/* /*
* Disk evolution graphing * Disk evolution graphing
*/ */
...@@ -79,3 +292,69 @@ window.loadDiskEvolutionChart = function(element) { ...@@ -79,3 +292,69 @@ window.loadDiskEvolutionChart = function(element) {
window.diskEvolutionChart.update(); window.diskEvolutionChart.update();
}); });
}; };
/*
* Netstat
*/
window.loadDiskEvolutionChart = function(element) {
var ctx = element.getContext('2d');
var config = {
type: 'line',
data: {
datasets: []
},
options: {
legend: {
display: true,
},
scales: {
xAxes: [{
type: 'time',
display: true,
scaleLabel: {
display: true,
labelString: 'Time'
}
}],
yAxes: [{
ticks: {
beginAtZero:true
},
scaleLabel: {
display: true,
labelString: '%'
}
}]
},
annotation: {
annotations: []
}
}
};
window.netstatChart = new Chart(ctx, config);
if (typeof window.monitorURL === 'undefined') {
window.monitorURL = "https://monitor.web-d.be";
}
var api_url = window.monitorURL + "/api/sensor/"
+ window.monitorServerID + "/" + window.monitorServerToken
+ "/netstat";
$.getJSON(api_url, function(data) {
$.each(data, function(key, dataset){
// console.log(dataset);
var new_color_name = window.colorNames[key];
var new_color = window.chartColors[new_color_name];
var new_dataset = {
label: dataset.name,
backgroundColor: "rgba(255, 255, 255, 0.0)", // transparent
borderColor: new_color,
data: dataset.points
};
config.data.datasets.push(new_dataset);
});
window.netstatChart.update();
});
};
...@@ -13,9 +13,8 @@ ...@@ -13,9 +13,8 @@
</table> </table>
<canvas id="ifconfig-chart" width='400' height='300'></canvas> <canvas id="ifconfig-chart" width='400' height='300'></canvas>
<script src="/js/sensor.ifconfig.js"></script>
<script> <script>
window.addEventListener('load', function() { window.addEventListener('load', function() {
window.monitorIfconfigChart(document.getElementById('ifconfig-chart')); window.monitorIfconfigChart(document.getElementById('ifconfig-chart'));
}); });
</script> </script>
\ No newline at end of file
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
<p>Current load: {{ $current_load }}</p> <p>Current load: {{ $current_load }}</p>
<canvas id="load-chart" width='400' height='300'></canvas> <canvas id="load-chart" width='400' height='300'></canvas>
<script src="/js/sensor.load.js"></script>
<script> <script>
window.addEventListener('load', function() { window.addEventListener('load', function() {
window.monitorLoadChart(document.getElementById('load-chart')); window.monitorLoadChart(document.getElementById('load-chart'));
......
<canvas id="memory-chart" width='400' height='300'></canvas> <canvas id="memory-chart" width='400' height='300'></canvas>
<script src="/js/sensor.memory.js"></script>
<script> <script>
window.addEventListener('load', function() { window.addEventListener('load', function() {
window.monitorMemChart(document.getElementById('memory-chart')); window.monitorMemChart(document.getElementById('memory-chart'));
}); });
</script> </script>
\ No newline at end of file
<canvas id="netstat-chart" width='400' height='300'></canvas> <canvas id="netstat-chart" width='400' height='300'></canvas>
<script> <script>
window.addEventListener('load', function() { window.addEventListener('load', function() {
var element = document.getElementById('netstat-chart'); window.monitorNetstatChart(document.getElementById('netstat-chart'));
var ctx = element.getContext('2d');
var config = {
type: 'line',
data: {
datasets: []
},
options: {
legend: {
display: true,
},
scales: {
xAxes: [{
type: 'time',
display: true,
scaleLabel: {
display: true,
labelString: 'Time'
}
}],
yAxes: [{
ticks: {
beginAtZero:true
},
scaleLabel: {
display: true,
labelString: '%'
}
}]
},
annotation: {
annotations: []
}
}
};
window.netstatChart = new Chart(ctx, config);
if (typeof window.monitorURL === 'undefined') {
window.monitorURL = "https://monitor.web-d.be";
}
var api_url = window.monitorURL + "/api/sensor/"
+ window.monitorServerID + "/" + window.monitorServerToken
+ "/netstat";
$.getJSON(api_url, function(data) {
$.each(data, function(key, dataset){
// console.log(dataset);
var new_color_name = window.colorNames[key];
var new_color = window.chartColors[new_color_name];
var new_dataset = {
label: dataset.name,
backgroundColor: "rgba(255, 255, 255, 0.0)", // transparent
borderColor: new_color,
data: dataset.points
};
config.data.datasets.push(new_dataset);
});
window.netstatChart.update();
});
}); });
</script> </script>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment