greatcare / pm2-zabbix

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

Error sending process list #1

Closed dinkonin closed 8 years ago

dinkonin commented 8 years ago

I'm having a problem sending pm2 process information to zabbix 3.0.1

pm2-zabbix --monitor --debug
* Client running (monitor mode: on)
[ OK ] Periodic sending of PM2 status succeeded
[ ERR ] Periodic sending of process list error: { [Error: Command failed: ] killed: false, code: 2, signal: null }

PM2 Status is OK in zabbix but PM2 Processes discovery rule does not trigger stating "Value should be a JSON object"

Running on CentOS 7.2.1511 (Core)

rkaw92 commented 8 years ago

Do you mean you are getting that in agent logs? The process that you run in the CLI above is not the one responsible for discovery. Could you please paste what pm2-zabbix --discover is printing to the console?

dinkonin commented 8 years ago

No its in the console , agent logs are not saying anything out of the ordinary here's thepm2-zabbix --discover result

{
        "data": [
                {
                        "{#PROCESS_ID}": "app1-7",
                        "{#PROCESS_NAME}": "app1"
                },
                {
                        "{#PROCESS_ID}": "app2-8",
                        "{#PROCESS_NAME}": "app2"
                },
                {
                        "{#PROCESS_ID}": "app4-9",
                        "{#PROCESS_NAME}": "app4"
                }
        ]
rkaw92 commented 8 years ago

Can you confirm there is no ending } character in the output? If you run the output through json_pp, can it parse the produced string? pm2-zabbix --discover | json_pp Or, if you have no json_pp installed: pm2-zabbix --discover | python -m json.tool

If it works, then the JSON is okay (it looks good on your paste, except for the missing trailing curly bracket), and the problem is elsewhere.

Also, can you paste your UserParameters from the agent that you are using for discovery?

dinkonin commented 8 years ago

I'm sorry there is an ending } , I've just missed it while copying, pm2-zabbix --discover | python -m json.tool produces the same output as above with the ending } . Here's the contents of /etc/zabbix/zabbix_agentd.d/pm2-zabbix.conf

# Put this file in /etc/zabbix/zabbix_agentd.d/ and remember to change the sudo -u <user> to use your user name
UserParameter=pm2.processes,sudo -u root pm2-zabbix --discover

Running sudo -u root pm2-zabbix --discover works.

rkaw92 commented 8 years ago

Running sudo -u root pm2-zabbix --discover works.

From the zabbix user? If the zabbix user has no permissions for sudo, then sudo would just print an error message, which looks nothing like JSON.

Clearly, the output produced is correct, so it must be something at a different layer.

dinkonin commented 8 years ago

That fixed IT ! Running sudo -u root pm2-zabbix --discover was working fine from the console. But i raised the debug level of the zabbix to 4 agent it said

Sorry, you must have a tty to run sudo

Then commented Defaults requiretty in my sudoers file and now everything is working. Thank you so much.

rkaw92 commented 8 years ago

Glad to help! I should probably add a note on this kind of issue to the UserParameters example file.

rkaw92 commented 8 years ago

Okay. I have modified the example sudoers file to include this:

Defaults:zabbix !requiretty

Users of RHEL and CentOS should no longer encounter problems such as yours.