]>
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('Days 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 status
= records
[0].data
.status
|| 'unknown';
67 // 2 = all good, 1 = different leves, 0 = none
68 let subStatus
= status
.toLowerCase() === 'active' ? 2 : 0;
69 me
.lookup('subscription').setSubStatus(subStatus
);
72 updateUsageStats: function(store
, records
, success
) {
76 if (records
=== undefined || records
.length
< 1) {
80 let viewmodel
= me
.getViewModel();
82 let res
= records
[0].data
;
83 viewmodel
.set('fingerprint', res
.info
.fingerprint
|| Proxmox
.Utils
.unknownText
);
89 var cpuPanel
= me
.lookup('cpu');
90 cpuPanel
.updateValue(cpu
);
92 var memPanel
= me
.lookup('mem');
93 memPanel
.updateValue(mem
.used
/ mem
.total
);
95 var hdPanel
= me
.lookup('root');
96 hdPanel
.updateValue(root
.used
/ root
.total
);
99 showFingerPrint: function() {
101 let vm
= me
.getViewModel();
102 let fingerprint
= vm
.get('fingerprint');
103 Ext
.create('Ext.window.Window', {
106 title
: gettext('Fingerprint'),
112 inputId
: 'fingerprintField',
120 iconCls
: 'fa fa-clipboard',
121 handler: function(b
) {
122 var el
= document
.getElementById('fingerprintField');
124 document
.execCommand("copy");
126 text
: gettext('Copy'),
130 handler: function() {
131 this.up('window').close();
138 updateTasks: function(store
, records
, success
) {
139 if (!success
) return;
141 let viewModel
= me
.getViewModel();
143 records
.sort((a
, b
) => a
.data
.duration
- b
.data
.duration
);
144 let top10
= records
.slice(-10);
145 me
.lookup('longesttasks').updateTasks(top10
);
148 backup
: { error
: 0, warning
: 0, ok
: 0 },
149 prune
: { error
: 0, warning
: 0, ok
: 0 },
150 garbage_collection
: { error
: 0, warning
: 0, ok
: 0 },
151 sync
: { error
: 0, warning
: 0, ok
: 0 },
152 verify
: { error
: 0, warning
: 0, ok
: 0 },
155 records
.forEach(record
=> {
156 let task
= record
.data
;
157 let type
= task
.worker_type
;
158 if (type
=== 'syncjob') {
162 if (type
.startsWith('verif')) {
166 if (data
[type
] && task
.status
) {
167 let parsed
= Proxmox
.Utils
.parse_task_status(task
.status
);
168 data
[type
][parsed
]++;
172 me
.lookup('tasksummary').updateTasks(data
, viewModel
.get('sinceEpoch'));
175 init: function(view
) {
177 var sp
= Ext
.state
.Manager
.getProvider();
178 var days
= sp
.get('dashboard-days') || 30;
179 me
.setDays(days
, false);
190 disableFPButton
: (get) => get('fingerprint') === "",
191 sinceEpoch
: (get) => (Date
.now()/1000 - get('days') * 24*3600).toFixed(0),
196 storeid
: 'dash-usage',
204 url
: '/api2/json/nodes/localhost/status',
207 load
: 'updateUsageStats',
211 storeid
: 'dash-subscription',
219 url
: '/api2/json/nodes/localhost/subscription',
222 load
: 'updateSubscription',
226 storeid
: 'dash-tasks',
232 model
: 'proxmox-tasks',
235 url
: '/api2/json/nodes/localhost/tasks',
238 since
: '{sinceEpoch}',
248 title
: gettext('Dashboard'),
254 bodyPadding
: '20 0 0 20',
265 tooltip
: gettext('Edit dashboard settings'),
266 handler
: 'openDashboardOptions',
275 iconCls
: 'fa fa-tasks',
276 title
: gettext('Server Resources'),
277 bodyPadding
: '0 20 0 20',
281 text
: gettext('Show Fingerprint'),
282 handler
: 'showFingerPrint',
284 disabled
: '{disableFPButton}',
293 xtype
: 'proxmoxGauge',
294 spriteFontSize
: '20px',
299 title
: gettext('CPU'),
303 title
: gettext('Memory'),
307 title
: gettext('Root Disk'),
313 xtype
: 'pbsDatastoresStatistics',
317 xtype
: 'pbsLongestTasks',
319 title
: gettext('Longest Tasks') + ' (' +
320 Ext
.String
.format(gettext('{0} days'), '{days}') + ')',
322 reference
: 'longesttasks',
326 xtype
: 'pbsRunningTasks',
331 title
: gettext('Task Summary') + ' (' +
332 Ext
.String
.format(gettext('{0} days'), '{days}') + ')',
334 xtype
: 'pbsTaskSummary',
336 reference
: 'tasksummary',
339 iconCls
: 'fa fa-ticket',
340 title
: 'Subscription',
342 reference
: 'subscription',
343 xtype
: 'pbsSubscriptionInfo',
348 Ext
.define('PBS.dashboard.SubscriptionInfo', {
349 extend
: 'Ext.panel.Panel',
350 xtype
: 'pbsSubscriptionInfo',
366 icon
: 'question-circle',
369 tpl
: '<center><i class="fa fa-3x fa-{icon}"></i></center>',
375 message
: gettext('Unknown'),
378 tpl
: '<center>{message}</center>',
382 setSubStatus: function(status
) {
390 message
= gettext('Your subscription status is valid.');
393 icon
= 'exclamation-triangle warning';
394 message
= gettext('Warning: Your subscription levels are not the same.');
397 icon
= 'times-circle critical';
398 message
= `<h1>${gettext('No valid subscription')}</h1>${PBS.Utils.noSubKeyHtml}`;
401 throw 'invalid subscription status';
403 me
.getComponent('icon').update({ icon
});
404 me
.getComponent('message').update({ message
});
411 var mainview
= this.component
.up('mainview');
412 mainview
.getController().redirectTo('pbsSubscription');