]>
Commit | Line | Data |
---|---|---|
7c53ee24 DM |
1 | Ext.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') { | |
347f88fe | 67 | window.open('https://www.proxmox.com/en/proxmox-virtual-environment/pricing', '_blank'); |
841f1ed4 | 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 | } | |
b5600e66 IT |
173 | |
174 | if (data.status === "unknown") { | |
175 | break; | |
176 | } | |
177 | ||
a30dca2f TL |
178 | used += data.disk; |
179 | total += data.maxdisk; | |
180 | countedStorage[sid] = true; | |
50a1eb7d | 181 | break; |
a30dca2f | 182 | } |
50a1eb7d | 183 | case 'qemu': |
a30dca2f TL |
184 | qemu[data.template ? 'template' : data.status]++; |
185 | if (data.hastate === 'error') { | |
50a1eb7d DC |
186 | error++; |
187 | } | |
188 | break; | |
189 | case 'lxc': | |
a30dca2f TL |
190 | lxc[data.template ? 'template' : data.status]++; |
191 | if (data.hastate === 'error') { | |
50a1eb7d DC |
192 | error++; |
193 | } | |
194 | break; | |
195 | default: break; | |
196 | } | |
197 | } | |
198 | ||
a30dca2f | 199 | let text = Ext.String.format(gettext('of {0} CPU(s)'), maxcpu); |
53e3ea84 | 200 | cpustat.updateValue(cpu/maxcpu, text); |
50a1eb7d | 201 | |
1bd7bcdb | 202 | text = Ext.String.format(gettext('{0} of {1}'), Proxmox.Utils.render_size(memory), Proxmox.Utils.render_size(maxmem)); |
53e3ea84 | 203 | memorystat.updateValue(memory/maxmem, text); |
50a1eb7d | 204 | |
1bd7bcdb | 205 | text = Ext.String.format(gettext('{0} of {1}'), Proxmox.Utils.render_size(used), Proxmox.Utils.render_size(total)); |
53e3ea84 | 206 | storagestat.updateValue(used/total, text); |
50a1eb7d | 207 | |
f6710aac | 208 | gueststatus.updateValues(qemu, lxc, error); |
50a1eb7d DC |
209 | |
210 | me.suspendLayout = false; | |
211 | me.updateLayout(true); | |
212 | }); | |
213 | ||
a30dca2f | 214 | let dcHealth = me.getComponent('dcHealth'); |
50a1eb7d DC |
215 | me.mon(rstore, 'load', dcHealth.updateStatus, dcHealth); |
216 | ||
a30dca2f | 217 | let subs = me.down('#subscriptions'); |
f734486b | 218 | me.mon(rstore, 'load', function(store, records, success) { |
f734486b | 219 | var level; |
3747b7a2 | 220 | var mixed = false; |
a30dca2f TL |
221 | for (let i = 0; i < records.length; i++) { |
222 | let node = records[i]; | |
223 | if (node.get('type') !== 'node' || node.get('status') === 'offline') { | |
f734486b DC |
224 | continue; |
225 | } | |
595d0457 | 226 | |
a30dca2f TL |
227 | let curlevel = node.get('level'); |
228 | if (curlevel === '') { // no subscription beats all, set it and break the loop | |
595d0457 DC |
229 | level = ''; |
230 | break; | |
231 | } | |
f734486b | 232 | |
3512569d | 233 | if (level === undefined) { // save level |
f734486b | 234 | level = curlevel; |
3747b7a2 TL |
235 | } else if (level !== curlevel) { // detect different levels |
236 | mixed = true; | |
f734486b DC |
237 | } |
238 | } | |
239 | ||
a30dca2f | 240 | let data = { |
595d0457 DC |
241 | title: Proxmox.Utils.unknownText, |
242 | text: Proxmox.Utils.unknownText, | |
f6710aac | 243 | iconCls: PVE.Utils.get_health_icon(undefined, true), |
595d0457 | 244 | }; |
f734486b | 245 | if (level === '') { |
595d0457 | 246 | data = { |
f734486b DC |
247 | title: gettext('No Subscription'), |
248 | iconCls: PVE.Utils.get_health_icon('critical', true), | |
f6710aac | 249 | text: gettext('You have at least one node without subscription.'), |
595d0457 | 250 | }; |
841f1ed4 | 251 | subs.setUserCls('pointer'); |
3747b7a2 | 252 | } else if (mixed) { |
595d0457 | 253 | data = { |
f734486b DC |
254 | title: gettext('Mixed Subscriptions'), |
255 | iconCls: PVE.Utils.get_health_icon('warning', true), | |
f6710aac | 256 | text: gettext('Warning: Your subscription levels are not the same.'), |
595d0457 | 257 | }; |
841f1ed4 | 258 | subs.setUserCls('pointer'); |
595d0457 DC |
259 | } else if (level) { |
260 | data = { | |
f734486b DC |
261 | title: PVE.Utils.render_support_level(level), |
262 | iconCls: PVE.Utils.get_health_icon('good', true), | |
f6710aac | 263 | text: gettext('Your subscription status is valid.'), |
595d0457 | 264 | }; |
841f1ed4 | 265 | subs.setUserCls(''); |
f734486b | 266 | } |
595d0457 DC |
267 | |
268 | subs.setData(data); | |
f734486b DC |
269 | }); |
270 | ||
8058410f | 271 | me.on('destroy', function() { |
cf8b372a DC |
272 | rstore.stopUpdate(); |
273 | }); | |
274 | ||
f973c5b2 DC |
275 | me.mon(sp, 'statechange', function(provider, key, value) { |
276 | if (key !== 'summarycolumns') { | |
277 | return; | |
278 | } | |
2874be00 | 279 | Proxmox.Utils.updateColumns(me); |
f973c5b2 DC |
280 | }); |
281 | ||
cf8b372a | 282 | rstore.startUpdate(); |
f6710aac | 283 | }, |
50a1eb7d | 284 | |
7c53ee24 | 285 | }); |