Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ Look will be started as a web server on port `5959`, you can access it by pointi

- `port` Listening port, defaulting to `5959`
- `host` Listening host, defaulting to `0.0.0.0`
- `user` string of "username:password", if present enable http basic authentication, defaulting null
- `real` string for realm in basic auth, defaulting `mydomain`

```js
require('look').start(3000, '127.0.0.1');
require('look').start(3000, '127.0.0.1', 'username:password', 'example.org');
```
7 changes: 4 additions & 3 deletions lib/look.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ agentio.createClient = function () {
return agent;
};

module.exports.start = function (port, host) {
module.exports.start = function (port, host, user, realm) {
if (cluster.isMaster) {
var observer = child_process.fork(__dirname + '/observer', [ port, host ]);
var observer = child_process.spawn('node', [__dirname + '/observer', port, host, user, realm ], {stdio: ['ipc', process.stdout, process.stderr], detached: false});

observer.on('message', function (data) {
if (data.cmd === 'init') {
Expand All @@ -23,6 +23,7 @@ module.exports.start = function (port, host) {
agent.request(data);
clusterhub.emit('request', data);
});
observer.unref();

agent.on('request', function (data) {
observer.send(data);
Expand Down Expand Up @@ -56,4 +57,4 @@ module.exports.start = function (port, host) {
});

nodetime.profile({ server: 'localhost', accountKey: 'session', silent: true, transactions: false });
};
};
27 changes: 24 additions & 3 deletions lib/observer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var connect = require('connect');
var connectRoute = require('connect-route');
var http = require('http');
var auth = require('basic-auth')
var app = connect();
var server = http.createServer(app);
var io = require('socket.io').listen(server, { log: false });
Expand All @@ -18,11 +19,31 @@ app.use(connectRoute(function(router) {
}));


app.use(connect.static(__dirname + '/web'));

var port = (typeof(process.argv[2]) !== 'undefined' && process.argv[2] !== 'undefined') ? process.argv[2] : 5959;
var host = (typeof(process.argv[3]) !== 'undefined' && process.argv[3] !== 'undefined') ? process.argv[3] : '0.0.0.0';

app.use(function(req, res, next){
var user = (typeof(process.argv[4]) !== 'undefined' && process.argv[4] !== 'undefined') ? process.argv[4] : null;
var realm = (typeof(process.argv[5]) !== 'undefined' && process.argv[5] !== 'undefined') ? process.argv[5] : 'mydomain';

if( user == null ){
next();
} else{
var credentials = auth(req)
params = user.split(":");
if (!credentials || credentials.name !== params[0] || credentials.pass !== params[1]) {
res.writeHead(401, {
'WWW-Authenticate': 'Basic realm="'+realm+'"'
})
res.end();
} else {
next();
}
}
});

app.use(connect.static(__dirname + '/web'));

console.log('Profiler listening on ' + host + ':' + port);

server.listen(port, host);
Expand All @@ -39,4 +60,4 @@ io.sockets.on('connection', function (socket) {

process.on('message', function (data) {
receiver.send(data);
});
});
4 changes: 2 additions & 2 deletions lib/receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Receiver.prototype.addSocket = function (socket) {
};

Receiver.prototype.send = function (data) {
if (data.cmd === 'init') {
if (data.cmd === 'init' && this.sockets[data.args.socket]) {
this.sockets[data.args.socket].emit('commands', [ data ]);
return;
}
Expand All @@ -41,4 +41,4 @@ Receiver.prototype.send = function (data) {
}
};

module.exports = Receiver;
module.exports = Receiver;
75 changes: 38 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
{
"name": "look",
"version": "0.1.3",
"description": "Performance profiler based on nodetime",
"keywords": [
"profiler",
"profiling",
"tracing",
"cpu",
"heap",
"performance",
"instrumentation",
"response time",
"performance",
"bottlenecks",
"monitoring",
"analytics",
"metrics"
],
"author": {
"name": "Vadim M. Baryshev",
"email": "vadimbaryshev@gmail.com"
},
"repository": {
"type": "git",
"url": "git://github.com/baryshev/look.git"
},
"main": "index",
"dependencies": {
"nodetime": "0.4.6",
"clusterhub": "0.2.1",
"connect": "2.7.4",
"connect-route": "0.1.3",
"socket.io": "0.9.14"
},
"engines": {
"node": ">= 0.8.0"
}
"name": "look",
"version": "0.1.3",
"description": "Performance profiler based on nodetime",
"keywords": [
"profiler",
"profiling",
"tracing",
"cpu",
"heap",
"performance",
"instrumentation",
"response time",
"performance",
"bottlenecks",
"monitoring",
"analytics",
"metrics"
],
"author": {
"name": "Vadim M. Baryshev",
"email": "vadimbaryshev@gmail.com"
},
"repository": {
"type": "git",
"url": "git://github.com/baryshev/look.git"
},
"main": "index",
"dependencies": {
"basic-auth": "^1.0.0",
"clusterhub": "0.2.1",
"connect": "2.7.4",
"connect-route": "0.1.3",
"nodetime": "0.4.6",
"socket.io": "0.9.14"
},
"engines": {
"node": ">= 0.8.0"
}
}