]> git.proxmox.com Git - pmg-gui.git/blame - js/Dashboard.js
dashboard: reduce noise in current kernel version
[pmg-gui.git] / js / Dashboard.js
CommitLineData
5936e3ef
DC
1Ext.define('PMG.Dashboard', {
2 extend: 'Ext.panel.Panel',
3 xtype: 'pmgDashboard',
4
b047eec0
DC
5 controller: {
6 xclass: 'Ext.app.ViewController',
5936e3ef 7
b047eec0
DC
8 openDashboardOptions: function() {
9 var me = this;
10 var viewModel = me.getViewModel();
11 Ext.create('Ext.window.Window', {
12 modal: true,
13 width: 300,
14 title: gettext('Dashboard Options'),
15 layout: {
c87d46fb 16 type: 'auto',
b047eec0
DC
17 },
18 items: [{
19 xtype: 'form',
de0ebd99 20 bodyPadding: '10 10 10 10',
b047eec0
DC
21 defaultButton: 'savebutton',
22 items: [{
23 xtype: 'proxmoxintegerfield',
24 itemId: 'hours',
25 labelWidth: 100,
26 anchor: '100%',
27 allowBlank: false,
28 minValue: 1,
29 maxValue: 24,
30 value: viewModel.get('hours'),
c87d46fb 31 fieldLabel: gettext('Hours to show'),
b047eec0
DC
32 }],
33 buttons: [{
34 text: gettext('Save'),
35 reference: 'loginButton',
36 formBind: true,
37 handler: function() {
38 var win = this.up('window');
39 var hours = win.down('#hours').getValue();
40 me.setHours(hours, true);
41 win.close();
c87d46fb
TL
42 },
43 }],
44 }],
b047eec0
DC
45 }).show();
46 },
5936e3ef 47
b047eec0
DC
48 setHours: function(hours, setState) {
49 var me = this;
50 var viewModel = me.getViewModel();
51 viewModel.set('hours', hours);
52 viewModel.notify();
53
54 Ext.Array.forEach(['recentmails', 'receivers'], function(item) {
86109d3a 55 viewModel.getStore(item).reload();
b047eec0
DC
56 });
57
58 if (setState) {
59 var sp = Ext.state.Manager.getProvider();
60 sp.set('dashboard-hours', hours);
61 }
62 },
63
64 updateMailStats: function(store, records, success) {
65 if (!success) {
66 return;
67 }
68 var me = this;
69 var viewModel = me.getViewModel();
70
71 var count = 0;
72 var bytes_in = 0;
73 var bytes_out = 0;
74 var ptime = 0;
b6248f6e 75 var avg_ptime = 'N/A';
b047eec0
DC
76
77 records.forEach(function(item) {
78 bytes_in += item.data.bytes_in;
79 bytes_out += item.data.bytes_out;
b79fbba8
DC
80 // unnormalize
81 count += (item.data.count*item.data.timespan)/60;
b047eec0
DC
82 ptime += item.data.ptimesum;
83 });
84
85 if (count) {
b6248f6e 86 avg_ptime = (ptime/count).toFixed(2) + " s";
b047eec0
DC
87 }
88
89 viewModel.set('bytes_in', Proxmox.Utils.format_size(bytes_in));
90 viewModel.set('bytes_out', Proxmox.Utils.format_size(bytes_out));
b6248f6e 91 viewModel.set('avg_ptime', avg_ptime);
b047eec0
DC
92 },
93
94 updateClusterStats: function(store, records, success) {
95 if (!success) {
96 return;
97 }
98 var me = this;
99 var viewmodel = me.getViewModel();
100
101 var subStatus = 2; // 2 = all good, 1 = different leves, 0 = none
102 var subLevel = "";
103
104 var cpu = 0;
105 var mem = 0;
106 var hd = 0;
107 var count = records.length;
bb7ab2ba 108 var errors = [];
b047eec0
DC
109
110 records.forEach(function(item) {
111 // subscription level check
112 if (subStatus && item.data.level) {
113 if (subLevel !== "" && subLevel !== item.data.level) {
114 subStatus = 1;
115 } else if (subLevel === "") {
116 subLevel = item.data.level;
117 }
118 } else {
119 subStatus = 0;
120 }
121
a0a5f5cf 122 if (item.data.name === Proxmox.NodeName) {
48e23079
FE
123 let repoStatus = me.lookup('nodeInfo').down('#repositoryStatus');
124 repoStatus.setSubscriptionStatus(!!item.data.level);
a0a5f5cf
FE
125 }
126
b047eec0 127 // resources count
91c74e81
DC
128 cpu += item.data.cpu || 0;
129
130 var memory = item.data.memory || { used: 0, total: 1 };
c87d46fb 131 mem += memory.used/memory.total;
91c74e81
DC
132
133 var rootfs = item.data.rootfs || { used: 0, total: 1 };
c87d46fb 134 hd += rootfs.used/rootfs.total;
91c74e81 135
bb7ab2ba
DC
136 if (item.data.conn_error && count > 1) {
137 count--;
138 errors.push({
139 name: item.data.name,
c87d46fb 140 msg: item.data.conn_error,
bb7ab2ba
DC
141 });
142 }
b047eec0
DC
143 });
144
145 var subscriptionPanel = me.lookup('subscription');
146 subscriptionPanel.setSubStatus(subStatus);
147
91a4c642
FE
148 // the node info already displays this information in case there is no cluster
149 me.lookup('clusterResources').setHidden(records.length === 1);
150
b047eec0
DC
151 cpu = cpu/count;
152 mem = mem/count;
153 hd = hd/count;
154
155 var cpuPanel = me.lookup('cpu');
156 cpuPanel.updateValue(cpu);
157
131ba4f6 158 var memPanel = me.lookup('mem');
b047eec0
DC
159 memPanel.updateValue(mem);
160
131ba4f6 161 var hdPanel = me.lookup('hd');
b047eec0 162 hdPanel.updateValue(hd);
bb7ab2ba
DC
163
164 if (errors.length && !viewmodel.get('error_shown')) {
165 var text = "";
166 errors.forEach(function(error) {
167 text += error.name + ':<br>' + error.msg + '<br>';
168 });
169 Ext.Msg.alert(gettext('Error'), text);
170 viewmodel.set('error_shown', true);
171 }
b047eec0
DC
172 },
173
11eae1a0
FE
174 updateRepositoryStatus: function(store, records, success) {
175 if (!success) {
176 return;
177 }
178
179 let me = this;
48e23079
FE
180 let repoStatus = me.lookup('nodeInfo').down('#repositoryStatus');
181 repoStatus.setRepositoryInfo(records[0].data['standard-repos']);
11eae1a0
FE
182 },
183
b047eec0
DC
184 init: function(view) {
185 var me = this;
186 var sp = Ext.state.Manager.getProvider();
187 var hours = sp.get('dashboard-hours') || 12;
188 me.setHours(hours, false);
c87d46fb 189 },
b047eec0
DC
190 },
191
192 viewModel: {
193 data: {
194 timespan: 300, // in seconds
195 hours: 12, // in hours
bb7ab2ba 196 error_shown: false,
b047eec0
DC
197 'bytes_in': 0,
198 'bytes_out': 0,
c87d46fb 199 'avg_ptime': 0.0,
b047eec0
DC
200 },
201
202 stores: {
203 cluster: {
204 storeid: 'dash-cluster',
205 type: 'update',
206 interval: 5000,
207 autoStart: true,
b047eec0
DC
208 autoDestroy: true,
209 proxy: {
929f40ff 210 extraParams: { list_single_node: 1 },
b047eec0 211 type: 'proxmox',
c87d46fb 212 url: '/api2/json/config/cluster/status',
b047eec0
DC
213 },
214 listeners: {
c87d46fb
TL
215 load: 'updateClusterStats',
216 },
b047eec0
DC
217 },
218 recentmails: {
219 storeid: 'dash-recent',
220 interval: 5000,
221 type: 'update',
222 autoStart: true,
b047eec0
DC
223 autoDestroy: true,
224 proxy: {
225 type: 'proxmox',
226 url: '/api2/json/statistics/recent',
227 extraParams: {
228 hours: '{hours}',
c87d46fb
TL
229 timespan: '{timespan}',
230 },
b047eec0
DC
231 },
232 fields: [
b79fbba8
DC
233 {
234 type: 'number', name: 'count',
c87d46fb 235 convert: PMG.Utils.convert_field_to_per_min,
b79fbba8
DC
236 },
237 {
238 type: 'number', name: 'count_in',
c87d46fb 239 convert: PMG.Utils.convert_field_to_per_min,
b79fbba8
DC
240 },
241 {
242 type: 'number', name: 'count_out',
c87d46fb 243 convert: PMG.Utils.convert_field_to_per_min,
b79fbba8
DC
244 },
245 {
246 type: 'number', name: 'spam',
c87d46fb 247 convert: PMG.Utils.convert_field_to_per_min,
b79fbba8
DC
248 },
249 {
250 type: 'number', name: 'spam_in',
c87d46fb 251 convert: PMG.Utils.convert_field_to_per_min,
b79fbba8
DC
252 },
253 {
254 type: 'number', name: 'spam_out',
c87d46fb 255 convert: PMG.Utils.convert_field_to_per_min,
b79fbba8
DC
256 },
257 {
258 type: 'number', name: 'virus',
c87d46fb 259 convert: PMG.Utils.convert_field_to_per_min,
b79fbba8
DC
260 },
261 {
262 type: 'number', name: 'virus_in',
c87d46fb 263 convert: PMG.Utils.convert_field_to_per_min,
b79fbba8 264 },
b047eec0
DC
265 { type: 'integer', name: 'virus_out' },
266 { type: 'integer', name: 'bytes_in' },
267 { type: 'integer', name: 'bytes_out' },
268 { type: 'number', name: 'ptimesum' },
c87d46fb 269 { type: 'date', dateFormat: 'timestamp', name: 'time' },
b047eec0
DC
270 ],
271 listeners: {
c87d46fb
TL
272 load: 'updateMailStats',
273 },
b047eec0
DC
274 },
275 receivers: {
276 storeid: 'dash-receivers',
277 interval: 10000,
278 type: 'update',
279 autoStart: true,
b047eec0
DC
280 autoDestroy: true,
281 proxy: {
282 type: 'proxmox',
283 url: '/api2/json/statistics/recentreceivers',
284 extraParams: {
c87d46fb
TL
285 hours: '{hours}',
286 },
b047eec0
DC
287 },
288 fields: [
289 { type: 'integer', name: 'count' },
c87d46fb
TL
290 { type: 'string', name: 'receiver' },
291 ],
292 },
11eae1a0
FE
293 repositories: {
294 storeid: 'dash-repositories',
295 type: 'update',
296 interval: 15000,
297 autoStart: true,
298 autoLoad: true,
299 autoDestroy: true,
300 proxy: {
301 type: 'proxmox',
302 url: '/api2/json/nodes/localhost/apt/repositories',
303 },
304 listeners: {
305 load: 'updateRepositoryStatus',
306 },
307 },
c87d46fb 308 },
b047eec0
DC
309 },
310
311 bind: {
312 title: gettext('Dashboard') + ' (' +
c87d46fb 313 Ext.String.format(gettext('{0} hours'), '{hours}') + ')',
b047eec0
DC
314 },
315
de0ebd99 316 layout: {
c87d46fb 317 type: 'column',
de0ebd99 318 },
b047eec0
DC
319 border: false,
320
321 bodyPadding: '20 0 0 20',
322
323 defaults: {
324 columnWidth: 0.5,
325 xtype: 'panel',
c87d46fb 326 margin: '0 20 20 0',
b047eec0
DC
327 },
328
329 tools: [
330 {
331 type: 'gear',
c87d46fb
TL
332 handler: 'openDashboardOptions',
333 },
b047eec0
DC
334 ],
335
336 scrollable: true,
337
338 items: [
339 {
340 height: 300,
341 flex: 1,
342 iconCls: 'fa fa-tachometer',
343 title: gettext('E-Mail Volume'),
344 layout: {
345 type: 'vbox',
c87d46fb 346 align: 'stretch',
b047eec0
DC
347 },
348 defaults: {
349 xtype: 'pmgMiniGraph',
350 bind: {
c87d46fb
TL
351 store: '{recentmails}',
352 },
b047eec0
DC
353 },
354 items: [
355 {
356 fields: ['count'],
c87d46fb 357 fieldTitles: [gettext('Mails / min')],
b047eec0 358 seriesConfig: {
c87d46fb 359 colors: ['#00617F'],
b047eec0
DC
360 style: {
361 opacity: 0.60,
c87d46fb 362 lineWidth: 1,
b047eec0
DC
363 },
364 highlightCfg: {
365 opacity: 1,
c87d46fb
TL
366 scaling: 1,
367 },
368 },
b047eec0
DC
369 },
370 {
371 fields: ['spam'],
c87d46fb 372 fieldTitles: [gettext('Spam / min')],
b047eec0 373 seriesConfig: {
c87d46fb 374 colors: ['#E67300'],
b047eec0
DC
375 style: {
376 opacity: 0.60,
c87d46fb 377 lineWidth: 1,
b047eec0
DC
378 },
379 highlightCfg: {
380 opacity: 1,
c87d46fb
TL
381 scaling: 1,
382 },
383 },
384 },
385 ],
b047eec0
DC
386 },
387 {
388 xtype: 'container',
389 height: 300,
390 layout: {
391 type: 'vbox',
c87d46fb 392 align: 'stretch',
b047eec0
DC
393 },
394 items: [
395 {
396 xtype: 'pmgMailProcessing',
397 title: gettext('E-Mail Processing'),
398 iconCls: 'fa fa-hourglass-half',
399 height: 180,
400 bind: {
401 data: {
7b18f75e
DC
402 'bytes_in': '{bytes_in}',
403 'bytes_out': '{bytes_out}',
c87d46fb
TL
404 'avg_ptime': '{avg_ptime}',
405 },
406 },
b047eec0
DC
407 },
408 {
409 iconCls: 'fa fa-ticket',
f334aeb0 410 title: gettext('Subscription'),
b047eec0
DC
411 reference: 'subscription',
412 xtype: 'pmgSubscriptionInfo',
413 margin: '10 0 0 0',
c87d46fb
TL
414 height: 110,
415 },
416 ],
b047eec0 417 },
11eae1a0
FE
418 {
419 xtype: 'pmgNodeInfoPanel',
420 reference: 'nodeInfo',
9b7b0553
TL
421 height: 275,
422 bodyPadding: '15 5 15 5',
11eae1a0
FE
423 iconCls: 'fa fa-tasks',
424 },
b047eec0 425 {
9b7b0553 426 height: 275,
b047eec0
DC
427 iconCls: 'fa fa-list',
428 title: gettext('Top Receivers'),
429
de0ebd99 430 bodyPadding: '20 20 20 20',
b047eec0
DC
431 layout: {
432 type: 'vbox',
433 pack: 'center',
c87d46fb 434 align: 'stretch',
b047eec0
DC
435 },
436 items: [{
437 xtype: 'grid',
438 bind: {
c87d46fb 439 store: '{receivers}',
b047eec0 440 },
b047eec0 441 emptyText: gettext('No data in database'),
b047eec0
DC
442 // remove all borders/lines/headers
443 border: false,
444 bodyBorder: false,
445 hideHeaders: true,
446 header: false,
447 columnLines: false,
448 rowLines: false,
449 viewConfig: {
c87d46fb 450 stripeRows: false,
b047eec0 451 },
b047eec0
DC
452 columns: [
453 {
454 dataIndex: 'receiver',
455 flex: 1,
c87d46fb 456 text: gettext('Receiver'),
b047eec0
DC
457 },
458 {
459 dataIndex: 'count',
460 align: 'right',
c87d46fb
TL
461 text: gettext('Count'),
462 },
463 ],
464 }],
465 },
8f691c7b
TL
466 {
467 height: 250,
468 iconCls: 'fa fa-tasks',
469 title: gettext('Cluster Resources (average)'),
470 reference: 'clusterResources',
471 hidden: true,
472 bodyPadding: '0 20 0 20',
473 layout: {
474 type: 'hbox',
475 align: 'center',
476 },
477 defaults: {
478 xtype: 'proxmoxGauge',
479 spriteFontSize: '20px',
480 flex: 1,
481 },
482 items: [
483 {
484 title: gettext('CPU'),
485 reference: 'cpu',
486 },
487 {
488 title: gettext('Memory'),
489 reference: 'mem',
490 },
491 {
492 title: gettext('Storage'),
493 reference: 'hd',
494 },
495 ],
496 },
c87d46fb 497 ],
5936e3ef 498});