Created
May 27, 2013 17:52
-
-
Save grahamb/5658290 to your computer and use it in GitHub Desktop.
Offline collector to stand in for graphite during outages.
This file contains hidden or 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
| 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