]>
git.proxmox.com Git - pmg-gui.git/blob - js/Dashboard.js
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
9 Ext
.define('PMG.Dashboard', {
10 extend
: 'Ext.panel.Panel',
11 xtype
: 'pmgDashboard',
14 xclass
: 'Ext.app.ViewController',
16 openDashboardOptions: function() {
18 var viewModel
= me
.getViewModel();
19 Ext
.create('Ext.window.Window', {
22 title
: gettext('Dashboard Options'),
28 bodyPadding
: '10 10 10 10',
29 defaultButton
: 'savebutton',
31 xtype
: 'proxmoxintegerfield',
38 value
: viewModel
.get('hours'),
39 fieldLabel
: gettext('Hours to show')
42 text
: gettext('Save'),
43 reference
: 'loginButton',
46 var win
= this.up('window');
47 var hours
= win
.down('#hours').getValue();
48 me
.setHours(hours
, true);
56 setHours: function(hours
, setState
) {
58 var viewModel
= me
.getViewModel();
59 viewModel
.set('hours', hours
);
62 Ext
.Array
.forEach(['recentmails', 'receivers'], function(item
) {
63 viewModel
.getStore(item
).reload();
67 var sp
= Ext
.state
.Manager
.getProvider();
68 sp
.set('dashboard-hours', hours
);
72 updateMailStats: function(store
, records
, success
) {
77 var viewModel
= me
.getViewModel();
83 var avg_ptime
= 'N/A';
85 records
.forEach(function(item
) {
86 bytes_in
+= item
.data
.bytes_in
;
87 bytes_out
+= item
.data
.bytes_out
;
89 count
+= (item
.data
.count
*item
.data
.timespan
)/60;
90 ptime
+= item
.data
.ptimesum
;
94 avg_ptime
= (ptime
/count
).toFixed(2) + " s";
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
);
102 updateClusterStats: function(store
, records
, success
) {
107 var viewmodel
= me
.getViewModel();
109 var subStatus
= 2; // 2 = all good, 1 = different leves, 0 = none
115 var count
= records
.length
;
118 records
.forEach(function(item
) {
119 // subscription level check
120 if (subStatus
&& item
.data
.level
) {
121 if (subLevel
!== "" && subLevel
!== item
.data
.level
) {
123 } else if (subLevel
=== "") {
124 subLevel
= item
.data
.level
;
131 cpu
+= item
.data
.cpu
|| 0;
133 var memory
= item
.data
.memory
|| { used
: 0, total
: 1 };
134 mem
+= (memory
.used
/memory
.total
);
136 var rootfs
= item
.data
.rootfs
|| { used
: 0, total
: 1 };
137 hd
+= (rootfs
.used
/rootfs
.total
);
139 if (item
.data
.conn_error
&& count
> 1) {
142 name
: item
.data
.name
,
143 msg
: item
.data
.conn_error
148 var subscriptionPanel
= me
.lookup('subscription');
149 subscriptionPanel
.setSubStatus(subStatus
);
155 var cpuPanel
= me
.lookup('cpu');
156 cpuPanel
.updateValue(cpu
);
158 var memPanel
= me
.lookup('mem');
159 memPanel
.updateValue(mem
);
161 var hdPanel
= me
.lookup('hd');
162 hdPanel
.updateValue(hd
);
164 if (errors
.length
&& !viewmodel
.get('error_shown')) {
166 errors
.forEach(function(error
) {
167 text
+= error
.name
+ ':<br>' + error
.msg
+ '<br>';
169 Ext
.Msg
.alert(gettext('Error'), text
);
170 viewmodel
.set('error_shown', true);
174 init: function(view
) {
176 var sp
= Ext
.state
.Manager
.getProvider();
177 var hours
= sp
.get('dashboard-hours') || 12;
178 me
.setHours(hours
, false);
184 timespan
: 300, // in seconds
185 hours
: 12, // in hours
194 storeid
: 'dash-cluster',
200 extraParams
: { list_single_node
: 1 },
202 url
: '/api2/json/config/cluster/status'
205 load
: 'updateClusterStats'
209 storeid
: 'dash-recent',
216 url
: '/api2/json/statistics/recent',
219 timespan
: '{timespan}'
224 type
: 'number', name
: 'count',
225 convert
: PMG
.Utils
.convert_field_to_per_min
228 type
: 'number', name
: 'count_in',
229 convert
: PMG
.Utils
.convert_field_to_per_min
232 type
: 'number', name
: 'count_out',
233 convert
: PMG
.Utils
.convert_field_to_per_min
236 type
: 'number', name
: 'spam',
237 convert
: PMG
.Utils
.convert_field_to_per_min
240 type
: 'number', name
: 'spam_in',
241 convert
: PMG
.Utils
.convert_field_to_per_min
244 type
: 'number', name
: 'spam_out',
245 convert
: PMG
.Utils
.convert_field_to_per_min
248 type
: 'number', name
: 'virus',
249 convert
: PMG
.Utils
.convert_field_to_per_min
252 type
: 'number', name
: 'virus_in',
253 convert
: PMG
.Utils
.convert_field_to_per_min
255 { type
: 'integer', name
: 'virus_out' },
256 { type
: 'integer', name
: 'bytes_in' },
257 { type
: 'integer', name
: 'bytes_out' },
258 { type
: 'number', name
: 'ptimesum' },
259 { type
: 'date', dateFormat
: 'timestamp', name
: 'time' }
262 load
: 'updateMailStats'
266 storeid
: 'dash-receivers',
273 url
: '/api2/json/statistics/recentreceivers',
279 { type
: 'integer', name
: 'count' },
280 { type
: 'string', name
: 'receiver' }
287 title
: gettext('Dashboard') + ' (' +
288 Ext
.String
.format(gettext('{0} hours'), '{hours}') + ')'
296 bodyPadding
: '20 0 0 20',
307 handler
: 'openDashboardOptions'
317 iconCls
: 'fa fa-tachometer',
318 title
: gettext('E-Mail Volume'),
324 xtype
: 'pmgMiniGraph',
326 store
: '{recentmails}'
332 fieldTitles
: [ gettext('Mails / min') ],
334 colors
: [ '#00617F' ],
347 fieldTitles
: [ gettext('Spam / min') ],
349 colors
: [ '#E67300' ],
371 xtype
: 'pmgMailProcessing',
372 title
: gettext('E-Mail Processing'),
373 iconCls
: 'fa fa-hourglass-half',
377 'bytes_in': '{bytes_in}',
378 'bytes_out': '{bytes_out}',
379 'avg_ptime': '{avg_ptime}'
384 iconCls
: 'fa fa-ticket',
385 title
: 'Subscription',
386 reference
: 'subscription',
387 xtype
: 'pmgSubscriptionInfo',
395 iconCls
: 'fa fa-tasks',
396 title
: gettext('Node Resources'),
397 bodyPadding
: '0 20 0 20',
403 xtype
: 'proxmoxGauge',
404 spriteFontSize
: '20px',
409 title
: gettext('CPU'),
413 title
: gettext('Memory'),
417 title
: gettext('Storage'),
424 iconCls
: 'fa fa-list',
425 title
: gettext('Top Receivers'),
427 bodyPadding
: '20 20 20 20',
439 emptyText
: gettext('No data in database'),
441 // remove all borders/lines/headers
454 dataIndex
: 'receiver',
456 text
: gettext('Receiver')
461 text
: gettext('Count')