Zabbix使用pm2-zabbix插件 监控pm2进程
插件地址
https://github.com/dickp/pm2-zabbix
安装命令
npm install -g pm2-zabbix
npm install -g zabbix-sender
pm2-zabbix --discover # 出现以下类似内容为成功。
{
"data": [
{
"{#PROCESS_ID}": "IM-0",
"{#PROCESS_NAME}": "IM"
},
{
"{#PROCESS_ID}": "app-3",
"{#PROCESS_NAME}": "app"
}
]
}
systemctl enable pm2-zabbix
systemctl start pm2-zabbix
systemctl restart zabbix-agent
cd /home
git clone https://github.com/greatcare/pm2-zabbix
vi /home/pm2-zabbix/install/init/systemd/pm2-zabbix.service
- 修改里面的
User=root
改为启动zabbix-agent使用的账号。这里使用root测试。 -
ExecStart=/usr/local/bin/pm2-zabbix --hostname
在zabbix-server登记的主机名 --monitor
cp /home/pm2-zabbix/install/init/systemd/pm2-zabbix.service /usr/lib/systemd/system/
service pm2-zabbix start
vim /home/pm2-zabbix/install/zabbix-agent/pm2-zabbix.conf #修改 pm2-zabbix用的用户名
cp /home/pm2-zabbix/install/zabbix-agent/pm2-zabbix.conf /etc/zabbix/zabbix_agentd.d/
service zabbix-agent restart
测试:
LOG_LEVEL=info pm2-zabbix --monitor --hostname 本地主机名 --server zabbix-server-ip --debug
vim /etc/zabbix/zabbix_agentd.d/pm2-zabbix.conf
UserParameter=pm2.processes,sudo -u root pm2-zabbix --hostname=[同上文的hostname] --discover
zabbix-server安装模板
下载 https://raw.githubusercontent.com/dickp/pm2-zabbix/master/install/zabbix-server/pm2-zabbix.template.xml
在监控主机上使用:
ln -s /root/.nvm/versions/node/v6.10.3/bin/pm2-zabbix /usr/local/bin/pm2-zabbix
systemctl start pm2-zabbix
visudo
zabbix ALL=(ALL:ALL) NOPASSWD: /usr/local/bin/pm2-zabbix
Defaults:zabbix !requiretty