Skip to content

Commit 14a97f4

Browse files
hhellyertobespc
authored andcommitted
Re-send static data when the client confirms it's connected (#102)
* Re-send static data when the client confirms it's connected to avoid timing issues. * Increment the version number
1 parent 3e5d42c commit 14a97f4

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

lib/appmetrics-dash.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -180,41 +180,51 @@ exports.monitor = function(options) {
180180
*/
181181
io.on('connection', function(socket) {
182182
var env = monitoring.getEnvironment();
183-
var result = [];
183+
var envData = [];
184184
var json;
185185
for (var entry in env) {
186186
switch (entry) {
187187
case 'command.line':
188188
json = {};
189189
json['Parameter'] = 'Command Line';
190190
json['Value'] = env[entry];
191-
result.push(json);
191+
envData.push(json);
192192
break;
193193
case 'environment.HOSTNAME':
194194
json = {};
195195
json['Parameter'] = 'Hostname';
196196
json['Value'] = env[entry];
197-
result.push(json);
197+
envData.push(json);
198198
break;
199199
case 'os.arch':
200200
json = {};
201201
json['Parameter'] = 'OS Architecture';
202202
json['Value'] = env[entry];
203-
result.push(json);
203+
envData.push(json);
204204
break;
205205
case 'number.of.processors':
206206
json = {};
207207
json['Parameter'] = 'Number of Processors';
208208
json['Value'] = env[entry];
209-
result.push(json);
209+
envData.push(json);
210210
break;
211211
default:
212212
break;
213213
}
214214
}
215-
socket.emit('environment', JSON.stringify(result));
215+
// Send static data ASAP but re-send below in case the client isn't ready.
216+
socket.emit('environment', JSON.stringify(envData));
216217
socket.emit('title', JSON.stringify({title: title, docs: docs}));
217218
socket.emit('status', JSON.stringify({profiling_enabled: profiling_enabled}));
219+
220+
// When the client confirms it's connected and has listeners ready,
221+
// re-send the static data.
222+
socket.on('connected', () => {
223+
socket.emit('environment', JSON.stringify(envData));
224+
socket.emit('title', JSON.stringify({title: title, docs: docs}));
225+
socket.emit('status', JSON.stringify({profiling_enabled: profiling_enabled}));
226+
});
227+
218228
/*
219229
* Support enabling/disabling profiling data
220230
*/

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "appmetrics-dash",
3-
"version": "3.3.1",
3+
"version": "3.3.2",
44
"description": "Embedded monitoring dashboard for Node.js applications.",
55
"main": "index.js",
66
"dependencies": {

public/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,9 @@ <h4 class="modal-title" font-color=black>Heap Snapshot</h4>
219219
}
220220
</script>
221221
<script type="text/javascript" src="graphmetrics/js/header.js"></script>
222+
<script type="text/javascript" src="graphmetrics/js/nodeReport.js"></script>
222223

223224
<!--
224-
<script type="text/javascript" src="graphmetrics/js/nodeReport.js"></script>
225225
<script type="text/javascript" src="graphmetrics/js/envTable.js"></script>
226226
<script type="text/javascript" src="graphmetrics/js/cpuChart.js"></script>
227227

0 commit comments

Comments
 (0)