How to monitor Node.js / io.js Apps with SPM

58 views
Skip to first unread message

Stefan Thies

unread,
Apr 28, 2015, 6:14:13 PM4/28/15
to nod...@googlegroups.com

Hi, 

We are starting to use Node.js here at Sematext and since eating one’s own dogfood is healthy, we wanted to be able to monitor our Node.js apps with SPM (we are in performance monitoring and big data biz). So the first thing we do in such a case is adding monitoring capability for technology we use in-house (like we did for Java, Solr, Elasticsearch, Kafka, HBase, NGINX). 

You may have seen our post about SPM for Node.js - but I thought I’d share a bit about how we monitor Node.js to help others facing the same devops needs when introducing new Node.js apps or the challenge to operate large deployments with a mix of technologies in the application stack:

1) npm i spm-agent-nodejs (it’s open source on Github: sematext/spm-agent-nodejs)

2) add a new SPM App for Node.js - each monitored App is identified by its App-Token (and Yes - there is an API to automate this step)

3) set the Environment variable for the application token SPM_TOKEN=YOUR_TOKEN

4) add one line to the beginning of your source code (when using node.js - io.js got a better option/see below)
   var spmAgent = require (‘spm-agent-nodejs’)
5) Run you app and after 60 seconds you should see first metrics in SPM

At this point what do I get?  I can see pre-defined metric charts like these, with about 5 minutes of work :)

https://sematext.files.wordpress.com/2015/03/nodejs-overview-2.png

https://sematext.files.wordpress.com/2015/03/nodejs-elasticsearch-dashboard.png

I saved already time - no need to define metric queries/widgets/dashboards. Now i could set up alerts on Latency or Garbage Collection, or I could have anomaly detection tell me when the number of Workers in a dynamic queue changes drastically.  I typically set ‘Algolerts’ (basically machine learning based anomaly detection) to get notified (e.g. via PagerDuty) when a service suddenly slows down - it produces less noise than regular threshold alerts. In addition I recommend to add Heartbeat alerts for each monitored service to be notified on any server outage or network problem.  In our case, where a node.js app runs tasks on Elasticsearch it makes sense to create custom dashboard to see Elasticsearch and Node.js metrics together (see 2nd screenshot above) - of course this applicable for other applications in the stack like Nginx, Redis or HaProxy.


Oh, and step 4) could be done even better with the latest io.js -- one could use io.js preload command-line option without adding the require statement for 'spm-agent-nodejs' to the source code:  

iojs -r "./spm-agent-nodejs" yourApp.js

If you want to try io.js, here is how to install it:
npm i n -g
n io 1.8

The ‘node’ executable is now linked to ‘iojs’ - to switch back to node 0.12 simply use
n 0.12

I hope this helps and if you’d like to see some Node.js/io.js metrics that are currently not being captured by SPM -  please let me know or simply open an issue here: https://github.com/sematext/spm-agent-nodejs/issues

---

Stefan Thies, DevOps Evangelist @sematext Performance Monitoring * Log Analytics * Search Analytics Solr & Elasticsearch Support * http://sematext.com/

Reply all
Reply to author
Forward
0 new messages