greatcare / pm2-zabbix

A Node.js PM2 monitoring tool for Zabbix.
MIT License
87 stars 60 forks source link

Question: Multiple pm2 instances under different users. #21

Open md2k opened 6 years ago

md2k commented 6 years ago

Hi, it is possible to monitor two or more PM2 instances under different users? While discovery it is not a problem to deal with, how about pm2.[cpu,memory,status,processes] commands?

rkaw92 commented 6 years ago

Hi, that's an interesting question. It should be possible to send data for 2 lists of processes (provided that they do not have conflicting <name>-<ID> pairs), but at the same time, gathering stats about the PM2 daemon itself only produces a constant set of keys per host. Naturally, Zabbix would overwrite the PM2 data items in a last-write-wins fashion - not what anyone wants.

Therefore, it seems that currently the only solution is alternating hostnames for those different users - faking multiple hosts. Whether this is going to be implemented in another way in the nearest future - I do not think so, because it would require changing the "shape" of all keys to also include the username in the item key, and that is a breaking change.

If we receive a pull request that does enable an optional, alternate mode of data-sending, with the keys including a [username] index, then I would be inclined to add it to this tool.

md2k commented 6 years ago

I not interesting in monitoring pm2 process itself, because if all services became down it is obviously means that this is a problem :) cpu/memory consumption as for me it is ok to have basic CPU/RAM monitoring if i'll see that CPU/Memory consumption jumps, it will mean that instance require some manual attention any way. So, in my opinion, most important it is possibility to monitor services managed by PM2 rather than PM2 itself. but for future it will be nice to have possibility to have multiple PM2 Daemon monitoring capabilities. One of the ways , make configuration options for pm2-zabbix to register itself separate pm2._ commands (keys) which can be later used in templates. i think this will be is most logical approach (it will keep backward compatibility because without config options all will work as now. and with options commands will have index int or word).

Also to have two pm2-zabbix just for services reporting hard to achieve, discovery rule can trigger only one of them. of course it is possible create 2 discovery rules, but then Zabbix complain that same key already used with another discovery rule (in same template, didn't tried to create 2 different templates).

md2k commented 6 years ago

it wont work straight forward. Need to create custom discovery which is collect from all users its processes and pm-zabbix daemon will send later to Zabbix-server their stats. or need allow pm2-zabbix to register itself keys with some custom index to allow separation of each pm2-zabbix service per user.

Or create virtual Host as you mentioned before, what is not best approach, but currently only one which allow monitor multiple PM2 running under different users.

rkaw92 commented 6 years ago

I agree that it does not seem to be possible without resorting to fake hosts, or writing custom "data gathering" scripts that take data from multiple users.

To avoid introducing half-measures, I would refrain from implementing such system-wide discovery / monitor wrappers, and instead opt to add the option to use per-user PM2 daemon and process keys (which would, in turn, require using separate Zabbix templates and agent discovery entries for LLD to be useful, of course).

I must say that we are a bit busy at the moment, and the resources devoted to development of new pm2-zabbix features are rather minimal, so do not expect this feature to appear for the next few weeks. If you would rather implement this yourself, go ahead - pull requests are always welcome!

md2k commented 6 years ago

@rkaw92, here no haste, it more like feature request, because faced this problem. pull request for me not a option, nodejs not my field, i'm more about golang, so will prefer to wait if this functionality will be some where later. and thanks for such software.

Warfunck commented 6 years ago

Hi, "Need to create custom discovery which is collect from all users its processes and pm-zabbix daemon will send later to Zabbix-server their stats". Can we expect the addition of this feature in the near future?

rkaw92 commented 6 years ago

@Warfunck Your best bet right now is adding this and issuing a PR.