]>
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 | { | |
60 | itemId: 'subscriptions', | |
841f1ed4 DC |
61 | xtype: 'pveHealthWidget', |
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) { | |
78 | PVE.Utils.updateColumns(panel); | |
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 | ||
121 | var cpu = 0; | |
122 | var maxcpu = 0; | |
123 | ||
124 | var nodes = 0; | |
125 | ||
126 | var memory = 0; | |
127 | var maxmem = 0; | |
128 | ||
129 | var countedStorages = {}; | |
130 | var used = 0; | |
131 | var total = 0; | |
0d1c1267 DC |
132 | var usableStorages = {}; |
133 | var storages = sp.get('dash-storages') || ''; | |
8058410f | 134 | storages.split(',').forEach(function(storage) { |
0d1c1267 DC |
135 | if (storage !== '') { |
136 | usableStorages[storage] = true; | |
137 | } | |
138 | }); | |
50a1eb7d DC |
139 | |
140 | var qemu = { | |
141 | running: 0, | |
142 | paused: 0, | |
143 | stopped: 0, | |
f6710aac | 144 | template: 0, |
50a1eb7d DC |
145 | }; |
146 | var lxc = { | |
147 | running: 0, | |
148 | paused: 0, | |
149 | stopped: 0, | |
f6710aac | 150 | template: 0, |
50a1eb7d DC |
151 | }; |
152 | var error = 0; | |
153 | ||
154 | var i; | |
155 | ||
156 | for (i = 0; i < results.length; i++) { | |
157 | var item = results[i]; | |
8058410f | 158 | switch (item.data.type) { |
50a1eb7d | 159 | case 'node': |
53e3ea84 | 160 | cpu += item.data.cpu * item.data.maxcpu; |
50a1eb7d DC |
161 | maxcpu += item.data.maxcpu || 0; |
162 | memory += item.data.mem || 0; | |
163 | maxmem += item.data.maxmem || 0; | |
164 | nodes++; | |
165 | ||
166 | // update grid also | |
167 | var griditem = gridstore.getById(item.data.id); | |
168 | if (griditem) { | |
169 | griditem.set('cpuusage', item.data.cpu); | |
170 | var max = item.data.maxmem || 1; | |
171 | var val = item.data.mem || 0; | |
172 | griditem.set('memoryusage', val/max); | |
173 | griditem.set('uptime', item.data.uptime); | |
174 | griditem.commit(); //else it marks the fields as dirty | |
175 | } | |
176 | break; | |
177 | case 'storage': | |
0d1c1267 DC |
178 | if (!Ext.Object.isEmpty(usableStorages)) { |
179 | if (usableStorages[item.data.id] === true) { | |
180 | used += item.data.disk; | |
181 | total += item.data.maxdisk; | |
182 | } | |
183 | break; | |
184 | } | |
50a1eb7d | 185 | if (!countedStorages[item.data.storage] || |
53e3ea84 | 186 | !item.data.shared && !countedStorages[item.data.id]) { |
50a1eb7d DC |
187 | used += item.data.disk; |
188 | total += item.data.maxdisk; | |
189 | ||
190 | countedStorages[item.data.storage === 'local'?item.data.id:item.data.storage] = true; | |
191 | } | |
192 | break; | |
193 | case 'qemu': | |
194 | qemu[item.data.template ? 'template' : item.data.status]++; | |
195 | if (item.data.hastate === 'error') { | |
196 | error++; | |
197 | } | |
198 | break; | |
199 | case 'lxc': | |
200 | lxc[item.data.template ? 'template' : item.data.status]++; | |
201 | if (item.data.hastate === 'error') { | |
202 | error++; | |
203 | } | |
204 | break; | |
205 | default: break; | |
206 | } | |
207 | } | |
208 | ||
209 | var text = Ext.String.format(gettext('of {0} CPU(s)'), maxcpu); | |
53e3ea84 | 210 | cpustat.updateValue(cpu/maxcpu, text); |
50a1eb7d | 211 | |
1bd7bcdb | 212 | text = Ext.String.format(gettext('{0} of {1}'), Proxmox.Utils.render_size(memory), Proxmox.Utils.render_size(maxmem)); |
53e3ea84 | 213 | memorystat.updateValue(memory/maxmem, text); |
50a1eb7d | 214 | |
1bd7bcdb | 215 | text = Ext.String.format(gettext('{0} of {1}'), Proxmox.Utils.render_size(used), Proxmox.Utils.render_size(total)); |
53e3ea84 | 216 | storagestat.updateValue(used/total, text); |
50a1eb7d | 217 | |
f6710aac | 218 | gueststatus.updateValues(qemu, lxc, error); |
50a1eb7d DC |
219 | |
220 | me.suspendLayout = false; | |
221 | me.updateLayout(true); | |
222 | }); | |
223 | ||
224 | var dcHealth = me.getComponent('dcHealth'); | |
225 | me.mon(rstore, 'load', dcHealth.updateStatus, dcHealth); | |
226 | ||
f734486b DC |
227 | var subs = me.down('#subscriptions'); |
228 | me.mon(rstore, 'load', function(store, records, success) { | |
229 | var i; | |
230 | var level; | |
3747b7a2 | 231 | var mixed = false; |
f734486b DC |
232 | for (i = 0; i < records.length; i++) { |
233 | if (records[i].get('type') !== 'node') { | |
234 | continue; | |
235 | } | |
595d0457 DC |
236 | var node = records[i]; |
237 | if (node.get('status') === 'offline') { | |
238 | continue; | |
239 | } | |
240 | ||
3747b7a2 | 241 | var curlevel = node.get('level'); |
595d0457 | 242 | |
3512569d | 243 | if (curlevel === '') { // no subscription trumps all, set and break |
595d0457 DC |
244 | level = ''; |
245 | break; | |
246 | } | |
f734486b | 247 | |
3512569d | 248 | if (level === undefined) { // save level |
f734486b | 249 | level = curlevel; |
3747b7a2 TL |
250 | } else if (level !== curlevel) { // detect different levels |
251 | mixed = true; | |
f734486b DC |
252 | } |
253 | } | |
254 | ||
595d0457 DC |
255 | var data = { |
256 | title: Proxmox.Utils.unknownText, | |
257 | text: Proxmox.Utils.unknownText, | |
f6710aac | 258 | iconCls: PVE.Utils.get_health_icon(undefined, true), |
595d0457 | 259 | }; |
f734486b | 260 | if (level === '') { |
595d0457 | 261 | data = { |
f734486b DC |
262 | title: gettext('No Subscription'), |
263 | iconCls: PVE.Utils.get_health_icon('critical', true), | |
f6710aac | 264 | text: gettext('You have at least one node without subscription.'), |
595d0457 | 265 | }; |
841f1ed4 | 266 | subs.setUserCls('pointer'); |
3747b7a2 | 267 | } else if (mixed) { |
595d0457 | 268 | data = { |
f734486b DC |
269 | title: gettext('Mixed Subscriptions'), |
270 | iconCls: PVE.Utils.get_health_icon('warning', true), | |
f6710aac | 271 | text: gettext('Warning: Your subscription levels are not the same.'), |
595d0457 | 272 | }; |
841f1ed4 | 273 | subs.setUserCls('pointer'); |
595d0457 DC |
274 | } else if (level) { |
275 | data = { | |
f734486b DC |
276 | title: PVE.Utils.render_support_level(level), |
277 | iconCls: PVE.Utils.get_health_icon('good', true), | |
f6710aac | 278 | text: gettext('Your subscription status is valid.'), |
595d0457 | 279 | }; |
841f1ed4 | 280 | subs.setUserCls(''); |
f734486b | 281 | } |
595d0457 DC |
282 | |
283 | subs.setData(data); | |
f734486b DC |
284 | }); |
285 | ||
8058410f | 286 | me.on('destroy', function() { |
cf8b372a DC |
287 | rstore.stopUpdate(); |
288 | }); | |
289 | ||
f973c5b2 DC |
290 | me.mon(sp, 'statechange', function(provider, key, value) { |
291 | if (key !== 'summarycolumns') { | |
292 | return; | |
293 | } | |
294 | PVE.Utils.updateColumns(me); | |
295 | }); | |
296 | ||
cf8b372a | 297 | rstore.startUpdate(); |
f6710aac | 298 | }, |
50a1eb7d | 299 | |
7c53ee24 | 300 | }); |