Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit e0cbcaba89a27dabc4bd2ed1ac7f6577244e9a4d @baryshev committed Aug 29, 2012
Showing with 29,376 additions and 0 deletions.
  1. +1 −0 .npmignore
  2. +22 −0 LICENSE
  3. +27 −0 README.md
  4. +1 −0 index.js
  5. +25 −0 lib/agent.js
  6. +59 −0 lib/look.js
  7. +42 −0 lib/observer.js
  8. +44 −0 lib/receiver.js
  9. +5,688 −0 lib/web/bootstrap/css/bootstrap.css
  10. +817 −0 lib/web/bootstrap/css/bootstrap.min.css
  11. BIN lib/web/bootstrap/img/glyphicons-halflings-white.png
  12. BIN lib/web/bootstrap/img/glyphicons-halflings.png
  13. +2,038 −0 lib/web/bootstrap/js/bootstrap.js
  14. +7 −0 lib/web/bootstrap/js/bootstrap.min.js
  15. +11 −0 lib/web/css/look.css
  16. +1,201 −0 lib/web/flot/API.txt
  17. +76 −0 lib/web/flot/FAQ.txt
  18. +22 −0 lib/web/flot/LICENSE.txt
  19. +9 −0 lib/web/flot/Makefile
  20. +508 −0 lib/web/flot/NEWS.txt
  21. +137 −0 lib/web/flot/PLUGINS.txt
  22. +90 −0 lib/web/flot/README.txt
  23. +143 −0 lib/web/flot/examples/ajax.html
  24. +75 −0 lib/web/flot/examples/annotating.html
  25. BIN lib/web/flot/examples/arrow-down.gif
  26. BIN lib/web/flot/examples/arrow-left.gif
  27. BIN lib/web/flot/examples/arrow-right.gif
  28. BIN lib/web/flot/examples/arrow-up.gif
  29. +38 −0 lib/web/flot/examples/basic.html
  30. +4 −0 lib/web/flot/examples/data-eu-gdp-growth-1.json
  31. +4 −0 lib/web/flot/examples/data-eu-gdp-growth-2.json
  32. +4 −0 lib/web/flot/examples/data-eu-gdp-growth-3.json
  33. +4 −0 lib/web/flot/examples/data-eu-gdp-growth-4.json
  34. +4 −0 lib/web/flot/examples/data-eu-gdp-growth-5.json
  35. +4 −0 lib/web/flot/examples/data-eu-gdp-growth.json
  36. +4 −0 lib/web/flot/examples/data-japan-gdp-growth.json
  37. +4 −0 lib/web/flot/examples/data-usa-gdp-growth.json
  38. +75 −0 lib/web/flot/examples/graph-types.html
  39. BIN lib/web/flot/examples/hs-2004-27-a-large_web.jpg
  40. +45 −0 lib/web/flot/examples/image.html
  41. +44 −0 lib/web/flot/examples/index.html
  42. +97 −0 lib/web/flot/examples/interacting-axes.html
  43. +93 −0 lib/web/flot/examples/interacting.html
  44. +6 −0 lib/web/flot/examples/layout.css
  45. +60 −0 lib/web/flot/examples/multiple-axes.html
  46. +118 −0 lib/web/flot/examples/navigate.html
  47. +57 −0 lib/web/flot/examples/percentiles.html
  48. +756 −0 lib/web/flot/examples/pie.html
  49. +83 −0 lib/web/flot/examples/realtime.html
  50. +61 −0 lib/web/flot/examples/resize.html
  51. +114 −0 lib/web/flot/examples/selection.html
  52. +61 −0 lib/web/flot/examples/setting-options.html
  53. +77 −0 lib/web/flot/examples/stacking.html
  54. +49 −0 lib/web/flot/examples/symbols.html
  55. +54 −0 lib/web/flot/examples/thresholding.html
  56. +71 −0 lib/web/flot/examples/time.html
  57. +95 −0 lib/web/flot/examples/tracking.html
  58. +98 −0 lib/web/flot/examples/turning-series.html
  59. +90 −0 lib/web/flot/examples/visitors.html
  60. +98 −0 lib/web/flot/examples/zooming.html
  61. +1,427 −0 lib/web/flot/excanvas.js
  62. +1 −0 lib/web/flot/excanvas.min.js
  63. +179 −0 lib/web/flot/jquery.colorhelpers.js
  64. +1 −0 lib/web/flot/jquery.colorhelpers.min.js
  65. +167 −0 lib/web/flot/jquery.flot.crosshair.js
  66. +1 −0 lib/web/flot/jquery.flot.crosshair.min.js
  67. +183 −0 lib/web/flot/jquery.flot.fillbetween.js
  68. +1 −0 lib/web/flot/jquery.flot.fillbetween.min.js
  69. +238 −0 lib/web/flot/jquery.flot.image.js
  70. +1 −0 lib/web/flot/jquery.flot.image.min.js
  71. +2,599 −0 lib/web/flot/jquery.flot.js
  72. +6 −0 lib/web/flot/jquery.flot.min.js
  73. +336 −0 lib/web/flot/jquery.flot.navigate.js
  74. +1 −0 lib/web/flot/jquery.flot.navigate.min.js
  75. +750 −0 lib/web/flot/jquery.flot.pie.js
  76. +1 −0 lib/web/flot/jquery.flot.pie.min.js
  77. +60 −0 lib/web/flot/jquery.flot.resize.js
  78. +1 −0 lib/web/flot/jquery.flot.resize.min.js
  79. +344 −0 lib/web/flot/jquery.flot.selection.js
  80. +1 −0 lib/web/flot/jquery.flot.selection.min.js
  81. +184 −0 lib/web/flot/jquery.flot.stack.js
  82. +1 −0 lib/web/flot/jquery.flot.stack.min.js
  83. +70 −0 lib/web/flot/jquery.flot.symbol.js
  84. +1 −0 lib/web/flot/jquery.flot.symbol.min.js
  85. +103 −0 lib/web/flot/jquery.flot.threshold.js
  86. +1 −0 lib/web/flot/jquery.flot.threshold.min.js
  87. +8,316 −0 lib/web/flot/jquery.js
  88. +23 −0 lib/web/flot/jquery.min.js
  89. +105 −0 lib/web/index.html
  90. +38 −0 lib/web/js/backbone-min.js
  91. +3 −0 lib/web/js/html5.js
  92. +2 −0 lib/web/js/jquery-1.8.0.min.js
  93. +69 −0 lib/web/js/jquery.sortElements.js
  94. +7 −0 lib/web/js/look/look.compatibility.js
  95. +53 −0 lib/web/js/look/look.core.js
  96. +116 −0 lib/web/js/look/look.cpu.js
  97. +28 −0 lib/web/js/look/look.init.js
  98. +85 −0 lib/web/js/look/look.memory.js
  99. +127 −0 lib/web/js/look/look.metrics.js
  100. +46 −0 lib/web/js/look/look.routing.js
  101. +163 −0 lib/web/js/look/look.samples.js
  102. +21 −0 lib/web/js/look/look.socket.js
  103. +32 −0 lib/web/js/underscore-min.js
  104. +10 −0 lib/web/kendoui/js/kendo.web.min.js
  105. BIN lib/web/kendoui/styles/Default/editor.png
  106. BIN lib/web/kendoui/styles/Default/imagebrowser.png
  107. BIN lib/web/kendoui/styles/Default/loading-image.gif
  108. BIN lib/web/kendoui/styles/Default/loading.gif
  109. BIN lib/web/kendoui/styles/Default/slider-h.gif
  110. BIN lib/web/kendoui/styles/Default/slider-v.gif
  111. BIN lib/web/kendoui/styles/Default/sprite.png
  112. +10 −0 lib/web/kendoui/styles/kendo.common.min.css
  113. +10 −0 lib/web/kendoui/styles/kendo.default.min.css
  114. BIN lib/web/kendoui/styles/textures/glass.png
  115. BIN lib/web/kendoui/styles/textures/highlight.png
  116. +39 −0 package.json
