]>
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 | ||
7 | bodyPadding: '10 0 0 0', | |
8 | ||
9 | layout: 'column', | |
10 | ||
11 | defaults: { | |
12 | width: 762, | |
13 | padding: '0 0 10 10' | |
14 | }, | |
15 | ||
16 | items: [ | |
50a1eb7d DC |
17 | { |
18 | itemId: 'dcHealth', | |
19 | xtype: 'pveDcHealth' | |
20 | }, | |
21 | { | |
22 | itemId: 'dcGuests', | |
23 | xtype: 'pveDcGuests' | |
24 | }, | |
25 | { | |
8f8ec25d | 26 | title: gettext('Resources'), |
50a1eb7d DC |
27 | xtype: 'panel', |
28 | height: 250, | |
29 | bodyPadding: '0 0 10 0', | |
30 | layout: 'column', | |
31 | defaults: { | |
32 | xtype: 'pveGauge', | |
33 | columnWidth: 1/3 | |
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 | }, | |
cf8b372a DC |
50 | { |
51 | itemId: 'nodeview', | |
52 | xtype: 'pveDcNodeView', | |
53 | height: 250 | |
54 | } | |
55 | ], | |
7c53ee24 DM |
56 | |
57 | initComponent: function() { | |
58 | var me = this; | |
59 | ||
cf8b372a DC |
60 | var rstore = Ext.create('PVE.data.UpdateStore', { |
61 | interval: 3000, | |
62 | storeid: 'pve-cluster-status', | |
63 | model: 'pve-dc-nodes', | |
64 | proxy: { | |
65 | type: 'pve', | |
66 | url: "/api2/json/cluster/status" | |
67 | } | |
7c53ee24 DM |
68 | }); |
69 | ||
cf8b372a DC |
70 | var gridstore = Ext.create('PVE.data.DiffStore', { |
71 | rstore: rstore, | |
72 | filters: { | |
73 | property: 'type', | |
74 | value: 'node' | |
75 | }, | |
76 | sorters: { | |
77 | property: 'id', | |
78 | direction: 'ASC' | |
7c53ee24 DM |
79 | } |
80 | }); | |
81 | ||
82 | me.callParent(); | |
cf8b372a DC |
83 | |
84 | me.getComponent('nodeview').setStore(gridstore); | |
85 | ||
50a1eb7d DC |
86 | var gueststatus = me.getComponent('dcGuests'); |
87 | ||
88 | var cpustat = me.down('#cpu'); | |
89 | var memorystat = me.down('#memory'); | |
90 | var storagestat = me.down('#storage'); | |
0d1c1267 | 91 | var sp = Ext.state.Manager.getProvider(); |
50a1eb7d DC |
92 | |
93 | me.mon(PVE.data.ResourceStore, 'load', function(curstore, results) { | |
94 | me.suspendLayout = true; | |
95 | ||
96 | var cpu = 0; | |
97 | var maxcpu = 0; | |
98 | ||
99 | var nodes = 0; | |
100 | ||
101 | var memory = 0; | |
102 | var maxmem = 0; | |
103 | ||
104 | var countedStorages = {}; | |
105 | var used = 0; | |
106 | var total = 0; | |
0d1c1267 DC |
107 | var usableStorages = {}; |
108 | var storages = sp.get('dash-storages') || ''; | |
109 | storages.split(',').forEach(function(storage){ | |
110 | if (storage !== '') { | |
111 | usableStorages[storage] = true; | |
112 | } | |
113 | }); | |
50a1eb7d DC |
114 | |
115 | var qemu = { | |
116 | running: 0, | |
117 | paused: 0, | |
118 | stopped: 0, | |
119 | template: 0 | |
120 | }; | |
121 | var lxc = { | |
122 | running: 0, | |
123 | paused: 0, | |
124 | stopped: 0, | |
125 | template: 0 | |
126 | }; | |
127 | var error = 0; | |
128 | ||
129 | var i; | |
130 | ||
131 | for (i = 0; i < results.length; i++) { | |
132 | var item = results[i]; | |
133 | switch(item.data.type) { | |
134 | case 'node': | |
135 | cpu += (item.data.cpu * item.data.maxcpu); | |
136 | maxcpu += item.data.maxcpu || 0; | |
137 | memory += item.data.mem || 0; | |
138 | maxmem += item.data.maxmem || 0; | |
139 | nodes++; | |
140 | ||
141 | // update grid also | |
142 | var griditem = gridstore.getById(item.data.id); | |
143 | if (griditem) { | |
144 | griditem.set('cpuusage', item.data.cpu); | |
145 | var max = item.data.maxmem || 1; | |
146 | var val = item.data.mem || 0; | |
147 | griditem.set('memoryusage', val/max); | |
148 | griditem.set('uptime', item.data.uptime); | |
149 | griditem.commit(); //else it marks the fields as dirty | |
150 | } | |
151 | break; | |
152 | case 'storage': | |
0d1c1267 DC |
153 | if (!Ext.Object.isEmpty(usableStorages)) { |
154 | if (usableStorages[item.data.id] === true) { | |
155 | used += item.data.disk; | |
156 | total += item.data.maxdisk; | |
157 | } | |
158 | break; | |
159 | } | |
50a1eb7d DC |
160 | if (!countedStorages[item.data.storage] || |
161 | (item.data.storage === 'local' && | |
162 | !countedStorages[item.data.id])) { | |
163 | used += item.data.disk; | |
164 | total += item.data.maxdisk; | |
165 | ||
166 | countedStorages[item.data.storage === 'local'?item.data.id:item.data.storage] = true; | |
167 | } | |
168 | break; | |
169 | case 'qemu': | |
170 | qemu[item.data.template ? 'template' : item.data.status]++; | |
171 | if (item.data.hastate === 'error') { | |
172 | error++; | |
173 | } | |
174 | break; | |
175 | case 'lxc': | |
176 | lxc[item.data.template ? 'template' : item.data.status]++; | |
177 | if (item.data.hastate === 'error') { | |
178 | error++; | |
179 | } | |
180 | break; | |
181 | default: break; | |
182 | } | |
183 | } | |
184 | ||
185 | var text = Ext.String.format(gettext('of {0} CPU(s)'), maxcpu); | |
186 | cpustat.updateValue((cpu/maxcpu), text); | |
187 | ||
188 | text = Ext.String.format(gettext('{0} of {1}'), PVE.Utils.render_size(memory), PVE.Utils.render_size(maxmem)); | |
189 | memorystat.updateValue((memory/maxmem), text); | |
190 | ||
191 | text = Ext.String.format(gettext('{0} of {1}'), PVE.Utils.render_size(used), PVE.Utils.render_size(total)); | |
192 | storagestat.updateValue((used/total), text); | |
193 | ||
194 | gueststatus.updateValues(qemu,lxc,error); | |
195 | ||
196 | me.suspendLayout = false; | |
197 | me.updateLayout(true); | |
198 | }); | |
199 | ||
200 | var dcHealth = me.getComponent('dcHealth'); | |
201 | me.mon(rstore, 'load', dcHealth.updateStatus, dcHealth); | |
202 | ||
cf8b372a DC |
203 | me.on('destroy', function(){ |
204 | rstore.stopUpdate(); | |
205 | }); | |
206 | ||
207 | rstore.startUpdate(); | |
7c53ee24 | 208 | } |
50a1eb7d | 209 | |
7c53ee24 | 210 | }); |