Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export PM2 Cluster Stats to Prometheus

I am trying to add monitoring to a Node.js PM2 cluster where I am looking for aggregated stats in prometheus which I will then import in Grafana.

I have been able to configure prom-client and get metrics for a single process to prometheus and grafana but not a pm2 cluster.

I referred https://github.com/siimon/prom-client/issues/165 and https://github.com/siimon/prom-client/issues/80 and both says its not possible.

Is there any other way to do it? I also referred https://github.com/redar9/pm2-cluster-prometheus but can't get it working as well.

I referred https://github.com/Unitech/pm2/issues/2035 and I was able to use it in my script and find which is the master and which is the slave. But not sure how I go ahead from there.

Any help is appreciated.

like image 375
Vignesh T.V. Avatar asked Jun 30 '18 21:06

Vignesh T.V.


2 Answers

I've came up with this solution.

It correctly collects metrics across all instances of PM2 cluster.

Instead of cluster module there is no direct access to the master process in pm2. To return metrics for the whole cluster you can do IPC calls from the active instance to the rest of them and wait while all their locally collected metrics will be sent. Finally you have to aggregate all received metrics.

like image 62
Yekver Avatar answered Oct 18 '22 21:10

Yekver


Node cluster is incompatible with the "pull model" of Prometheus, so a solution is to make node push data to an "collector", from which Prometheus pulls data. For example, statsd should work.

The idea in sketch:

node_instance -> statsd_exporter <- Prometheus

like image 1
golopot Avatar answered Oct 18 '22 20:10

golopot