I needed to extract certain metrics for events from the Node.js application. For example, increment the metric in case of a successful response, and so on.
I had Zabbix and Grafana at my disposal.
It turned out that there is a prom-client module for Node.js that can export metrics, but the problem is – like other modules, it does not work with pm2.
The problem is that a metric collected in one process cannot be correctly received in another process, which is responsible for providing the metric to the zabix agent through http.
We fix the omission: pm2-prom-client
The module is basically for Prometheus, but it also suits us.
Its essence boils down to transmitting the metrics on the pm2 bus to the agent process with subsequent export in plain-text or JSON.