]>
Commit | Line | Data |
---|---|---|
0b659b8e DC |
1 | Ext.define('PVE.dc.Health', { |
2 | extend: 'Ext.panel.Panel', | |
3 | alias: 'widget.pveDcHealth', | |
4 | ||
5 | title: gettext('Datacenter Health'), | |
6 | ||
7 | bodyPadding: '0 20 0 20', | |
8 | height: 200, | |
9 | layout: 'column', | |
10 | ||
11 | defaults: { | |
12 | columnWidth: 0.5, | |
13 | xtype: 'box', | |
14 | style: { | |
15 | 'text-align':'center' | |
16 | } | |
17 | }, | |
18 | ||
19 | cepherrors: 0, | |
20 | ||
21 | updateStatus: function(store, records, success) { | |
22 | var me = this; | |
23 | if (!success) { | |
24 | return; | |
25 | } | |
26 | ||
27 | var cluster = { | |
428bc4a2 | 28 | iconCls: PVE.Utils.get_health_icon('good', true), |
0b659b8e DC |
29 | text: gettext("Standalone node - no cluster defined") |
30 | }; | |
31 | ||
32 | var nodes = { | |
33 | online: 0, | |
34 | offline: 0 | |
35 | }; | |
36 | ||
37 | // by default we have one node | |
38 | var numNodes = 1; | |
39 | var i; | |
40 | ||
41 | for (i = 0; i < records.length; i++) { | |
42 | var item = records[i]; | |
43 | if (item.data.type === 'node') { | |
44 | nodes[item.data.online === 1 ? 'online':'offline']++; | |
45 | } else if(item.data.type === 'cluster') { | |
46 | cluster.text = gettext("Cluster") + ": "; | |
47 | cluster.text += item.data.name + ", "; | |
48 | cluster.text += gettext("Quorate") + ": "; | |
49 | cluster.text += PVE.Utils.format_boolean(item.data.quorate); | |
50 | if (item.data.quorate != 1) { | |
428bc4a2 | 51 | cluster.iconCls = PVE.Utils.get_health_icon('critical', true); |
0b659b8e DC |
52 | } |
53 | ||
54 | numNodes = item.data.nodes; | |
55 | } | |
56 | } | |
57 | ||
58 | if (numNodes !== (nodes.online + nodes.offline)) { | |
59 | nodes.offline = numNodes - nodes.online; | |
60 | } | |
61 | ||
62 | me.getComponent('clusterstatus').update(cluster); | |
63 | me.getComponent('nodestatus').update(nodes); | |
64 | }, | |
65 | ||
66 | updateCeph: function(store, records, success) { | |
67 | var me = this; | |
68 | var cephstatus = me.getComponent('ceph'); | |
69 | if (!success || records.length < 1) { | |
70 | me.cepherrors++; | |
71 | cephstatus.setVisible(false); | |
72 | ||
73 | // after 3 unsuccessful tries of | |
74 | // /nodes/localhost/ceph/status | |
75 | // we give up (there probably is no ceph installed) | |
76 | if (me.cepherrors >= 3) { | |
77 | me.cephstore.stopUpdate(); | |
78 | } | |
79 | return; | |
80 | } | |
81 | ||
82 | me.cepherrors = 0; | |
83 | ||
84 | var cephstate = { | |
85 | iconCls: 'faded fa-question-circle', | |
86 | text: '' | |
87 | }; | |
88 | ||
89 | switch (records[0].data.health.overall_status) { | |
90 | case 'HEALTH_OK': | |
91 | cephstate.iconCls = 'good fa-check-circle'; | |
92 | break; | |
93 | case 'HEALTH_WARN': | |
94 | cephstate.iconCls = 'warning fa-info-circle'; | |
95 | break; | |
96 | case 'HEALTH_ERR': | |
97 | cephstate.iconCls = 'critical fa-times-circle'; | |
98 | break; | |
99 | default: | |
100 | cephstate.iconCls = 'faded fa-question-circle'; | |
101 | break; | |
102 | } | |
103 | cephstate.text = records[0].data.health.overall_status; | |
104 | cephstatus.update(cephstate); | |
105 | cephstatus.setVisible(true); | |
106 | }, | |
107 | ||
108 | listeners: { | |
109 | destroy: function() { | |
110 | var me = this; | |
111 | me.cephstore.stopUpdate(); | |
112 | } | |
113 | }, | |
114 | ||
115 | items: [ | |
116 | { | |
117 | itemId: 'clusterstatus', | |
118 | data: { | |
119 | iconCls: 'faded fa-question-circle', | |
120 | text: '' | |
121 | }, | |
122 | tpl: [ | |
123 | '<h3>' + gettext('Status') + '</h3>', | |
124 | '<i class="fa fa-5x {iconCls}"></i>', | |
125 | '<br /><br/>', | |
126 | '{text}' | |
127 | ] | |
128 | }, | |
129 | { | |
130 | itemId: 'nodestatus', | |
131 | data: { | |
132 | online: 0, | |
133 | offline: 0 | |
134 | }, | |
135 | tpl: [ | |
136 | '<h3>' + gettext('Nodes') + '</h3><br />', | |
137 | '<div style="width: 150px;margin: auto;font-size: 12pt">', | |
138 | '<div class="left-aligned">', | |
139 | '<i class="good fa fa-fw fa-check"> </i>', | |
140 | gettext('Online'), | |
141 | '</div>', | |
142 | '<div class="right-aligned">{online}</div>', | |
143 | '<br /><br />', | |
144 | '<div class="left-aligned">', | |
145 | '<i class="critical fa fa-fw fa-times"> </i>', | |
146 | gettext('Offline'), | |
147 | '</div>', | |
148 | '<div class="right-aligned">{offline}</div>', | |
149 | '</div>' | |
150 | ] | |
151 | }, | |
152 | { | |
153 | itemId: 'ceph', | |
154 | width: 250, | |
155 | columnWidth: undefined, | |
156 | data: { | |
157 | text: '', | |
158 | iconCls: 'faded fa-question-circle' | |
159 | }, | |
160 | tpl: [ | |
161 | '<h3>Ceph</h3>', | |
162 | '<i class="fa fa-5x {iconCls}"></i><br /><br />', | |
163 | gettext("Health") + ': {text}' | |
164 | ], | |
165 | hidden: true | |
166 | } | |
167 | ], | |
168 | ||
169 | initComponent: function() { | |
170 | var me = this; | |
171 | ||
172 | me.cephstore = Ext.create('PVE.data.UpdateStore', { | |
173 | interval: 3000, | |
174 | storeid: 'pve-cluster-ceph', | |
175 | proxy: { | |
176 | type: 'pve', | |
177 | url: '/api2/json/nodes/localhost/ceph/status' | |
178 | } | |
179 | }); | |
180 | me.callParent(); | |
181 | me.cephstore.startUpdate(); | |
182 | me.mon(me.cephstore, 'load', me.updateCeph, me); | |
183 | } | |
184 | }); |