Skip to content

Commit

Permalink
Re-send static data when the client confirms it's connected (#102)
Browse files Browse the repository at this point in the history
* Re-send static data when the client confirms it's connected to avoid timing issues.

* Increment the version number
  • Loading branch information
hhellyer authored and tobespc committed Aug 4, 2017
1 parent 3e5d42c commit 14a97f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
22 changes: 16 additions & 6 deletions lib/appmetrics-dash.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,41 +180,51 @@ exports.monitor = function(options) {
*/
io.on('connection', function(socket) {
var env = monitoring.getEnvironment();
var result = [];
var envData = [];
var json;
for (var entry in env) {
switch (entry) {
case 'command.line':
json = {};
json['Parameter'] = 'Command Line';
json['Value'] = env[entry];
result.push(json);
envData.push(json);
break;
case 'environment.HOSTNAME':
json = {};
json['Parameter'] = 'Hostname';
json['Value'] = env[entry];
result.push(json);
envData.push(json);
break;
case 'os.arch':
json = {};
json['Parameter'] = 'OS Architecture';
json['Value'] = env[entry];
result.push(json);
envData.push(json);
break;
case 'number.of.processors':
json = {};
json['Parameter'] = 'Number of Processors';
json['Value'] = env[entry];
result.push(json);
envData.push(json);
break;
default:
break;
}
}
socket.emit('environment', JSON.stringify(result));
// Send static data ASAP but re-send below in case the client isn't ready.
socket.emit('environment', JSON.stringify(envData));
socket.emit('title', JSON.stringify({title: title, docs: docs}));
socket.emit('status', JSON.stringify({profiling_enabled: profiling_enabled}));

// When the client confirms it's connected and has listeners ready,
// re-send the static data.
socket.on('connected', () => {
socket.emit('environment', JSON.stringify(envData));
socket.emit('title', JSON.stringify({title: title, docs: docs}));
socket.emit('status', JSON.stringify({profiling_enabled: profiling_enabled}));
});

/*
* Support enabling/disabling profiling data
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "appmetrics-dash",
"version": "3.3.1",
"version": "3.3.2",
"description": "Embedded monitoring dashboard for Node.js applications.",
"main": "index.js",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ <h4 class="modal-title" font-color=black>Heap Snapshot</h4>
}
</script>
<script type="text/javascript" src="graphmetrics/js/header.js"></script>
<script type="text/javascript" src="graphmetrics/js/nodeReport.js"></script>

<!--
<script type="text/javascript" src="graphmetrics/js/nodeReport.js"></script>
<script type="text/javascript" src="graphmetrics/js/envTable.js"></script>
<script type="text/javascript" src="graphmetrics/js/cpuChart.js"></script>
Expand Down

0 comments on commit 14a97f4

Please sign in to comment.