10. Monitoring Server Load
In this section we will present a simple way to monitor the load of a single application. We will accomplish this by adding a route which will dump the active SpawnInfo objects from our Spawner. Add the status method to your Spawner class:
Next, bind the route to the status method in Spawner.start:
Note that the status method is bound to a GET request as opposed to a POST request.
To quickly see this in action, restart your Node.js application and use the front end to create a few viewers. Create a new browser tab and navigate to http://localhost:8082/status. You will see data for each one of your running instances.
The final task is to expose this data on our front end. We first will add a method in index.html to get the json data from our application server and instantiate an instance-template for each running instance:
For the purposes of our demo, we will call updateServerStatus at an interval of 1 second using the setInterval method when the page loads:
When you reload the index.html page, you will see information about the running viewers populate the right column of the page as viewers are created and removed. If you want more granular updates you can reduce the interval time.