@@ -0,0 +1 @@
+.git*
22 LICENSE
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2012 Vadim M. Baryshev <vadimbaryshev@gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
+# Look
+
+Look is a perfomance profiler for node.js applications based on [nodetime](https://github.com/nodetime/nodetime).
+Look don't send any data outside your server.
+
+# Installation
+
+ npm install look
+
+# Usage
+
+The following call should be placed before any other require statement in your application, e.g. at the first line of your main module
+
+```js
+require('look').start();
+```
+
+Look will be started as a web server on port `5959`, you can access it by pointing your browser to: `http://[yourhost]:5959`
+
+# Options
+
+ - `port` Listening port, defaulting to `5959`
+ - `host` Listening host, defaulting to `0.0.0.0`
+
+```js
+require('look').start(3000, '127.0.0.1');
+```
@@ -0,0 +1 @@
+module.exports = require('./lib/look');
@@ -0,0 +1,25 @@
+var events = require('events');
+var util = require('util');
+
+var Agent = function() {
+ events.EventEmitter.call(this);
+};
+
+util.inherits(Agent, events.EventEmitter);
+
+Agent.prototype.send = function (data) {
+ this.emit('request', data);
+};
+
+Agent.prototype.request = function (data) {
+ switch (data.cmd) {
+ case 'transactions-start' :
+ case 'transactions-stop' :
+ this.emit('command', data);
+ default :
+ this.emit('message', data);
+ break;
+ }
+};
+
+module.exports = Agent;
@@ -0,0 +1,59 @@
+var cluster = require('cluster');
+var child_process = require('child_process');
+var nodetime = require('nodetime');
+var agentio = require('nodetime/lib/agent.io');
+
+var clusterhub = require('clusterhub').createHub('look');
+
+var agent = new (require('./agent'));
+
+agentio.createClient = function () {
+ return agent;
+};
+
+module.exports.start = function (port, host) {
+ if (cluster.isMaster) {
+ var observer = child_process.fork(__dirname + '/observer.js', [ port, host ]);
+
+ observer.on('message', function (data) {
+ if (data.cmd === 'init') {
+ observer.send({ cmd: 'init', args: { socket: data.args.socket, transactions: nodetime.transactions } });
+ return;
+ }
+ agent.request(data);
+ clusterhub.emit('request', data);
+ });
+
+ agent.on('request', function (data) {
+ observer.send(data);
+ });
+
+ clusterhub.on('response', function (data) {
+ observer.send(data);
+ });
+
+ } else {
+ agent.on('request', function (data) {
+ clusterhub.emit('response', data);
+ });
+
+ clusterhub.on('request', function (data) {
+ agent.request(data);
+ });
+ }
+
+ agent.on('command', function (data) {
+ switch (data.cmd) {
+ case 'transactions-start' :
+ nodetime.transactions = true;
+ nodetime.resume();
+ break;
+ case 'transactions-stop' :
+ nodetime.pause();
+ nodetime.transactions = false;
+ break;
+ }
+ });
+
+ nodetime.profile({ server: 'localhost', accountKey: 'session', silent: true, transactions: false });
+};
@@ -0,0 +1,42 @@
+var connect = require('connect');
+var connectRoute = require('connect-route');
+var http = require('http');
+var app = connect();
+var server = http.createServer(app);
+var io = require('socket.io').listen(server, { log: false });
+
+var rewrite = function(req, res, next) {
+ req.url = '/';
+ next();
+};
+
+app.use(connectRoute(function(router) {
+ router.get('/metrics', rewrite);
+ router.get('/transactions', rewrite);
+ router.get('/cpu', rewrite);
+ router.get('/memory', rewrite);
+}));
+
+
+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';
+
+console.log('Profiler listening on ' + host + ':' + port);
+
+server.listen(port, host);
+
+var receiver = new (require('./receiver'));
+
+receiver.on('request', function (data) {
+ process.send(data);
+});
+
+io.sockets.on('connection', function (socket) {
+ receiver.addSocket(socket);
+});
+
+process.on('message', function (data) {
+ receiver.send(data);
+});
@@ -0,0 +1,44 @@
+var events = require('events');
+var util = require('util');
+
+var Receiver = function () {
+ events.EventEmitter.call(this);
+ this.sockets = {};
+ this.data = [];
+};
+
+util.inherits(Receiver, events.EventEmitter);
+
+Receiver.prototype.addSocket = function (socket) {
+ var that = this;
+
+ this.sockets[socket.id] = socket;
+
+ socket.emit('commands', this.data);
+
+ this.emit('request', { cmd: 'init', args: { socket: socket.id } });
+
+ socket.on('command', function (data) {
+ that.emit('request', data);
+ });
+
+ socket.on('disconnect', function () {
+ socket.removeAllListeners('disconnect');
+ socket.removeAllListeners('message');
+ delete(that.sockets[socket.id]);
+ });
+};
+
+Receiver.prototype.send = function (data) {
+ if (data.cmd === 'init') {
+ this.sockets[data.args.socket].emit('commands', [ data ]);
+ return;
+ }
+ this.data.push(data);
+ if (this.data.length > 512) this.data.shift();
+ for (var id in this.sockets) {
+ this.sockets[id].emit('commands', [ data ]);
+ }
+};
+
+module.exports = Receiver;
Oops, something went wrong.

0 comments on commit e0cbcab

Please sign in to comment.