|
9 | 9 | memoryUsageLine, |
10 | 10 | swapUsageLine, |
11 | 11 | cpuLoadChart, |
12 | | - cpuLoadLine, |
13 | | - activeUsersChart, |
14 | | - sharesChart; |
15 | | - |
16 | | - $(document).ready(function () { |
17 | | - var rambox = document.getElementById('rambox'); |
18 | | - rambox.style.backgroundColor = OCA.Theming ? OCA.Theming.color : 'rgb(54, 129, 195)'; |
19 | | - |
20 | | - var swapbox = document.getElementById('swapbox'); |
21 | | - swapbox.style.backgroundColor = 'rgba(100, 100, 100, 0.8)'; |
| 12 | + cpuLoadLine |
| 13 | + |
| 14 | + const chartOptions = { |
| 15 | + millisPerPixel: 100, |
| 16 | + minValue: 0, |
| 17 | + grid: {fillStyle: 'rgba(0,0,0,0)', strokeStyle: 'transparent'}, |
| 18 | + labels: {fillStyle: getThemedPassiveColor(), fontSize: 12, precision: 1}, |
| 19 | + responsive: true, |
| 20 | + tooltip: true, |
| 21 | + tooltipLine: { |
| 22 | + strokeStyle: getThemedPassiveColor() |
| 23 | + } |
| 24 | + }; |
22 | 25 |
|
| 26 | + $(function () { |
23 | 27 | initDiskCharts(); |
24 | 28 |
|
25 | 29 | setHumanReadableSizeToElement("databaseSize"); |
|
37 | 41 |
|
38 | 42 | $.get(url) |
39 | 43 | .done(function (response) { |
40 | | - updateCPUStatistics(response.system.cpuload) |
| 44 | + updateCPUStatistics(response.system.cpuload, response.system.cpunum) |
41 | 45 | updateMemoryStatistics(response.system.mem_total, response.system.mem_free, response.system.swap_total, response.system.swap_free) |
42 | 46 | }) |
43 | 47 | .always(function () { |
|
63 | 67 | * Reset all canvas widths on window resize so canvas is responsive |
64 | 68 | */ |
65 | 69 | function resizeSystemCharts() { |
66 | | - var cpuCanvas = $("#cpuloadcanvas"), |
67 | | - cpuCanvasWidth = cpuCanvas.parents('.infobox').width() - 30, |
| 70 | + let cpuCanvas = $("#cpuloadcanvas"), |
| 71 | + cpuCanvasWidth = cpuCanvas.parents('.infobox').width(), |
68 | 72 | memCanvas = $("#memorycanvas"), |
69 | | - memCanvasWidth = memCanvas.parents('.infobox').width() - 30; |
| 73 | + memCanvasWidth = memCanvas.parents('.infobox').width(); |
70 | 74 |
|
71 | 75 |
|
72 | 76 | // We have to set css width AND attribute width |
|
76 | 80 | memCanvas.attr('width', memCanvasWidth); |
77 | 81 | } |
78 | 82 |
|
79 | | - function updateCPUStatistics(cpuload) { |
80 | | - var $cpuFooterInfo = $('#cpuFooterInfo'); |
81 | | - var $cpuLoadCanvas = $('#cpuloadcanvas'); |
| 83 | + function updateCPUStatistics(cpuload, numCpus) { |
| 84 | + let $cpuFooterInfo = $('#cpuFooterInfo'); |
| 85 | + let $cpuLoadCanvas = $('#cpuloadcanvas'); |
| 86 | + |
| 87 | + // We need to stop touch events here, since they cause the tooltip to open, but never close again |
| 88 | + $cpuLoadCanvas[0].addEventListener('touchstart', (e) => { |
| 89 | + e.preventDefault(); |
| 90 | + }) |
82 | 91 |
|
83 | | - if (cpuload === 'N/A') { |
| 92 | + if (cpuload === 'N/A' || numCpus === -1) { |
84 | 93 | $cpuFooterInfo.text(t('serverinfo', 'CPU info not available')); |
85 | 94 | $cpuLoadCanvas.addClass('hidden'); |
86 | 95 | return; |
87 | | - |
88 | 96 | } else if ($cpuLoadCanvas.hasClass('hidden')) { |
89 | 97 | $cpuLoadCanvas.removeClass('hidden'); |
90 | 98 | } |
91 | 99 |
|
92 | | - var cpu1 = cpuload[0], |
93 | | - cpu2 = cpuload[1], |
94 | | - cpu3 = cpuload[2]; |
| 100 | + let cpuloadFixed = cpuload.map((load) => load.toFixed(2)); |
| 101 | + let cpuloadPercentageFixed = cpuload.map((load) => ((load / numCpus) * 100).toFixed(1)); |
95 | 102 |
|
96 | 103 | if (typeof cpuLoadChart === 'undefined') { |
97 | | - cpuLoadChart = new SmoothieChart( |
98 | | - { |
99 | | - millisPerPixel: 100, |
100 | | - minValue: 0, |
101 | | - grid: {fillStyle: 'rgba(0,0,0,0)', strokeStyle: 'transparent'}, |
102 | | - labels: {fillStyle: 'rgba(0,0,0,0.4)', fontSize: 12}, |
103 | | - responsive: true |
104 | | - }); |
| 104 | + const percentageFormatter = (val, precision) => val.toFixed(precision) + " %"; |
| 105 | + |
| 106 | + cpuLoadChart = new SmoothieChart({ |
| 107 | + ...chartOptions, |
| 108 | + yMinFormatter: percentageFormatter, |
| 109 | + yMaxFormatter: percentageFormatter, |
| 110 | + maxValue: 100 |
| 111 | + }); |
105 | 112 | cpuLoadChart.streamTo(document.getElementById("cpuloadcanvas"), 1000/*delay*/); |
106 | 113 | cpuLoadLine = new TimeSeries(); |
107 | 114 | cpuLoadChart.addTimeSeries(cpuLoadLine, { |
108 | 115 | lineWidth: 1, |
109 | 116 | strokeStyle: getThemedPassiveColor(), |
110 | | - fillStyle: getThemedPrimaryColor() |
| 117 | + fillStyle: getThemedPrimaryColor(), |
| 118 | + tooltipLabel: t('serverinfo', 'CPU Usage:') |
111 | 119 | }); |
112 | 120 | } |
113 | 121 |
|
114 | | - $cpuFooterInfo.text(t('serverinfo', 'Load average: {cpu} (last minute)', { cpu: cpu1.toFixed(2) })); |
115 | | - cpuLoadLine.append(new Date().getTime(), cpu1); |
| 122 | + $cpuFooterInfo.text(t('serverinfo', 'Load average: {percentage} % ({load}) last minute', { percentage: cpuloadPercentageFixed[0], load: cpuloadFixed[0] })); |
| 123 | + $cpuFooterInfo[0].title = t( |
| 124 | + 'serverinfo', |
| 125 | + '{lastMinutePercentage} % ({lastMinute}) last Minute\n{last5MinutesPercentage} % ({last5Minutes}) last 5 Minutes\n{last15MinutesPercentage} % ({last15Minutes}) last 15 Minutes', |
| 126 | + { |
| 127 | + lastMinute: cpuloadFixed[0], |
| 128 | + lastMinutePercentage: cpuloadPercentageFixed[0], |
| 129 | + last5Minutes: cpuloadFixed[1], |
| 130 | + last5MinutesPercentage: cpuloadPercentageFixed[1], |
| 131 | + last15Minutes: cpuloadFixed[2], |
| 132 | + last15MinutesPercentage: cpuloadPercentageFixed[2] |
| 133 | + } |
| 134 | + ); |
| 135 | + |
| 136 | + cpuLoadLine.append(new Date().getTime(), cpuload[0] / numCpus * 100); |
116 | 137 | } |
117 | 138 |
|
118 | 139 | function isMemoryStat(memTotal, memFree) { |
|
136 | 157 | var $swapFooterInfo = $('#swapFooterInfo'); |
137 | 158 | var $memoryCanvas = $('#memorycanvas'); |
138 | 159 |
|
| 160 | + // We need to stop touch events here, since they cause the tooltip to open, but never close again |
| 161 | + $memoryCanvas[0].addEventListener('touchstart', (e) => { |
| 162 | + e.preventDefault(); |
| 163 | + }) |
| 164 | + |
139 | 165 | var memTotalBytes = memTotal * 1024, |
140 | 166 | memUsageBytes = (memTotal - memFree) * 1024, |
141 | 167 | memTotalGB = memTotal / (1024 * 1024), |
|
152 | 178 | } |
153 | 179 |
|
154 | 180 | if (typeof memoryUsageChart === 'undefined') { |
| 181 | + const gbFormatter = (val, precision) => val.toFixed(precision) + " GB"; |
| 182 | + |
155 | 183 | memoryUsageChart = new SmoothieChart( |
156 | 184 | { |
157 | | - millisPerPixel: 100, |
| 185 | + ...chartOptions, |
158 | 186 | maxValue: maxValueOfChart, |
159 | | - minValue: 0, |
160 | | - grid: {fillStyle: 'rgba(0,0,0,0)', strokeStyle: 'transparent'}, |
161 | | - labels: {fillStyle: 'rgba(0,0,0,0.4)', fontSize: 12}, |
162 | | - responsive: true |
| 187 | + yMinFormatter: gbFormatter, |
| 188 | + yMaxFormatter: gbFormatter |
163 | 189 | }); |
164 | 190 | memoryUsageChart.streamTo(document.getElementById("memorycanvas"), 1000/*delay*/); |
165 | 191 | memoryUsageLine = new TimeSeries(); |
166 | 192 | memoryUsageChart.addTimeSeries(memoryUsageLine, { |
167 | 193 | lineWidth: 1, |
168 | 194 | strokeStyle: getThemedPassiveColor(), |
169 | | - fillStyle: getThemedPrimaryColor() |
| 195 | + fillStyle: getThemedPrimaryColor(), |
| 196 | + tooltipLabel: t('serverinfo', 'RAM Usage:') |
170 | 197 | }); |
171 | 198 | swapUsageLine = new TimeSeries(); |
172 | 199 | memoryUsageChart.addTimeSeries(swapUsageLine, { |
173 | 200 | lineWidth: 1, |
174 | | - strokeStyle: 'rgb(100, 100, 100)', |
175 | | - fillStyle: 'rgba(100, 100, 100, 0.2)' |
| 201 | + strokeStyle: getThemedPassiveColor(), |
| 202 | + fillStyle: 'rgba(100, 100, 100, 0.2)', |
| 203 | + tooltipLabel: t('serverinfo', 'SWAP Usage:') |
176 | 204 | }); |
177 | 205 | } |
178 | 206 |
|
|
0 commit comments