Varnish Dashboard – Real Time Updates with Socket IO

Posted by on Apr 10, 2014 in Server Monitoring, Varnish | No Comments
Varnish Dashboard – Real Time Updates with Socket IO

I decided that I would have a look at NodeJS and Socket.IO to see how they worked and what I could do with them.  They would give the ability to have real time data pushed to all clients that have the dashboard open at the time.  So if something happened then it would have the ability to display this information as soon as it happens without lots of AJAX polling from each of the clients.

I created a NodeJS instance which would collect the varnishstat output every 5 seconds and then send it to all the clients that are connected so  that the table could be updated and display real time data.  I also added an alerting mechanism so that if something happens on the server I can send out a notice of the event as it happens, this will then update the main dashboard page with the alert as can be seen below:

Varnish Real Time Alerts

Varnish Real Time Alerts

I’m not sure what type of alerts that I will put in here in the end, but probably things like:

  • High CPU usage
  • Monitoring of the backends
  • Selected errors from either Varnish or the OS

I think that I will now convert the rest of the backend data presentation and put that in using socket IO to give much more real time data to the dashboard.

Custom VCL for Socket IO

As Socket.IO keeps a connection open from the browser to the NodeJS instance it required some additional VCL to pipe it to the backend.  The following is the VCL I added:

sub vcl_recv {
  if (req.url ~ "socket.io/[0-9]") {
    set req.backend = nodejs;
    return(pipe);
  }
}

sub vcl_pipe {
  if (req.http.upgrade) {
    set bereq.http.upgrade = req.http.upgrade;
  }
}

Leave a Reply