]>
git.proxmox.com Git - proxmox-backup.git/blob - www/Dashboard.js
1 Ext
.define('PBS.Dashboard', {
2 extend
: 'Ext.panel.Panel',
6 xclass
: 'Ext.app.ViewController',
8 openDashboardOptions: function() {
10 var viewModel
= me
.getViewModel();
11 Ext
.create('Ext.window.Window', {
14 title
: gettext('Dashboard Options'),
20 bodyPadding
: '10 10 10 10',
21 defaultButton
: 'savebutton',
23 xtype
: 'proxmoxintegerfield',
30 value
: viewModel
.get('days'),
31 fieldLabel
: gettext('Hours to show'),
34 text
: gettext('Save'),
35 reference
: 'savebutton',
38 var win
= this.up('window');
39 var days
= win
.down('#days').getValue();
40 me
.setDays(days
, true);
48 setDays: function(days
, setState
) {
50 var viewModel
= me
.getViewModel();
51 viewModel
.set('days', days
);
54 viewModel
.getStore('tasks').reload();
57 var sp
= Ext
.state
.Manager
.getProvider();
58 sp
.set('dashboard-days', days
);
63 updateSubscription: function(store
, records
, success
) {
64 if (!success
) { return; }
66 let subStatus
= records
[0].data
.status
=== 'Active' ? 2 : 0; // 2 = all good, 1 = different leves, 0 = none
67 me
.lookup('subscription').setSubStatus(subStatus
);
70 updateUsageStats: function(store
, records
, success
) {
74 if (records
=== undefined || records
.length
< 1) {
78 let viewmodel
= me
.getViewModel();
80 let res
= records
[0].data
;
81 viewmodel
.set('fingerprint', res
.info
.fingerprint
|| Proxmox
.Utils
.unknownText
);
87 var cpuPanel
= me
.lookup('cpu');
88 cpuPanel
.updateValue(cpu
);
90 var memPanel
= me
.lookup('mem');
91 memPanel
.updateValue(mem
.used
/ mem
.total
);
93 var hdPanel
= me
.lookup('root');
94 hdPanel
.updateValue(root
.used
/ root
.total
);
97 showFingerPrint: function() {
99 let vm
= me
.getViewModel();
100 let fingerprint
= vm
.get('fingerprint');
101 Ext
.create('Ext.window.Window', {
104 title
: gettext('Fingerprint'),
110 inputId
: 'fingerprintField',
118 iconCls
: 'fa fa-clipboard',
119 handler: function(b
) {
120 var el
= document
.getElementById('fingerprintField');
122 document
.execCommand("copy");
124 text
: gettext('Copy'),
128 handler: function() {
129 this.up('window').close();
136 updateTasks: function(store
, records
, success
) {
137 if (!success
) return;
139 let viewModel
= me
.getViewModel();
141 records
.sort((a
, b
) => a
.data
.duration
- b
.data
.duration
);
142 let top10
= records
.slice(-10);
143 me
.lookup('longesttasks').updateTasks(top10
);
146 backup
: { error
: 0, warning
: 0, ok
: 0 },
147 prune
: { error
: 0, warning
: 0, ok
: 0 },
148 garbage_collection
: { error
: 0, warning
: 0, ok
: 0 },
149 sync
: { error
: 0, warning
: 0, ok
: 0 },
150 verify
: { error
: 0, warning
: 0, ok
: 0 },
153 records
.forEach(record
=> {
154 let type
= record
.data
.worker_type
;
155 if (type
=== 'syncjob') {
159 if (type
.startsWith('verify')) {
163 if (data
[type
] && record
.data
.status
) {
164 let parsed
= Proxmox
.Utils
.parse_task_status(record
.data
.status
);
165 data
[type
][parsed
]++;
169 me
.lookup('tasksummary').updateTasks(data
, viewModel
.get('sinceEpoch'));
172 init: function(view
) {
174 var sp
= Ext
.state
.Manager
.getProvider();
175 var days
= sp
.get('dashboard-days') || 30;
176 me
.setDays(days
, false);
187 disableFPButton
: (get) => get('fingerprint') === "",
188 sinceEpoch
: (get) => (Date
.now()/1000 - get('days') * 24*3600).toFixed(0),
193 storeid
: 'dash-usage',
201 url
: '/api2/json/nodes/localhost/status',
204 load
: 'updateUsageStats',
208 storeid
: 'dash-subscription',
216 url
: '/api2/json/nodes/localhost/subscription',
219 load
: 'updateSubscription',
223 storeid
: 'dash-tasks',
229 model
: 'proxmox-tasks',
232 url
: '/api2/json/status/tasks',
234 since
: '{sinceEpoch}',
244 title
: gettext('Dashboard'),
250 bodyPadding
: '20 0 0 20',
261 handler
: 'openDashboardOptions',
270 iconCls
: 'fa fa-tasks',
271 title
: gettext('Server Resources'),
272 bodyPadding
: '0 20 0 20',
276 text
: gettext('Show Fingerprint'),
277 handler
: 'showFingerPrint',
279 disabled
: '{disableFPButton}',
288 xtype
: 'proxmoxGauge',
289 spriteFontSize
: '20px',
294 title
: gettext('CPU'),
298 title
: gettext('Memory'),
302 title
: gettext('Root Disk'),
308 xtype
: 'pbsDatastoresStatistics',
312 xtype
: 'pbsLongestTasks',
314 title
: gettext('Longest Tasks') + ' (' +
315 Ext
.String
.format(gettext('{0} days'), '{days}') + ')',
317 reference
: 'longesttasks',
321 xtype
: 'pbsRunningTasks',
326 title
: gettext('Task Summary') + ' (' +
327 Ext
.String
.format(gettext('{0} days'), '{days}') + ')',
329 xtype
: 'pbsTaskSummary',
330 reference
: 'tasksummary',
333 iconCls
: 'fa fa-ticket',
334 title
: 'Subscription',
336 reference
: 'subscription',
337 xtype
: 'pbsSubscriptionInfo',
342 Ext
.define('PBS.dashboard.SubscriptionInfo', {
343 extend
: 'Ext.panel.Panel',
344 xtype
: 'pbsSubscriptionInfo',
360 icon
: 'question-circle',
363 tpl
: '<center><i class="fa fa-3x fa-{icon}"></i></center>',
369 message
: gettext('Unknown'),
372 tpl
: '<center>{message}</center>',
376 setSubStatus: function(status
) {
384 message
= gettext('Your subscription status is valid.');
387 icon
= 'exclamation-triangle warning';
388 message
= gettext('Warning: Your subscription levels are not the same.');
391 icon
= 'times-circle critical';
392 message
= gettext('This node does not have a subscription.');
395 throw 'invalid subscription status';
397 me
.getComponent('icon').update({ icon
});
398 me
.getComponent('message').update({ message
});
405 var mainview
= this.component
.up('mainview');
406 mainview
.getController().redirectTo('pbsSubscription');