Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
window.chartColors = {
red: 'rgba(255, 99, 132, 0.2)',
orange: 'rgba(255, 165, 0, 0.3)',
yellow: 'rgba(255, 205, 86, 0.2)',
green: 'rgba(0, 178, 0, 0.3)',
blue: 'rgba(54, 162, 235, 0.2)',
purple: 'rgba(153, 102, 255, 0.2)',
grey: 'rgba(201, 203, 207, 0.2)'
};
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: {
// Defines when the annotations are drawn.
// This allows positioning of the annotation relative to the other
// elements of the graph.
//
// Should be one of: afterDraw, afterDatasetsDraw, beforeDatasetsDraw
// See http://www.chartjs.org/docs/#advanced-usage-creating-plugins
drawTime: 'afterDatasetsDraw', // (default)
// Array of annotation configuration objects
// See below for detailed descriptions of the annotation options
annotations: [{
drawTime: 'afterDraw', // overrides annotation.drawTime if set
type: 'line',
mode: 'horizontal',
scaleID: 'y-axis-0',
value: '{{ $server->memoryTotal() / 1000 }}',
borderColor: 'red',
borderWidth: 2
}]
}
}
};
window.memChart = new Chart(ctx, config);
var used_url = "/api/sensor/"
+ window.monitorServerID + "/" + window.monitorServerToken
+ "/memory/used"
$.getJSON(used_url, function( data ) {
var new_dataset = {
label: 'Used',
backgroundColor: window.chartColors.green,
borderColor: window.chartColors.green,
data: data
};
config.data.datasets.push(new_dataset);
window.memChart.update();
});
var cached_url = "/api/sensor/"
+ window.monitorServerID + "/" + window.monitorServerToken
+ "/memory/cached"
$.getJSON(cached_url, function( data ) {
var new_dataset = {
label: 'Cached',
backgroundColor: window.chartColors.orange,
borderColor: window.chartColors.orange,
data: data
};
config.data.datasets.push(new_dataset);
window.memChart.update();
});
};