Skip to content
Browse files

Added node-memcached as a submodule, added memcached stats plugin, an…

…d began to work out how data will be rendered client-side.
  • Loading branch information...
1 parent 252a99f commit f23bfa5b17c10aef00186dbbfff3c521b70c624a @meltingice committed
View
3 .gitmodules
@@ -0,0 +1,3 @@
+[submodule "plugins/lib/node-memcached"]
+ path = plugins/lib/node-memcached
+ url = git@github.com:meltingice/node-memcached.git
View
16 NodeMonitor_Node.js
@@ -28,10 +28,14 @@ MonitorNode.start = function() {
MonitorNode.load_plugins = function() {
// Load plugins
var plugin_count = 0;
- var pluginarr = fs.readdirSync('./plugins');
+ var pluginarr = fs.readdirSync('./plugins/enabled');
pluginarr.forEach(function(plugin) {
plugin = plugin.split('.')[0];
- MonitorNode.plugins[plugin] = require('./plugins/'+plugin);
+ MonitorNode.plugins[plugin] = require('./plugins/enabled/'+plugin);
+ if(MonitorNode.config.plugin_options[plugin]) {
+ MonitorNode.plugins[plugin].set_options(MonitorNode.config.plugin_options[plugin]);
+ }
+
plugin_count++;
});
@@ -55,15 +59,15 @@ MonitorNode.server_connect = function() {
MonitorNode.execute_plugins = function() {
var interval = setInterval(function(){
for(var plugin in MonitorNode.plugins) {
- MonitorNode.plugins[plugin].poll(function(plugin_name, data) {
- MonitorNode.send_data(plugin_name, data);
+ MonitorNode.plugins[plugin].poll(function(plugin_name, render, data) {
+ MonitorNode.send_data(plugin_name, render, data);
});
}
}, 500);
}
-MonitorNode.send_data = function(plugin, msg) {
- var data = JSON.stringify({'plugin':plugin, 'msg':msg, 'origin':this.config.node_name});
+MonitorNode.send_data = function(plugin, render, data) {
+ var data = JSON.stringify({'plugin':plugin, 'render':render, 'data':data, 'origin':this.config.node_name});
/*
* I really hate doing this, but sometimes multiple pieces of data
View
5 README.textile
@@ -6,6 +6,11 @@ NodeMonitor is a distributed server monitoring system written in Javascript for
* <a href="http://github.com/ry/node">Node.JS</a>
<h1>How to Use</h1>
+To get the code (<b>Using --recursive is very important</b>):
+<pre>
+git clone git://github.com/meltingice/NodeMonitor.git --recursive
+</pre>
+
For a simple proof-of-concept:
* Configure config/server_config.js and config/node_config.js with the desired values. Should be pretty straightforward.
View
10 config/node_config.js
@@ -5,4 +5,12 @@ this.node_name = "Server 1";
this.server_addr = '127.0.0.1';
// The port where the server is listening
-this.server_port = 88;
+this.server_port = 88;
+
+// Optional plugin options
+this.plugin_options = {
+ 'memcached_stats' : {
+ 'addr': 'localhost',
+ 'port': 11211
+ }
+};
View
9 html/js/nodemonitor.js
@@ -29,8 +29,7 @@ var NM = window.NM || {};
});
NM.socket.on('message', function(msg) {
- var data = JSON.parse(msg);
- console.log(data);
+ NM.parse_data(msg);
});
}
@@ -55,4 +54,10 @@ var NM = window.NM || {};
}, 2000);*/
}
+ NM.parse_data = function(data) {
+ data = JSON.parse(data);
+ console.log(data);
+
+ }
+
})(window);
View
53 plugins/enabled/memcached_stats.js
@@ -0,0 +1,53 @@
+/*
+ * NodeMonitor
+ * Copyright 2010 Ryan LeFevre - @meltingice
+ *
+ * Licensed under the New BSD License, more info in LICENSE file
+ * included with this software.
+ *
+ * Source code is hosted at http://github.com/meltingice/NodeMonitor
+ * =================================================================
+ * Name: Memcached Stats Plugin
+ * Desc: Reports memcached statistics
+ */
+
+var memcached = require('./../lib/node-memcached/node-memcached');
+
+this.set_options = function(options) {
+ this.options = options;
+}
+
+this.set_defaults = function() {
+ this.options = {
+ addr: 'localhost',
+ port: 11211
+ };
+}
+
+this.poll = function(callback) {
+ if(!this.options) {
+ this.set_defaults();
+ }
+
+ var self = this;
+ memcached.connect(this.options.addr, this.options.port, function() {
+ memcached.stats(function(stats) {
+ memcached.disconnect();
+
+ var table = new Array();
+ for(var key in stats) {
+ table.push([key, stats[key]]);
+ }
+
+ callback('memcached', self.render(), table);
+ })
+ });
+}
+
+this.render = function() {
+ return {
+ type: 'table',
+ title: 'Memcached Stats',
+ cols: ['Data', 'Value']
+ };
+}
View
10 plugins/system_uptime.js → plugins/enabled/system_uptime.js
@@ -15,7 +15,15 @@ this.poll = function(callback) {
var exec = require('child_process').exec,
child;
+ var self = this;
child = exec('uptime', function(error, stdout, stderr) {
- callback("Uptime", stdout);
+ callback("uptime", self.render(), stdout);
});
+}
+
+this.render = function() {
+ return {
+ type: 'text',
+ title: 'System Uptime'
+ };
}
1 plugins/lib/node-memcached
@@ -0,0 +1 @@
+Subproject commit fcc97f57bd5e40a780c9bacfa058cb13f21f3c8c

0 comments on commit f23bfa5

Please sign in to comment.
Something went wrong with that request. Please try again.