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