]>
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',
201 extraParams
: { list_single_node
: 1 },
203 url
: '/api2/json/config/cluster/status'
206 load
: 'updateClusterStats'
210 storeid
: 'dash-recent',
218 url
: '/api2/json/statistics/recent',
221 timespan
: '{timespan}'
226 type
: 'number', name
: 'count',
227 convert
: PMG
.Utils
.convert_field_to_per_min
230 type
: 'number', name
: 'count_in',
231 convert
: PMG
.Utils
.convert_field_to_per_min
234 type
: 'number', name
: 'count_out',
235 convert
: PMG
.Utils
.convert_field_to_per_min
238 type
: 'number', name
: 'spam',
239 convert
: PMG
.Utils
.convert_field_to_per_min
242 type
: 'number', name
: 'spam_in',
243 convert
: PMG
.Utils
.convert_field_to_per_min
246 type
: 'number', name
: 'spam_out',
247 convert
: PMG
.Utils
.convert_field_to_per_min
250 type
: 'number', name
: 'virus',
251 convert
: PMG
.Utils
.convert_field_to_per_min
254 type
: 'number', name
: 'virus_in',
255 convert
: PMG
.Utils
.convert_field_to_per_min
257 { type
: 'integer', name
: 'virus_out' },
258 { type
: 'integer', name
: 'bytes_in' },
259 { type
: 'integer', name
: 'bytes_out' },
260 { type
: 'number', name
: 'ptimesum' },
261 { type
: 'date', dateFormat
: 'timestamp', name
: 'time' }
264 load
: 'updateMailStats'
268 storeid
: 'dash-receivers',
276 url
: '/api2/json/statistics/recentreceivers',
282 { type
: 'integer', name
: 'count' },
283 { type
: 'string', name
: 'receiver' }
290 title
: gettext('Dashboard') + ' (' +
291 Ext
.String
.format(gettext('{0} hours'), '{hours}') + ')'
299 bodyPadding
: '20 0 0 20',
310 handler
: 'openDashboardOptions'
320 iconCls
: 'fa fa-tachometer',
321 title
: gettext('E-Mail Volume'),
327 xtype
: 'pmgMiniGraph',
329 store
: '{recentmails}'
335 fieldTitles
: [ gettext('Mails / min') ],
337 colors
: [ '#00617F' ],
350 fieldTitles
: [ gettext('Spam / min') ],
352 colors
: [ '#E67300' ],
374 xtype
: 'pmgMailProcessing',
375 title
: gettext('E-Mail Processing'),
376 iconCls
: 'fa fa-hourglass-half',
380 'bytes_in': '{bytes_in}',
381 'bytes_out': '{bytes_out}',
382 'avg_ptime': '{avg_ptime}'
387 iconCls
: 'fa fa-ticket',
388 title
: 'Subscription',
389 reference
: 'subscription',
390 xtype
: 'pmgSubscriptionInfo',
398 iconCls
: 'fa fa-tasks',
399 title
: gettext('Node Resources'),
400 bodyPadding
: '0 20 0 20',
406 xtype
: 'proxmoxGauge',
407 spriteFontSize
: '20px',
412 title
: gettext('CPU'),
416 title
: gettext('Memory'),
420 title
: gettext('Storage'),
427 iconCls
: 'fa fa-list',
428 title
: gettext('Top Receivers'),
430 bodyPadding
: '20 20 20 20',
442 emptyText
: gettext('No data in database'),
444 // remove all borders/lines/headers
457 dataIndex
: 'receiver',
459 text
: gettext('Receiver')
464 text
: gettext('Count')