1 server: nagios nagios_plugin nrpe ip:192.168.1.2 2 client nagios_plugin xinetd nrpe ip:192.168.1.3
一篇介绍nagios很好的博文 http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html
nagios插件(python + psutil)(client 被监控点)(收集system信息)
1 yum install -y gcc python-devel 2 yum install python-setuptools -y 3 easy_install psutil
1 #client side 2 #vim /usr/local/nagios/libexec/get_sys_info.py 3 4 #!/usr/bin/env python 5 __author__ = 'metasequoia' 6 7 import psutil 8 import datetime 9 import platform 10 11 def info(): 12 system_info = platform.version() 13 print "system_version:%s" % system_info 14 cpu_count = psutil.cpu_count() 15 print "logical_cpu_count:%score" % cpu_count 16 mem = psutil.virtual_memory() 17 print "memory_volume:%sM memory_used:%sM memory_free:%sM percent:%s%s" % ((mem[0]/1024/1024),(mem[3]/1024/1024),(mem[4]/1024/1024),mem[2],"%") 18 swap = psutil.swap_memory() 19 print "swap_volume:%sM swap_used:%sM swap_free:%sM percent:%s%s" % ((swap[0]/1024/1024),(swap[1]/1024/1024),(swap[2]/1024/1024),swap[3],"%") 20 print datetime.datetime.fromtimestamp(psutil.boot_time()).strftime("%Y-%m-%d %H:%M:%S") + " UP" 21 users = psutil.users() 22 for user in users: 23 print "%s %s %s (%s)" % (user[0],user[1],datetime.datetime.fromtimestamp(user[3]).strftime("%Y-%m-%d %H:%M"),user[2]) 24 #disk_partitions = psutil.disk_partitions() 25 disk_usage = psutil.disk_usage('/') 26 print "disk_volume:%sG disk_used:%sG disk_free:%sG percent:%s%s" % ((disk_usage[0]/1024/1024/1024),(disk_usage[1]/1024/1024/1024),(disk_usage[2]/1024/1024/1024),disk_usage[3],"%") 27 28 if __name__ == "__main__": 29 info()
chmod + /usr/local/nagios/libexec/get_sys_info.py
client define command
1 vim /usr/local/nagios/etc/nrpe.cfg 2 command[check_sys_info]=/usr/local/nagios/libexec/get_sys_info.py
server define command
1 vim commands.cfg 2 define command{ 3 command_name check_nrpe 4 command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1 5 }
server register service
1 vim services.cfg 2 3 define service{ 4 use local-service 5 host_name Nagios-Linux 6 service_description Check sys_info 7 check_command check_nrpe!check_sys_info 8 }
server test
1 /usr/local/nagios/libexec/check_nrpe -H 192.168.1.3 -c check_sys_info