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