]>
Commit | Line | Data |
---|---|---|
5936e3ef DC |
1 | Ext.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 | 285 | hours: '{hours}', |
a2afe563 | 286 | limit: 10, // make this also configurable? |
c87d46fb | 287 | }, |
b047eec0 DC |
288 | }, |
289 | fields: [ | |
290 | { type: 'integer', name: 'count' }, | |
c87d46fb TL |
291 | { type: 'string', name: 'receiver' }, |
292 | ], | |
293 | }, | |
11eae1a0 FE |
294 | repositories: { |
295 | storeid: 'dash-repositories', | |
296 | type: 'update', | |
297 | interval: 15000, | |
298 | autoStart: true, | |
299 | autoLoad: true, | |
300 | autoDestroy: true, | |
301 | proxy: { | |
302 | type: 'proxmox', | |
303 | url: '/api2/json/nodes/localhost/apt/repositories', | |
304 | }, | |
305 | listeners: { | |
306 | load: 'updateRepositoryStatus', | |
307 | }, | |
308 | }, | |
c87d46fb | 309 | }, |
b047eec0 DC |
310 | }, |
311 | ||
312 | bind: { | |
313 | title: gettext('Dashboard') + ' (' + | |
c87d46fb | 314 | Ext.String.format(gettext('{0} hours'), '{hours}') + ')', |
b047eec0 DC |
315 | }, |
316 | ||
de0ebd99 | 317 | layout: { |
c87d46fb | 318 | type: 'column', |
de0ebd99 | 319 | }, |
b047eec0 DC |
320 | border: false, |
321 | ||
322 | bodyPadding: '20 0 0 20', | |
323 | ||
324 | defaults: { | |
325 | columnWidth: 0.5, | |
326 | xtype: 'panel', | |
c87d46fb | 327 | margin: '0 20 20 0', |
b047eec0 DC |
328 | }, |
329 | ||
330 | tools: [ | |
331 | { | |
332 | type: 'gear', | |
c87d46fb TL |
333 | handler: 'openDashboardOptions', |
334 | }, | |
b047eec0 DC |
335 | ], |
336 | ||
337 | scrollable: true, | |
338 | ||
339 | items: [ | |
340 | { | |
341 | height: 300, | |
342 | flex: 1, | |
343 | iconCls: 'fa fa-tachometer', | |
344 | title: gettext('E-Mail Volume'), | |
345 | layout: { | |
346 | type: 'vbox', | |
c87d46fb | 347 | align: 'stretch', |
b047eec0 DC |
348 | }, |
349 | defaults: { | |
350 | xtype: 'pmgMiniGraph', | |
351 | bind: { | |
c87d46fb TL |
352 | store: '{recentmails}', |
353 | }, | |
b047eec0 DC |
354 | }, |
355 | items: [ | |
356 | { | |
357 | fields: ['count'], | |
c87d46fb | 358 | fieldTitles: [gettext('Mails / min')], |
b047eec0 | 359 | seriesConfig: { |
c87d46fb | 360 | colors: ['#00617F'], |
b047eec0 DC |
361 | style: { |
362 | opacity: 0.60, | |
c87d46fb | 363 | lineWidth: 1, |
b047eec0 DC |
364 | }, |
365 | highlightCfg: { | |
366 | opacity: 1, | |
c87d46fb TL |
367 | scaling: 1, |
368 | }, | |
369 | }, | |
b047eec0 DC |
370 | }, |
371 | { | |
372 | fields: ['spam'], | |
c87d46fb | 373 | fieldTitles: [gettext('Spam / min')], |
b047eec0 | 374 | seriesConfig: { |
c87d46fb | 375 | colors: ['#E67300'], |
b047eec0 DC |
376 | style: { |
377 | opacity: 0.60, | |
c87d46fb | 378 | lineWidth: 1, |
b047eec0 DC |
379 | }, |
380 | highlightCfg: { | |
381 | opacity: 1, | |
c87d46fb TL |
382 | scaling: 1, |
383 | }, | |
384 | }, | |
385 | }, | |
386 | ], | |
b047eec0 DC |
387 | }, |
388 | { | |
389 | xtype: 'container', | |
390 | height: 300, | |
391 | layout: { | |
392 | type: 'vbox', | |
c87d46fb | 393 | align: 'stretch', |
b047eec0 DC |
394 | }, |
395 | items: [ | |
396 | { | |
397 | xtype: 'pmgMailProcessing', | |
398 | title: gettext('E-Mail Processing'), | |
399 | iconCls: 'fa fa-hourglass-half', | |
400 | height: 180, | |
401 | bind: { | |
402 | data: { | |
7b18f75e DC |
403 | 'bytes_in': '{bytes_in}', |
404 | 'bytes_out': '{bytes_out}', | |
c87d46fb TL |
405 | 'avg_ptime': '{avg_ptime}', |
406 | }, | |
407 | }, | |
b047eec0 DC |
408 | }, |
409 | { | |
410 | iconCls: 'fa fa-ticket', | |
f334aeb0 | 411 | title: gettext('Subscription'), |
b047eec0 DC |
412 | reference: 'subscription', |
413 | xtype: 'pmgSubscriptionInfo', | |
414 | margin: '10 0 0 0', | |
c87d46fb TL |
415 | height: 110, |
416 | }, | |
417 | ], | |
b047eec0 | 418 | }, |
11eae1a0 FE |
419 | { |
420 | xtype: 'pmgNodeInfoPanel', | |
421 | reference: 'nodeInfo', | |
95288fa8 | 422 | height: 300, |
9b7b0553 | 423 | bodyPadding: '15 5 15 5', |
11eae1a0 FE |
424 | iconCls: 'fa fa-tasks', |
425 | }, | |
b047eec0 | 426 | { |
95288fa8 | 427 | height: 300, |
b047eec0 DC |
428 | iconCls: 'fa fa-list', |
429 | title: gettext('Top Receivers'), | |
430 | ||
a2afe563 | 431 | bodyPadding: '10 10 10 10', |
b047eec0 DC |
432 | layout: { |
433 | type: 'vbox', | |
434 | pack: 'center', | |
c87d46fb | 435 | align: 'stretch', |
b047eec0 DC |
436 | }, |
437 | items: [{ | |
438 | xtype: 'grid', | |
439 | bind: { | |
c87d46fb | 440 | store: '{receivers}', |
b047eec0 | 441 | }, |
b047eec0 | 442 | emptyText: gettext('No data in database'), |
b047eec0 DC |
443 | // remove all borders/lines/headers |
444 | border: false, | |
445 | bodyBorder: false, | |
446 | hideHeaders: true, | |
447 | header: false, | |
448 | columnLines: false, | |
449 | rowLines: false, | |
450 | viewConfig: { | |
c87d46fb | 451 | stripeRows: false, |
b047eec0 | 452 | }, |
b047eec0 DC |
453 | columns: [ |
454 | { | |
455 | dataIndex: 'receiver', | |
456 | flex: 1, | |
c87d46fb | 457 | text: gettext('Receiver'), |
b047eec0 DC |
458 | }, |
459 | { | |
460 | dataIndex: 'count', | |
461 | align: 'right', | |
c87d46fb TL |
462 | text: gettext('Count'), |
463 | }, | |
464 | ], | |
465 | }], | |
466 | }, | |
8f691c7b TL |
467 | { |
468 | height: 250, | |
469 | iconCls: 'fa fa-tasks', | |
470 | title: gettext('Cluster Resources (average)'), | |
471 | reference: 'clusterResources', | |
472 | hidden: true, | |
473 | bodyPadding: '0 20 0 20', | |
474 | layout: { | |
475 | type: 'hbox', | |
476 | align: 'center', | |
477 | }, | |
478 | defaults: { | |
479 | xtype: 'proxmoxGauge', | |
480 | spriteFontSize: '20px', | |
481 | flex: 1, | |
482 | }, | |
483 | items: [ | |
484 | { | |
485 | title: gettext('CPU'), | |
486 | reference: 'cpu', | |
487 | }, | |
488 | { | |
489 | title: gettext('Memory'), | |
490 | reference: 'mem', | |
491 | }, | |
492 | { | |
493 | title: gettext('Storage'), | |
494 | reference: 'hd', | |
495 | }, | |
496 | ], | |
497 | }, | |
c87d46fb | 498 | ], |
5936e3ef | 499 | }); |