node.js resource monitoring app

For a while now I’ve been working on a node.js based tracker. This is basically a pixel that you attach to any website and it captures information about the visitors. With this development comes the (not small, not irrelevant) task of monitoring the app and the server to be able to define tests as “successful” or “in need of more testing”.
So, I have built a small piece of code that goes within the tracker server, and it repeatedly captures system information and stores it in a Redis database. Another script returns a set of graphs that feed from the Redis information and present the relevant numbers in a visual fashion.

Enough talking!

The code

What it does:

  1. Sets a loop to be executed every 5 seconds.
  2. Reads information from system resource files.
  3. Stores it in a Redis database.
  4. Purges expired stats records.

The other limb of this code is the script which presents the information to the end-user browser. These two pieces of code can be put together into one script, but in my case I needed to capture some information of the actual process being monitored, thus monitoring code went to one script and stats into another.

The code

What’s happening here is:

  1. If the request is /live.html, return the static file.
  2. If not, return the stats from Redis db.
    I’ve done some hacking to be able to return the stats in a json readable way.

Also, I’ve been checking around and trying Marcos Brasil’s code. He’s building a node monitor that resembles mine in some ways, but is currently focusing on CPU usage relying on internal node.js objects.
I must say he did a very good job at keeping the code and implementation clean. I’m in the process of making my node.js production tidier, so I’ll follow examples like these which make install as simple as “npm install”.
That said, I think some graphs and visual organization of the info is critical for the user to understand what this means…


  • I’ve built the stats (live.html file) using the library. I highly recommend giving it a try.
  • You should check out A very impressive real-time monitoring app that is going through beta stage.
  • I’m sharing all this code (including live.html) in this repo, for you to fork.
  • I’ll soon update the code to alter the way I fetch CPU usage. I must say I prefer the internal node.js objects to the Linux’ info flat file.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s