设为首页 收藏本站
查看: 1205|回复: 0

Nagios Server通过NRPE监控client memory usage.

[复制链接]

尚未签到

发表于 2015-9-8 12:25:53 | 显示全部楼层 |阅读模式
How to monitor server memory usage with Nagios Remote Plugin Executor (NRPE)


Last updated on September 8, 2014 Authored by Sarmed Rahman 5 Comments   In a previous tutorial, we have seen how we can set up Nagios Remote Plugin Executor (NRPE) in an existing Nagios setup. However, the scripts and plugins needed to monitor memory usage do not come with stock Nagios. In this tutorial, we will see how we can configure NRPE to monitor RAM usage of a remote server.
  The script that we will use for monitoring RAM is available at Nagios Exchange, as well as the creators' Github repository.
  Assuming that NRPE has already been set up, we start the process by downloading the script in the server that we want to monitor.

Preparing Remote Servers
  On Debain/Ubuntu:


# cd /usr/lib/nagios/plugins/
# wget https://raw.githubusercontent.com/justintime/nagios-plugins/master/check_mem/check_mem.pl
# mv check_mem.pl check_mem
# chmod +x check_mem  On RHEL/CentOS:



# cd /usr/lib64/nagios/plugins/  (or /usr/lib/nagios/plugins/ for 32-bit)
# wget https://raw.githubusercontent.com/justintime/nagios-plugins/master/check_mem/check_mem.pl
# mv check_mem.pl check_mem
# chmod +x check_mem  You can check whether the script generates output properly by
manually running the following command on localhost.  When used with
NRPE, this command is supposed to check free memory, warn when free
memory is less than 20%, and generate critical alarm when free memory is
less than 10%.



# ./check_mem -f -w 20 -c 10
OK - 34.0% (2735744 kB) free.|TOTAL=8035340KB;;;; USED=5299596KB;6428272;7231806;; FREE=2735744KB;;;; CACHES=2703504KB;;;;

  If you see something like the above as an output, that means the command is working okay.
  Now that the script is ready, we define the command to check RAM usage for NRPE. As mentioned before, the command will check free memory, warn when free memory is less than 20%, and generate critical alarm when free memory is less than 10%.


# vim /etc/nagios/nrpe.cfg  For Debian/Ubuntu:

command[check_mem]=/usr/lib/nagios/plugins/check_mem  -f -w 20 -c 10

  For RHEL/CentOS 32 bit:

command[check_mem]=/usr/lib/nagios/plugins/check_mem  -f -w 20 -c 10

  For RHEL/CentOS 64 bit:

command[check_mem]=/usr/lib64/nagios/plugins/check_mem  -f -w 20 -c 10

Preparing Nagios Server
  In the Nagios server, we define a custom command for NRPE. The command can be stored in any directory within Nagios. To keep the tutorial simple, we will put the command definition in /etc/nagios directory.


  For Debian/Ubuntu:


# vim /etc/nagios3/conf.d/nrpe_command.cfg
define command{
command_name check_nrpe
command_line /usr/lib/nagios/plugins/check_nrpe -H '$HOSTADDRESS$'  -c '$ARG1$'
}

  For RHEL/CentOS 32 bit:


# vim /etc/nagios/objects/nrpe_command.cfg
define command{
command_name check_nrpe
command_line /usr/lib/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

  For RHEL/CentOS 64 bit:


# vim /etc/nagios/objects/nrpe_command.cfg
define command{
command_name check_nrpe
command_line /usr/lib64/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

  Now we define the service check in Nagios.
  On Debian/Ubuntu:


# vim /etc/nagios3/conf.d/nrpe_service_check.cfg
define service{
use                            local-service
host_name                      remote-server
service_description            Check RAM
check_command                  check_nrpe!check_mem
}

  On RHEL/CentOS:


# vim /etc/nagios/objects/nrpe_service_check.cfg
define service{
use                            local-service
host_name                      remote-server
service_description            Check RAM
check_command                  check_nrpe!check_mem
}

  Finally, we restart the Nagios service.
  On Debian/Ubuntu:


# service nagios3 restart  On RHEL/CentOS 6:


# service nagios restart  On RHEL/CentOS 7:


# systemctl restart nagios.service
Troubleshooting
  Nagios should start checking RAM usage of a remote-server using NRPE. If you are having any problem, you could check the following.


  • Make sure that NRPE port is allowed all the way to the remote host. Default NRPE port is TCP 5666.
  • You could try manually checking NRPE operation by executing the check_nrpe command: /usr/lib/nagios/plugins/check_nrpe -H remote-server
  • You could also try to run the check_mem command manually: /usr/lib/nagios/plugins/check_nrpe -H remote-server –c check_mem
  • In the remote server, set debug=1 in /etc/nagios/nrpe.cfg. Restart the NRPE service and check the log file /var/log/messages (RHEL/CentOS) or /var/log/syslog (Debain/Ubuntu). The log files should contain relevant information if there is any configuration or permission errors. If there are not hits in the log, it is very likely that the requests are not reaching the remote server due to port filtering at some point.
  To sum up, this tutorial demonstrated how we can easily tune NRPE to monitor RAM usage of remote servers. The process is as simple as downloading the script, defining the commands, and restarting the services. Hope this helps.
  
  原文链接:http://xmodulo.com/monitor-server-memory-usage-nagios-remote-plugin-executor.html

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-111043-1-1.html 上篇帖子: php开发nagios插件的方法 下篇帖子: ndoutils_mq项目: 发送Nagios的性能、报警、配置文件到RabbitMQ
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表