Export PM2 Cluster Stats to Prometheus
Asked Answered
B

2

9

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.

Bidding answered 30/6, 2018 at 21:53 Comment(3)
I am trying to do the same, could you figure it out.. ?Carlitacarlo
@DagaArihant: Unfortunately the Head of engineering of Keymetrics(pm2) replied in github.com/Unitech/pm2/issues/2035 saying that its strictly not possible.Bidding
any updates on this ?Few
F
3

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.

Frilling answered 10/3, 2019 at 6:30 Comment(1)
In your solution, you are using pm2 api right, isnt the agpl v3 license not applicable ?Dodder
I
1

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

Interjection answered 23/6, 2019 at 15:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.