Skip to content

Commit 6cbb7a5

Browse files
committed
PR fixes
1 parent 2fccaf7 commit 6cbb7a5

File tree

5 files changed

+37
-18
lines changed

5 files changed

+37
-18
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@ Usage: nodejs-dashboard [options] -- [node] [script] [arguments]
9292
```
9393
Options:
9494
95-
-h, --help output usage information
96-
-V, --version output the version number
97-
-p, --port [port] Socket listener port
98-
-e, --eventdelay [ms] Minimum threshold for event loop reporting, default 10ms
95+
-h, --help output usage information
96+
-V, --version output the version number
97+
-p, --port [port] Socket listener port
98+
-e, --eventdelay [ms] Minimum threshold for event loop reporting, default 10ms
99+
-s, --scrollback [count] Maximum scroll history for log windows
99100
```
100101

101102
#####`--port`
@@ -104,4 +105,7 @@ Under the hood the dashboard utilizes SocketIO with a default port of `9838`. If
104105
#####`--eventdelay`
105106
This tunes the minimum threshold for reporting event loop delays. The default value is `10ms`. Any delay below this value will be reported at `0`.
106107

108+
#####`--scrollback`
109+
Specifies the maximum number of lines that log windows (e.g. stdout, stderr) will buffer in order to scroll backwards and see the history. The default is 1000 lines.
110+
107111
To gracefully exit and terminate the spawned process use one of: `Ctrl + C`, `Q`, or `ESC`.

bin/nodejs-dashboard.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var program = new commander.Command(pkg.name);
1717
program.version(pkg.version);
1818
program.option("-p, --port [port]", "Socket listener port");
1919
program.option("-e, --eventdelay [ms]", "Minimum threshold for event loop reporting, default 10ms");
20+
program.option("-s, --scrollback [count]", "Maximum scroll history for log windows");
2021
program.usage("[options] -- [node] [script] [arguments]");
2122
program.parse(process.argv);
2223

lib/dashboard-agent.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
"use strict";
22

3-
var SocketIO = require("socket.io-client");
3+
var socketWriterFactory = require("./socket-writer");
44
var blocked = require("blocked");
55
var pusage = require("pidusage");
66
var os = require("os");
77
var _ = require("lodash");
88
var config = require("./config");
9-
var socketWriterFactory = require("./socket-writer");
109

1110
var dashboardAgent = function () {
1211

@@ -21,7 +20,7 @@ var dashboardAgent = function () {
2120
var metrics = {
2221
eventLoop: {
2322
delay: 0,
24-
high: 0,
23+
high: 0
2524
},
2625
mem: {
2726
systemTotal: os.totalmem()
@@ -77,7 +76,7 @@ var dashboardAgent = function () {
7776
};
7877

7978
var destroy = function () {
80-
socket.close();
79+
socketWriter.close();
8180
clearInterval(options.intervalId);
8281
};
8382

lib/socket-writer.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,38 @@ var SocketIO = require("socket.io-client");
88
// Potentially related to: https://github.com/socketio/socket.io-client/issues/845
99
module.exports = function create(options) {
1010

11-
var connected;
11+
var connected = false;
1212

1313
var socket = new SocketIO("http://localhost:" + options.port);
1414

15-
socket.on('connect', function() {
15+
socket.on("connect", function socketOnConnect() {
1616
connected = true;
1717
});
1818

19-
socket.on('reconnect', function() {
19+
socket.on("reconnect", function socketOnReconnect() {
2020
connected = true;
2121
});
2222

23-
socket.on('disconnect', function() {
23+
socket.on("disconnect", function socketOnDisconnect() {
2424
connected = false;
2525
});
2626

27-
return {
28-
write: function(name, data) {
29-
if(connected) {
30-
return socket.emit(name, data);
31-
}
27+
var write = function write(name, data) {
28+
if (connected && socket) {
29+
socket.emit(name, data);
30+
}
31+
};
32+
33+
var close = function close() {
34+
if (socket) {
35+
socket.close();
36+
socket = null;
37+
connected = false;
3238
}
3339
};
40+
41+
return {
42+
write: write,
43+
close: close
44+
};
3445
};

lib/views/stream-view.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ StreamView.prototype.onEvent = function (data) {
4545
// the original method calls shiftLine with two parameters (start, end)
4646
// when it should call it with just one (num lines to shift out)
4747
// blessed v0.1.81 - https://github.com/chjj/blessed/issues/255
48+
// disable eslint for the next section since it is a copy/fix from the original
49+
// blessed log.js codebase
50+
/* eslint-disable */
4851
blessed.log.prototype.log =
4952
blessed.log.prototype.add = function() {
5053
var args = Array.prototype.slice.call(arguments);
@@ -55,9 +58,10 @@ blessed.log.prototype.add = function() {
5558
this.emit('log', text);
5659
var ret = this.pushLine(text);
5760
if (this._clines.fake.length > this.scrollback) {
58-
this.shiftLine((this.scrollback / 3) | 0);
61+
this.shiftLine((this.scrollback / 3) | 0); // fixed line
5962
}
6063
return ret;
6164
};
65+
/* eslint-enable */
6266

6367
module.exports = StreamView;

0 commit comments

Comments
 (0)