greatcare / pm2-zabbix

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

pm2-zabbix --discover error #18

Closed sqwit closed 5 years ago

sqwit commented 7 years ago

Hi All... I've tried to get pm2-zabbix to work on CentOS 6 and 7 with Zabbix 3.2 agent, but in both cases i had the bellow error after installation using npm. I also verified if the pm2-zabbix.conf was placed in /etc/zabbix/zabbix_agentd.d/, but the file was not there. Is it done automatically?

pm2-zabbix --discover

/usr/lib/node_modules/pm2-zabbix/lib/PM2ZabbixMonitor.js:61 self._logger.error({ event: 'PM2ZabbixMonitor#processUpdateSendingError', error: error, processID: changeEvent.processID, newState: changeEvent.newState }, 'Real-time status update sending failed for process %s: %s', changeEvent.processID, ); ^ SyntaxError: Unexpected token ) at createScript (vm.js:56:10) at Object.runInThisContext (vm.js:97:10) at Module._compile (module.js:542:28) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object. (/usr/lib/node_modules/pm2-zabbix/monitor.js:5:24)

rkaw92 commented 7 years ago

Hi, there was a bug in error handling which is now fixed in 0.3.2 - try the newest version. The bug could only be triggered when sending fails, though - so it looks like sending the data did not succeed, after all. The new release should show the real error correctly.

As for your other question regarding the Zabbix agent drop-in config (pm2-zabbix.conf) - it needs to be installed manually and optionally customized (e.g. by adjusting the sudo user depending on your local install).

sqwit commented 7 years ago

Thanks to fix it rkaw92, now the discovery works. I've placed the pm2-zabbix.conf and i changed debian to root and place the suduers file, restart the agent. Now how do i know if the Zabbix server is getting anything?

I tried from the server zabbix_get and i've got the following: [root@xxxxxxxxx xxx]# zabbix_get -s xxx.xxx.xxx.xxx -k pm2.status ZBX_NOTSUPPORTED: Unsupported item key.

I also tried on the client: [root@xxxxxx xxxx]# pm2-zabbix --monitor {"name":"pm2-zabbix","hostname":"xxx.xxxx.internal","pid":11645,"level":50,"event":"PM2ZabbixMonitor#processListSendingError","error":{"code":"ENOENT","errno":"ENOENT","syscall":"spawn /usr/bin/zabbix_sender","path":"/usr/bin/zabbix_sender","spawnargs":["--config","/etc/zabbix/zabbix_agentd.conf","--input-file","-"],"cmd":"/usr/bin/zabbix_sender --config /etc/zabbix/zabbix_agentd.conf --input-file -"},"msg":"Failed to send process list with stats to server: Error: spawn /usr/bin/zabbix_sender ENOENT","time":"2017-07-20T17:37:32.343Z","v":0}

I've installed the sender via npm , but there is no /usr/bin/zabbix_sender folder there.

Thanks!

rkaw92 commented 7 years ago

Hi. First of all, I've uploaded pm2-zabbix@0.3.2 to npm just now - it was still at 0.3.1 earlier today in npm, so it might have been a bit confusing; sorry about that.

Now, ENOENT while spawning zabbix_sender surely means you do not have the binary installed. As stated in the package's prerequisites (README), it is necessary to install whatever package your distro supplies zabbix_sender with. On CentOS, I think it is just called zabbix-sender, though I have no personal experience with that distribution nor a ready instance to check it on.

As for your zabbix_get invocation on the server, let me refer to the manpage:

zabbix_get is a command line utility for getting data from Zabbix agent.

ZBX_NOTSUPPORTED seems to be a generic error returned by the agent, but one of the cases where it appears is when the key is not defined on the agent. This is correct - the agent is not the party that supplies this info.

We use the Zabbix agent for item discovery - by placing the agent config file, the server can contact the agent running on a monitored host and poll it for a process list (and this is what --discover is for). However, it is pm2-zabbix (our process) that sends PM2 status and process stats for the discovered processes. The agent will thus not have any info about PM2 status, because --discovery does not supply this data.

I would say that a good way to find out if the server is getting the data is using the management GUI (web front-end) of the Zabbix server itself.

sqwit commented 7 years ago

