-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Geoff Flarity
committed
Feb 5, 2012
1 parent
b85473c
commit 41a4bc3
Showing
15 changed files
with
1,131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var GraphiteAxon = require('./graphite_axon').GraphiteAxon; | ||
var STDOUTAxon = require('./stdout_axon').STDOUTAxon; | ||
|
||
module.exports = function( system_type, config ) { | ||
|
||
switch(system_type) { | ||
|
||
case 'graphite' : | ||
return function( subspace ) { | ||
var namespace = config.graphite_namespace + '.' + subspace; | ||
return new GraphiteAxon( namespace, config.graphite_host, config.graphite_port ); | ||
} | ||
|
||
case 'stdout' : | ||
return function( subspace ) { | ||
var namespace = subspace | ||
return new STDOUTAxon( namespace ); | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
var net = require('net'); | ||
|
||
var GraphiteAxon = function ( namespace, host, port) { | ||
|
||
var this_axon = this; | ||
|
||
this_axon.namespace = namespace; | ||
this_axon.host = host; | ||
this_axon.port = port; | ||
|
||
this_axon.tcp_connection = net.createConnection( port, host ); | ||
|
||
//TODO eventually this could get big if we can't send them out for a while | ||
this_axon.message_buffer = []; | ||
|
||
//not this is async, so everything below will get set first | ||
this_axon.tcp_connection.connect( port, host ); | ||
|
||
//on connect we need to check if we have any messages in the | ||
//the message buffer, send them if so but first send a new | ||
//connect message | ||
var on_connect = function() { | ||
|
||
var connected_message_metric_path = axon.namespace + '.nervous.connected'; | ||
var connected_mesage_value = '1'; | ||
var connected_message_timestamp = Math.floor( new Date / 1000.0 ); | ||
this_axon.tcp_connection.write( connected_message_metric_path | ||
+ ' ' + connected_message_value | ||
+ ' ' + connected_message_timestamp + '\n' ); | ||
|
||
|
||
//TODO eventually this could get big if we can't send them out for a while | ||
while( this.message_buffer.length > 0) { | ||
|
||
var message = this_axon.message_buffer.shift(); | ||
this_axon.write( message ); | ||
} | ||
|
||
}; | ||
this_axon.tcp_connection.on( 'connect', on_connect ); | ||
|
||
var on_error = function( exception ){ | ||
|
||
//TODO create an error message and enque it | ||
//log error | ||
|
||
}; | ||
this_axon.tcp_connection.on( 'error', on_error ); | ||
|
||
var on_end = function( ) { | ||
|
||
//TODO create an end message | ||
//log that we ended | ||
|
||
//reconnect | ||
this_axon.tcp_connection.connect( this_axon.port, this_axon.port ); | ||
|
||
}; | ||
this_axon.tcp_connection.on( 'end', on_end ); | ||
|
||
}; | ||
module.exports.GraphiteAxon = GraphiteAxon; | ||
|
||
GraphiteAxon.prototype.fire = function( name, value, timestamp ) { | ||
|
||
this_axon = this; | ||
|
||
//by default we generate the timestamp on fire, but it can be | ||
//overridden | ||
timestamp = timestamp || Math.floor(new Date()/1000); | ||
|
||
var metric_path = this_axon.namespace + '.' + name; | ||
var metric_value = value; | ||
var metric_timestamp = timestamp; | ||
var line = metric_path + ' ' + metric_value + ' ' + metric_timestamp + '\n'; | ||
|
||
try { | ||
this_axon.tcp_connection.write( line ); | ||
} catch ( e ) { | ||
|
||
console.log( line ); | ||
|
||
//TODO need to resend these | ||
this.message_buffer.push ( line ); | ||
} | ||
|
||
|
||
|
||
}; | ||
|
||
GraphiteAxon.prototype.misfire = function( error ) { | ||
|
||
this_axon = this; | ||
|
||
console.log( error ); | ||
|
||
var name = 'nervous.misfire'; | ||
this_axon.fire( name, 1 ); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var net = require('net'); | ||
|
||
var STDOUTAxon = function ( namespace) { | ||
|
||
var this_axon = this; | ||
|
||
this_axon.namespace = namespace; | ||
|
||
}; | ||
module.exports.STDOUTAxon = STDOUTAxon; | ||
|
||
STDOUTAxon.prototype.fire = function( name, value, timestamp ) { | ||
|
||
this_axon = this; | ||
|
||
|
||
//by default we generate the timestamp on fire, but it can be | ||
//overridden | ||
timestamp = timestamp || Math.floor(new Date()/1000); | ||
var metric_path = this_axon.namespace + '.' + name; | ||
var metric_value = value; | ||
var metric_timestamp = timestamp; | ||
var line = metric_path + ' ' + metric_value + ' ' + metric_timestamp; | ||
|
||
console.log( line ); | ||
|
||
}; | ||
|
||
|
||
STDOUTAxon.prototype.misfire = function( err ) { | ||
|
||
this_axon = this; | ||
console.log(err); | ||
|
||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//config | ||
var plugin_dir = './plugins'; | ||
|
||
var system_type = 'graphite'; | ||
var config = { | ||
graphite_host : 'stats01-smc03', | ||
graphite_port : '2003', | ||
graphite_namespace : 'nervous.www02-smc03' | ||
}; | ||
|
||
//deps | ||
var fs = require('fs'); | ||
var axon_factory = require('axon_factory')( system_type, config ); | ||
|
||
//code | ||
|
||
var load_plugins = function () { | ||
fs.readdir( plugin_dir, function( err, entries ) { | ||
var dirs = []; | ||
entries.forEach( function( entry ) { | ||
|
||
var plugin_path = plugin_dir + '/' + entry; | ||
fs.stat( plugin_path, function( err, stats ) { | ||
if ( stats.isDirectory() ) { | ||
require( plugin_path )( AxonFactory( entry ) ); | ||
} | ||
} ); | ||
} ); | ||
|
||
|
||
} | ||
|
||
); | ||
}; | ||
|
||
|
||
load_plugins(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// configuration | ||
var interval = 10*1000; | ||
var filesystem = "/"; | ||
|
||
//deps | ||
var child_process = require('child_process'); | ||
|
||
//code | ||
var on_exec_complete = function( err, stdout, stderr ) { | ||
|
||
var lines = stdout.split('\n'); | ||
var payload = lines[1]; | ||
|
||
var matches = payload.match(/(\d+)\%/ ); | ||
|
||
console.log(matches[1]); | ||
|
||
|
||
|
||
}; | ||
|
||
|
||
//this checks it | ||
var check_filesystem_usage = function() { | ||
child_process.exec( 'df ' + filesystem, on_exec_complete ); | ||
}; | ||
|
||
|
||
//our plugin main function | ||
module.exports = function( config ) { | ||
|
||
setInterval( check_filesystem_usage, interval ); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
//config | ||
var host = 'localhost'; | ||
var port = 11211; | ||
var interval = 1000; | ||
|
||
var stats_to_gather = | ||
[ | ||
'get_misses', //number of get misses | ||
'curr_connections', //current connections | ||
'evictions', //number of evictions | ||
'rusage_user', //seconds the cpu has devoted to the process as the user | ||
'rusage_system', //econds the cpu has devoted to the process as the system | ||
'decr_misses', //decr misses | ||
'accepting_conns', //accepting connections true/false, | ||
'pid', //the pid | ||
'cmd_set', //the number of times cmd set called | ||
'cmd_flush', //the number of times flush called | ||
'delete_misses', //delete misses '0', | ||
'cas_hits', //compare and swap hits | ||
'incr_misses', //increment misses, | ||
'cas_badval', //cass bad values | ||
//'conn_yields', //the number of connection yields | ||
'get_hits', //number of get hits | ||
'incr_hits', //number of incr hits | ||
'delete_hits', //number of delete hits | ||
'bytes_read', //bites read count | ||
'bytes_written', //butes written count | ||
'cas_misses', //cas misses | ||
'total_connections', //cas misses | ||
'bytes', //total number of bytes currently in use by curr_items | ||
'total_items', //total number of items | ||
'threads', //number of threads in use | ||
'decr_hits', //number of decr hits | ||
'cmd_get', //total GET commands issued to the server | ||
'curr_items', //total number of items currently in memcache | ||
//'time', //current time | ||
//'version', //the version of memcache | ||
//'uptime', //the update for the process | ||
]; | ||
|
||
//deps | ||
var memcache = require('memcache'); | ||
var utils = require('util'); | ||
|
||
//code | ||
module.exports = function( axon ) { | ||
|
||
//this gets called every interval milliseconds | ||
var check_stats = function() { | ||
|
||
var client = new memcache.Client(port, host); | ||
client.connect(); | ||
var on_connect = function () { | ||
client.stats( function( err, result ){ | ||
|
||
if( err ) { axon.misfire( err ) }; | ||
|
||
|
||
//console.log( utils.inspect( result, true, null, true ) ); | ||
for ( var i = 0; i < stats_to_gather.length; i++ ) { | ||
|
||
var name = stats_to_gather[i]; | ||
var value = result[name]; | ||
var timestamp = result.time; | ||
|
||
axon.fire( name, value, timestamp ); | ||
|
||
} | ||
|
||
//reset and then close the client | ||
debugger; | ||
client.stats( 'reset', function( err ) { | ||
console.log(err); | ||
client.close(); | ||
} ); | ||
}); | ||
|
||
}; | ||
client.on( 'connect', on_connect ); | ||
|
||
var on_error = function( err ) { | ||
|
||
axon.misfire( e ); | ||
}; | ||
client.on( 'error', on_error ); | ||
|
||
|
||
}; | ||
|
||
//periodically send back stats | ||
setInterval( check_stats, interval ); | ||
|
||
}; | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.