A
A
Al2016-07-25 18:59:33
Node.js
Al, 2016-07-25 18:59:33

Is it possible to get information about all the workers in the master?

When an application starts in a cluster, you want to monitor the resources it consumes. Let's say there is a cronjob that works in the master, and it should get information about all existing workers, for example, about the memory consumed by each, and send it to the client. There are no problems when we have one process, but in a cluster, it is not clear how to get information about workers.
I want to get the number of workers with data about them, any ideas how to implement this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Timur Shemsedinov, 2016-07-25
@Sanu0074

1. Timed tasks cannot be run in the master, if they fail, then everything will fail, it is better to run tasks in workers
2. I strongly do not recommend using the cluster library, this is one of the worst pieces of node code, use child_process instead of cluster
3. From the worker, which does tasks on time, information can be sent to the master, and other workers can pick it up, there is an IPC for this:
3.1. To send messages from master to workers: https://nodejs.org/api/child_process.html#child_pr...
3.2. To send workers to the master: https://nodejs.org/api/process.html#process_proces...
4. Instead of IPC, I recommend using TCP sockets, but if the task does not require heavy loads, then IPC will do, it is easier

D
Dmitry Belyaev, 2016-07-25
@bingo347

pm2.keymetrics.io/docs/usage/pm2-api

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question