]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/dc/Summary.js
ui: ldap: add 'Check connection' checkbox as advanced option
[pve-manager.git] / www / manager6 / dc / Summary.js
1 Ext.define('PVE.dc.Summary', {
2 extend: 'Ext.panel.Panel',
3 alias: 'widget.pveDcSummary',
4
5 scrollable: true,
6
7 bodyPadding: 5,
8
9 layout: 'column',
10
11 defaults: {
12 padding: 5,
13 columnWidth: 1,
14 },
15
16 items: [
17 {
18 itemId: 'dcHealth',
19 xtype: 'pveDcHealth',
20 },
21 {
22 itemId: 'dcGuests',
23 xtype: 'pveDcGuests',
24 },
25 {
26 title: gettext('Resources'),
27 xtype: 'panel',
28 minHeight: 250,
29 bodyPadding: 5,
30 layout: 'hbox',
31 defaults: {
32 xtype: 'proxmoxGauge',
33 flex: 1,
34 },
35 items: [
36 {
37 title: gettext('CPU'),
38 itemId: 'cpu',
39 },
40 {
41 title: gettext('Memory'),
42 itemId: 'memory',
43 },
44 {
45 title: gettext('Storage'),
46 itemId: 'storage',
47 },
48 ],
49 },
50 {
51 itemId: 'nodeview',
52 xtype: 'pveDcNodeView',
53 height: 250,
54 },
55 {
56 title: gettext('Subscriptions'),
57 height: 220,
58 items: [
59 {
60 xtype: 'pveHealthWidget',
61 itemId: 'subscriptions',
62 userCls: 'pointer',
63 listeners: {
64 element: 'el',
65 click: function() {
66 if (this.component.userCls === 'pointer') {
67 window.open('https://www.proxmox.com/en/proxmox-ve/pricing', '_blank');
68 }
69 },
70 },
71 },
72 ],
73 },
74 ],
75
76 listeners: {
77 resize: function(panel) {
78 Proxmox.Utils.updateColumns(panel);
79 },
80 },
81
82 initComponent: function() {
83 var me = this;
84
85 var rstore = Ext.create('Proxmox.data.UpdateStore', {
86 interval: 3000,
87 storeid: 'pve-cluster-status',
88 model: 'pve-dc-nodes',
89 proxy: {
90 type: 'proxmox',
91 url: "/api2/json/cluster/status",
92 },
93 });
94
95 var gridstore = Ext.create('Proxmox.data.DiffStore', {
96 rstore: rstore,
97 filters: {
98 property: 'type',
99 value: 'node',
100 },
101 sorters: {
102 property: 'id',
103 direction: 'ASC',
104 },
105 });
106
107 me.callParent();
108
109 me.getComponent('nodeview').setStore(gridstore);
110
111 var gueststatus = me.getComponent('dcGuests');
112
113 var cpustat = me.down('#cpu');
114 var memorystat = me.down('#memory');
115 var storagestat = me.down('#storage');
116 var sp = Ext.state.Manager.getProvider();
117
118 me.mon(PVE.data.ResourceStore, 'load', function(curstore, results) {
119 me.suspendLayout = true;
120
121 let cpu = 0, maxcpu = 0;
122 let memory = 0, maxmem = 0;
123
124 let used = 0, total = 0;
125 let countedStorage = {}, usableStorages = {};
126 let storages = sp.get('dash-storages') || '';
127 storages.split(',').filter(v => v !== '').forEach(storage => {
128 usableStorages[storage] = true;
129 });
130
131 let qemu = {
132 running: 0,
133 paused: 0,
134 stopped: 0,
135 template: 0,
136 };
137 let lxc = {
138 running: 0,
139 paused: 0,
140 stopped: 0,
141 template: 0,
142 };
143 let error = 0;
144
145 for (const { data } of results) {
146 switch (data.type) {
147 case 'node':
148 cpu += data.cpu * data.maxcpu;
149 maxcpu += data.maxcpu || 0;
150 memory += data.mem || 0;
151 maxmem += data.maxmem || 0;
152
153 if (gridstore.getById(data.id)) {
154 let griditem = gridstore.getById(data.id);
155 griditem.set('cpuusage', data.cpu);
156 let max = data.maxmem || 1;
157 let val = data.mem || 0;
158 griditem.set('memoryusage', val / max);
159 griditem.set('uptime', data.uptime);
160 griditem.commit(); // else the store marks the field as dirty
161 }
162 break;
163 case 'storage': {
164 let sid = !data.shared || data.storage === 'local' ? data.id : data.storage;
165 if (!Ext.Object.isEmpty(usableStorages)) {
166 if (usableStorages[data.id] !== true) {
167 break;
168 }
169 sid = data.id;
170 } else if (countedStorage[sid]) {
171 break;
172 }
173 used += data.disk;
174 total += data.maxdisk;
175 countedStorage[sid] = true;
176 break;
177 }
178 case 'qemu':
179 qemu[data.template ? 'template' : data.status]++;
180 if (data.hastate === 'error') {
181 error++;
182 }
183 break;
184 case 'lxc':
185 lxc[data.template ? 'template' : data.status]++;
186 if (data.hastate === 'error') {
187 error++;
188 }
189 break;
190 default: break;
191 }
192 }
193
194 let text = Ext.String.format(gettext('of {0} CPU(s)'), maxcpu);
195 cpustat.updateValue(cpu/maxcpu, text);
196
197 text = Ext.String.format(gettext('{0} of {1}'), Proxmox.Utils.render_size(memory), Proxmox.Utils.render_size(maxmem));
198 memorystat.updateValue(memory/maxmem, text);
199
200 text = Ext.String.format(gettext('{0} of {1}'), Proxmox.Utils.render_size(used), Proxmox.Utils.render_size(total));
201 storagestat.updateValue(used/total, text);
202
203 gueststatus.updateValues(qemu, lxc, error);
204
205 me.suspendLayout = false;
206 me.updateLayout(true);
207 });
208
209 let dcHealth = me.getComponent('dcHealth');
210 me.mon(rstore, 'load', dcHealth.updateStatus, dcHealth);
211
212 let subs = me.down('#subscriptions');
213 me.mon(rstore, 'load', function(store, records, success) {
214 var level;
215 var mixed = false;
216 for (let i = 0; i < records.length; i++) {
217 let node = records[i];
218 if (node.get('type') !== 'node' || node.get('status') === 'offline') {
219 continue;
220 }
221
222 let curlevel = node.get('level');
223 if (curlevel === '') { // no subscription beats all, set it and break the loop
224 level = '';
225 break;
226 }
227
228 if (level === undefined) { // save level
229 level = curlevel;
230 } else if (level !== curlevel) { // detect different levels
231 mixed = true;
232 }
233 }
234
235 let data = {
236 title: Proxmox.Utils.unknownText,
237 text: Proxmox.Utils.unknownText,
238 iconCls: PVE.Utils.get_health_icon(undefined, true),
239 };
240 if (level === '') {
241 data = {
242 title: gettext('No Subscription'),
243 iconCls: PVE.Utils.get_health_icon('critical', true),
244 text: gettext('You have at least one node without subscription.'),
245 };
246 subs.setUserCls('pointer');
247 } else if (mixed) {
248 data = {
249 title: gettext('Mixed Subscriptions'),
250 iconCls: PVE.Utils.get_health_icon('warning', true),
251 text: gettext('Warning: Your subscription levels are not the same.'),
252 };
253 subs.setUserCls('pointer');
254 } else if (level) {
255 data = {
256 title: PVE.Utils.render_support_level(level),
257 iconCls: PVE.Utils.get_health_icon('good', true),
258 text: gettext('Your subscription status is valid.'),
259 };
260 subs.setUserCls('');
261 }
262
263 subs.setData(data);
264 });
265
266 me.on('destroy', function() {
267 rstore.stopUpdate();
268 });
269
270 me.mon(sp, 'statechange', function(provider, key, value) {
271 if (key !== 'summarycolumns') {
272 return;
273 }
274 Proxmox.Utils.updateColumns(me);
275 });
276
277 rstore.startUpdate();
278 },
279
280 });