]> git.proxmox.com Git - pmg-gui.git/blame - js/Dashboard.js
jslint fix: do not use single statements when using if
[pmg-gui.git] / js / Dashboard.js
CommitLineData
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
9Ext.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: {
178 type: 'proxmox',
179 url: '/api2/json/config/cluster/status'
180 },
181 listeners: {
182 load: 'updateClusterStats'
183 }
184 },
185 recentmails: {
186 storeid: 'dash-recent',
187 interval: 5000,
188 type: 'update',
189 autoStart: true,
190 autoLoad: true,
191 autoDestroy: true,
192 proxy: {
193 type: 'proxmox',
194 url: '/api2/json/statistics/recent',
195 extraParams: {
196 hours: '{hours}',
197 timespan: '{timespan}'
198 }
199 },
200 fields: [
b79fbba8
DC
201 {
202 type: 'number', name: 'count',
203 convert: PMG.Utils.convert_field_to_per_min
204 },
205 {
206 type: 'number', name: 'count_in',
207 convert: PMG.Utils.convert_field_to_per_min
208 },
209 {
210 type: 'number', name: 'count_out',
211 convert: PMG.Utils.convert_field_to_per_min
212 },
213 {
214 type: 'number', name: 'spam',
215 convert: PMG.Utils.convert_field_to_per_min
216 },
217 {
218 type: 'number', name: 'spam_in',
219 convert: PMG.Utils.convert_field_to_per_min
220 },
221 {
222 type: 'number', name: 'spam_out',
223 convert: PMG.Utils.convert_field_to_per_min
224 },
225 {
226 type: 'number', name: 'virus',
227 convert: PMG.Utils.convert_field_to_per_min
228 },
229 {
230 type: 'number', name: 'virus_in',
231 convert: PMG.Utils.convert_field_to_per_min
232 },
b047eec0
DC
233 { type: 'integer', name: 'virus_out' },
234 { type: 'integer', name: 'bytes_in' },
235 { type: 'integer', name: 'bytes_out' },
236 { type: 'number', name: 'ptimesum' },
237 { type: 'date', dateFormat: 'timestamp', name: 'time' }
238 ],
239 listeners: {
240 load: 'updateMailStats'
241 }
242 },
243 receivers: {
244 storeid: 'dash-receivers',
245 interval: 10000,
246 type: 'update',
247 autoStart: true,
248 autoLoad: true,
249 autoDestroy: true,
250 proxy: {
251 type: 'proxmox',
252 url: '/api2/json/statistics/recentreceivers',
253 extraParams: {
771bd0b9 254 hours: '{hours}'
b047eec0
DC
255 }
256 },
257 fields: [
258 { type: 'integer', name: 'count' },
259 { type: 'string', name: 'receiver' }
260 ]
261 }
262 }
263 },
264
265 bind: {
266 title: gettext('Dashboard') + ' (' +
267 Ext.String.format(gettext('{0} hours'), '{hours}') + ')'
268 },
269
de0ebd99
DC
270 layout: {
271 type: 'column'
272 },
b047eec0
DC
273 border: false,
274
275 bodyPadding: '20 0 0 20',
276
277 defaults: {
278 columnWidth: 0.5,
279 xtype: 'panel',
280 margin: '0 20 20 0'
281 },
282
283 tools: [
284 {
285 type: 'gear',
286 handler: 'openDashboardOptions'
287 }
288 ],
289
290 scrollable: true,
291
292 items: [
293 {
294 height: 300,
295 flex: 1,
296 iconCls: 'fa fa-tachometer',
297 title: gettext('E-Mail Volume'),
298 layout: {
299 type: 'vbox',
771bd0b9 300 align: 'stretch'
b047eec0
DC
301 },
302 defaults: {
303 xtype: 'pmgMiniGraph',
304 bind: {
305 store: '{recentmails}'
306 }
307 },
308 items: [
309 {
310 fields: ['count'],
b79fbba8 311 fieldTitles: [ gettext('Mails / min') ],
b047eec0
DC
312 seriesConfig: {
313 colors: [ '#00617F' ],
314 style: {
315 opacity: 0.60,
316 lineWidth: 1
317 },
318 highlightCfg: {
319 opacity: 1,
320 scaling: 1
771bd0b9
DC
321 }
322 }
b047eec0
DC
323 },
324 {
325 fields: ['spam'],
b79fbba8 326 fieldTitles: [ gettext('Spam / min') ],
b047eec0
DC
327 seriesConfig: {
328 colors: [ '#E67300' ],
329 style: {
330 opacity: 0.60,
331 lineWidth: 1
332 },
333 highlightCfg: {
334 opacity: 1,
335 scaling: 1
771bd0b9
DC
336 }
337 }
338 }
b047eec0
DC
339 ]
340 },
341 {
342 xtype: 'container',
343 height: 300,
344 layout: {
345 type: 'vbox',
771bd0b9 346 align: 'stretch'
b047eec0
DC
347 },
348 items: [
349 {
350 xtype: 'pmgMailProcessing',
351 title: gettext('E-Mail Processing'),
352 iconCls: 'fa fa-hourglass-half',
353 height: 180,
354 bind: {
355 data: {
7b18f75e
DC
356 'bytes_in': '{bytes_in}',
357 'bytes_out': '{bytes_out}',
358 'avg_ptime': '{avg_ptime}'
b047eec0 359 }
771bd0b9 360 }
b047eec0
DC
361 },
362 {
363 iconCls: 'fa fa-ticket',
364 title: 'Subscription',
365 reference: 'subscription',
366 xtype: 'pmgSubscriptionInfo',
367 margin: '10 0 0 0',
771bd0b9 368 height: 110
b047eec0
DC
369 }
370 ]
371 },
372 {
373 height: 250,
374 iconCls: 'fa fa-tasks',
375 title: 'Node Resources',
376 bodyPadding: '0 20 0 20',
377 layout: {
378 type: 'hbox',
379 align: 'center'
380 },
381 defaults: {
382 xtype: 'proxmoxGauge',
383 spriteFontSize: '20px',
384 flex: 1
385 },
386 items: [
387 {
388 title: gettext('CPU'),
389 reference: 'cpu'
390 },
391 {
392 title: gettext('Memory'),
393 reference: 'mem'
394 },
395 {
396 title: gettext('Storage'),
397 reference: 'hd'
398 }
399 ]
400 },
401 {
402 height: 250,
403 iconCls: 'fa fa-list',
404 title: gettext('Top Receivers'),
405
de0ebd99 406 bodyPadding: '20 20 20 20',
b047eec0
DC
407 layout: {
408 type: 'vbox',
409 pack: 'center',
410 align: 'stretch'
411 },
412 items: [{
413 xtype: 'grid',
414 bind: {
415 store: '{receivers}'
416 },
417
418 emptyText: gettext('No data in database'),
419
420 // remove all borders/lines/headers
421 border: false,
422 bodyBorder: false,
423 hideHeaders: true,
424 header: false,
425 columnLines: false,
426 rowLines: false,
427 viewConfig: {
771bd0b9 428 stripeRows: false
b047eec0
DC
429 },
430
431 columns: [
432 {
433 dataIndex: 'receiver',
434 flex: 1,
435 text: gettext('Receiver')
436 },
437 {
438 dataIndex: 'count',
439 align: 'right',
440 text: gettext('Count')
441 }
442 ]
443 }]
444 }
445 ]
5936e3ef 446});