0

js gurus,

I'm creating my first node.js server/client reporting app. It gathers data via rest APIs to keep a pulse on web services I use such as CloudFlare.com, UptimeRobot.com, etc. In addition (where I need help), I'd like to connect my local reporting node.js server to my production node.js server, which will report CPU load and available memory in intervals.

Starting on the production server, here's what I have so far:

(function(){
    var status = {load: 0.9, usedMem: 0.5}; //contians this machine's memory usage and average CPU loads, just some basic values here to get things started, no assistance needed with getting those values


    ///////////////////////////////////
    //socket server
    ///////////////////////////////////
    var app = require('express')()
        , server = require('http').createServer(app)
        , io = require('socket.io').listen(server);

    server.listen(3000);

    io.sockets.on('connection', function (socket) {
        socket.emit('status', status); //NOT SO FAST! I need to authenticate before giving away this stuff!!!
    });
})();

And here's the 'client' side (although the client will be server, which collects and delivers this and other data to an actual browser client):

(function(){
    var socket = io.connect('http://localhost:3000'); //too easy, right?
    socket.on('status', function (data) {
        console.log(data);
    });
})();

It would terrify me to actually use this in a production environment. Any thoughts on how to "simply" tighten this up? For the most part, only one other machine will/should have access to the production server's node.js server. However, I'll likely need to set up access for a few people to access the reporting server eventually.

Thank you for any tips and pointers in advance. I truly appreciate it.

Christopher Stevens
  • 1,214
  • 17
  • 32
  • As I dig, it looks like [Passport](http://passportjs.org) and [passport.socketio](https://github.com/jfromaniello/passport.socketio) may be helpful. I'm still connecting the dots on how to make this work. – Christopher Stevens Mar 21 '14 at 22:12
  • [This is getting me close](https://github.com/wcamarao/session.socket.io/blob/master/example/server.js), need to absorb in a couple of hours. – Christopher Stevens Mar 21 '14 at 22:18
  • [This might also be helpful](http://stackoverflow.com/questions/8754849/socket-io-authentication-after-socket-established) as well. Sorry to keep rambling, just getting all the resources in one place for reference... – Christopher Stevens Mar 21 '14 at 22:21

0 Answers0