5,创建 zabbix-agent 的配置文件
vi /usr/local/zabbix/etc/zabbix_agentd.conf.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
# Note that it is advised you test whether sudo works from the zabbix user first, including *without a TTY*.
# If you get a "Value should be a JSON object" error during key discovery, please check your sudoers -
# refer to the example sudoers file for an option that disables the tty requirement.
6,创建sudo用户 zabbix
vi /etc/sudoers.d/pm2-zabbix-sudoers
# Allow the Zabbix user to run pm2-zabbix as any user, without a password.
zabbix ALL=(ALL:ALL) NOPASSWD: /usr/bin/pm2-zabbix
# On some systems (notably RHEL and CentOS), sudo is configured to require a tty
# by default, which prevents it from working at all with the Zabbix agent.
# This lifts that default restriction.
Defaults:zabbix !requiretty
7,在zabbix-get服务端测试是否能获取数据
/usr/local/zabbix/bin/zabbix_get -s 172.16.23.31 -p 10050 -k 'pm2.processes'
如果有信息,没有报错即可
8,服务端添加模板