Skip to content

Instantly share code, notes, and snippets.

@grahamb
Created May 27, 2013 17:52
Show Gist options
  • Select an option

  • Save grahamb/5658290 to your computer and use it in GitHub Desktop.

Select an option

Save grahamb/5658290 to your computer and use it in GitHub Desktop.
Offline collector to stand in for graphite during outages.
var net = require('net');
var fs = require('fs');
var file = '/tmp/offlinecache';
var port = 2003;
net.createServer(function(socket) {
socket.name = socket.remoteAddress + ":" + socket.remotePort;
console.log ("Connection: %s", socket.name);
socket.on('data', function(data) {
console.log(data.toString());
fs.appendFile(file, data, function(err) {
if (err) {
console.log(err);
}
});
});
socket.on('end', function() {
console.log("End connection: %s", socket.name);
});
}).listen(port);
console.log("Server listening on port " + port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment