我想使用Nagios通过PASSENGER-STATUS监控我们的rails应用程序,但我找不到适合当前版本乘客的插件。
我想看队列中的"请求"因为我在顶级队列中总是有0个请求,即使我在所有应用程序中都有数百个请求队列。
.---------- General information -----------
Max pool size : 6
Processes : 1
Requests in top-level queue : 0
.---------- Application groups -----------
/webapps/example.local#default:
App root: /webapps/example.local
Requests in queue: 0
* PID: 16915 Sessions: 0 Processed: 1 Uptime: 2s
CPU: 0% Memory : 9M Last used: 2s ago
我正在使用ff版本:
Passenger (4.0.2)
Nagios 3.5.1
我创建了一个bash脚本,用于grep队列中的Requests。
#!/bin/bash
queue=`passenger-status | grep -A 1 "myapp1" | grep "Requests in queue:" | awk '{print $4}'`
if [ $queue == 0 ]
then
echo "OK - $queue Passenger Queue on myapp1"
exit 0
elif [ $queue -le 10 ]
then
echo "Warning - $queue Passenger Queue on myapp1"
exit 1
elif [ $queue > 10 ]
then
echo "Critical - $queue Passenger Queue on myapp1"
exit 2
else
echo "Unknown Error - Please check config."
exit 3
fi
手动运行脚本时。我得到了正确的结果。
[root@localhost user]# /usr/lib64/nagios/plugins/check_passenger_queue.sh
OK - 0 Passenger Queue on myapp1
但是当我使用NRPE插件运行脚本时。它给了我不同的结果。
[root@localhost user]# /usr/lib64/nagios/plugins/check_nrpe -H localhost -c check_passenger_queue
Unknown Error - Please check config.
我尝试在Nagios Server上运行NRPE插件,但结果相同。
[root@nagios user]# /usr/local/nagios/libexec/check_nrpe -H xxx.xxx.xxx.xxx -c check_passenger_queue
Unknown Error - Please check config.
答案 0 :(得分:1)
我的解决方案是
#!/bin/bash
export PATH="/usr/local/rvm/gems/ruby-1.9.3-p392/bin:/usr/local/rvm/gems/ruby-1.9.3-p392@global/bin:/usr/local/rvm/gems/ruby-1.9.3-p392@myapp1/bin:/usr/local/rvm/rubies/ruby-1.9.3-p392/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
rvmsudo /usr/local/rvm/gems/ruby-1.9.3-p392/bin/passenger-status > /usr/lib64/nagios/plugins/passenger/passenger-status.txt
#!/bin/bash
export PATH="/usr/local/rvm/gems/ruby-1.9.3-p392/bin:/usr/local/rvm/gems/ruby-1.9.3-p392@global/bin:/usr/local/rvm/gems/ruby-1.9.3-p392@myapp1/bin:/usr/local/rvm/rubies/ruby-1.9.3-p392/bin:/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
rvmsudo /usr/local/rvm/gems/ruby-1.9.3-p392/bin/passenger-status > /usr/lib64/nagios/plugins/passenger/passenger-status.txt
#!/bin/bash
queue=`cat /usr/lib64/nagios/plugins/passenger/passenger-status.txt | grep -A 1 "myapp1" | grep "Requests in queue:" | awk '{print $4}'`
if [ $queue -eq 0 ]; then
echo "OK - $queue Passenger Queue on myapp1"
exit 0
elif [ $queue -le 10 ]; then
echo "Warning - $queue Passenger Queue on myapp1"
exit 1
elif [ $queue -ge 11 ]; then
echo "Critical - $queue Passenger Queue on myapp1"
exit 2
else
echo "Unknown Error - $queue Please check config."
exit 3
fi
#!/bin/bash
queue=`cat /usr/lib64/nagios/plugins/passenger/passenger-status.txt | grep -A 1 "myapp1" | grep "Requests in queue:" | awk '{print $4}'`
if [ $queue -eq 0 ]; then
echo "OK - $queue Passenger Queue on myapp1"
exit 0
elif [ $queue -le 10 ]; then
echo "Warning - $queue Passenger Queue on myapp1"
exit 1
elif [ $queue -ge 11 ]; then
echo "Critical - $queue Passenger Queue on myapp1"
exit 2
else
echo "Unknown Error - $queue Please check config."
exit 3
fi
答案 1 :(得分:0)
passenger-status
运行 rvmsudo
,如Eman所示。使用用户 nagios 调用NRPE,当您在没有passenger-status
的情况下调用rvmsudo
时,您最有可能获得未知错误。
另一方面,当您使用rvmsudo passenger-status
通过NRPE使用用户 nagios 调用插件时,如果脚本点击rvmsudo
,则会请求密码。由于在通过NRPE调用插件时无法输入密码,因此无法帮助收集。
因此,nrpe.cfg中记录的一个解决方案是
command_prefix=/usr/bin/sudo
nagios ALL=(ALL) NOPASSWD:/usr/lib/nagios/plugins/,/path/to/passenger-status
将用户 nagios 添加到/ etc / sudoers。重要提示:请确保使用sudo visudo -f /etc/sudoers
编辑/ etc / sudoers!sudo service nagios-nrpe-server restart
步骤2.假设您的插件位于/ usr / lib / nagios / plugins。
可以使用passenger-status
标识rvmsudo which passenger-status
的路径。还要确保rvmsudo
在你的路径中。