Hi, I've trying to get this working on CentOS 6 and 7, i've zabbix_sender installed in both of them.

Now i'm getting the following errors: Try from the server to the centos 7 host

[root@hostname xxx]# zabbix_get -s xx.xx.xx.x -k pm2.processes sh: /usr/bin/sudo: Permission denied

Try from the server to the centos 6 host

[root@eac-uxr-web uxr]# zabbix_get -s 10.14.208.30 -k pm2.processes { "data": [ { "{#PROCESS_ID}": "moov-client-0", "{#PROCESS_NAME}": "moov-client" }, { "{#PROCESS_ID}": "pm2-logrotate-1", "{#PROCESS_NAME}": "pm2-logrotate" } ] }

So looks like things are better on CentOS 6, but in both of them when i try pm2-zabbix --monitor,i get the same error below

[root@xxxxxx xxxxxx]#pm2-zabbix --monitor {"name":"pm2-zabbix","hostname":"xxxxxxx.internal","pid":1699,"level":50,"event":"PM2ZabbixMonitor#processListSendingError","error":{"killed":false,"code":1,"signal":null,"cmd":"/usr/bin/zabbix_sender --config /etc/zabbix/zabbix_agentd.conf --input-file -"},"msg":"Failed to send process list with stats to server: Error: Command failed: /usr/bin/zabbix_sender --config /etc/zabbix/zabbix_agentd.conf --input-file -\n","time":"2017-07-20T22:53:46.329Z","v":0} {"name":"pm2-zabbix","hostname":"xxxxxxx.uxrlab.internal","pid":1699,"level":50,"event":"PM2ZabbixMonitor#PM2StatusSent","error":{"killed":false,"code":1,"signal":null,"cmd":"/usr/bin/zabbix_sender --config /etc/zabbix/zabbix_agentd.conf --input-file -"},"msg":"Failed to send PM2 status: Error: Command failed: /usr/bin/zabbix_sender --config /etc/zabbix/zabbix_agentd.conf --input-file -\n","time":"2017-07-20T22:53:46.338Z","v":0}

This time on both servers, zabbix_server is there /usr/bin/zabbix_sender

I'm also not getting pm2 data on the Zabbix GUI Server. Any clue what could be?

Thanks Again!

rkaw92 commented 7 years ago

On CentOS 7, it looks like your sudo is non-executable (?!). You should check if sudo works there at all.

Error code 1 in zabbix_sender means that sending failed - perhaps the connection could not be established, or if using TLS, cert auth may have failed. You should try sending some key/value manually in verbose mode using zabbix_sender and work from there. It is not a problem with pm2-zabbix at this point, but with underlying agent config file or connectivity.

sqwit commented 7 years ago

Hi, I think i got this working on CentOS 6

I did some change on zabbix_agentd.conf that was set as default and TSL was already set as unencrypted.

ServerActive=10.10.13.167 (Zabbix Server IP) Hostname=pm2hostname (Same hostname that is in the Zabbix webpage)

Now zabbix _sender seems to be working fine:

[root@ux-ears-media01 zabbix-agent]# zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -k "pm2.processes[moov-client-0,cpu]" -s ux-ears-media01 -o 90 -vv zabbix_sender [44606]: DEBUG: answer [{"response":"success","info":"processed: 1; failed: 0; total: 1; seconds spent: 0.000050"}] info from server: "processed: 1; failed: 0; total: 1; seconds spent: 0.000050" sent: 1; skipped: 0; total: 1

Now I'm going to setup it on startup or as a services as per your instructions.

If i got it, the server cant get any data by itself using zabbix_get, i tried some keys and thei did no work.

Once I get this fully working on CentOS 6 I will try to get this working CentOS 7, I suspect that the issue is with SELinux.

Thanks,

Bruno

rkaw92 commented 7 years ago

Great! From what you have posted, it seems to be working as expected. Your conclusions are correct, indeed:

If you need to inspect what data exactly is being discovered / received from pm2 and sent to the server, you can pass a LOG_LEVEL environment variable to pm2-zabbix - it is a fairly new feature and documented in the README.

dcdamien commented 5 years ago

@sqwit I'm going to close this issue. Feel free to reopen if problem still persist.