1. check_linux_stats插件用于监控linux系统性能(cpu, mem, load, disk usage, disk io, network usage, open files and processes). 
  2.  
  3. 需要安装Sys::Statistics::Linux(是perl插件) 
  4. nagios插件地址:http://exchange.nagios.org/directory/Plugins/Operating-Systems/Linux/check_linux_stats/details 
  5.  
  6. 下载check_linux_stats.pl插件,放置nagios的插件目录,给予执行权限。 
  7. perl插件安装: 
  8. wget -c http://search.cpan.org/CPAN/authors/id/B/BL/BLOONIX/Sys-Statistics-Linux-0.66.tar.gz 
  9. 之前测试时版本是0.60,如下 
  10. tar xzvf Sys-Statistics-Linux-0.60.tar.gz 
  11. cd Sys-Statistics-Linux-0.60 
  12. ls 
  13. more INSTALL 
  14. perl Makefile.PL 
  15. yum install perl-UNIVERSAL-require.noarch 
  16. perl Makefile.PL 
  17. make 
  18. make test 
  19. make install 
  20.  
  21. 定义nagios命令 
  22.  
  23. define command{ 
  24. command_name linux_cpu_stats 
  25. command_line $USER1$/check_linux_stats.pl -C -w 100 -s 5 
  26.  
  27. define command{ 
  28. command_name linux_load_stats 
  29. command_line $USER1$/check_linux_stats.pl -L -w 10,8,5 -c 20,18,15 
  30.  
  31. define command{ 
  32. command_name linux_mem_stats 
  33. command_line $USER1$/check_linux_stats.pl -M -w 99,50 -c 100,50 
  34.  
  35. define command{ 
  36. command_name linux_disk_stats 
  37. command_line $USER1$/check_linux_stats.pl -D -w 10 -c 5 -p / -u GB 
  38.  
  39. define command{ 
  40. command_name linux_disk_IO_stats 
  41. command_line $USER1$/check_linux_stats.pl -I -w 100,70 -c 150,100 -p sda1 
  42.  
  43. define command{ 
  44. command_name linux_network_stats 
  45. command_line $USER1$/check_linux_stats.pl -N -w 30000 -c 45000 -p eth0 
  46.  
  47. define command{ 
  48. command_name linux_openfiles_stats 
  49. command_line $USER1$/check_linux_stats.pl -F -w 10000,150000 -c 15000,250000 
  50.  
  51. define command{ 
  52. command_name linux_sockets_stats 
  53. command_line $USER1$/check_linux_stats.pl -S -w 1000 -c 2000 
  54.  
  55. define command{ 
  56. command_name linux_process_stats 
  57. command_line $USER1$/check_linux_stats.pl -P -w 2000 -c 3000 
  58.  
  59. 定义nagios主机服务 
  60.  
  61. define service{ 
  62. use local-service 
  63. host_name local 
  64. service_description linux disk stats 
  65. check_command linux_disk_stats 
  66.  
  67. define service{ 
  68. use local-service 
  69. host_name local 
  70. service_description linux Processes stats 
  71. check_command linux_process_stats 
  72. define service{ 
  73. use local-service 
  74. host_name local 
  75. service_description linux Load stats 
  76. check_command linux_load_stats 
  77. define service{ 
  78. use local-service 
  79. host_name local 
  80. service_description linux mem stats 
  81. check_command linux_mem_stats 
  82. notifications_enabled 1 
  83.  
  84. define service{ 
  85. use local-service 
  86. host_name local 
  87. service_description linux cpu stats 
  88. check_command linux_cpu_stats 
  89. notifications_enabled 1 
  90.  
  91. define service{ 
  92. use local-service 
  93. host_name local 
  94. service_description linux socket stats 
  95. check_command linux_sockets_stats 
  96. notifications_enabled 1 
  97.  
  98. define service{ 
  99. use local-service 
  100. host_name local 
  101. service_description linux disk_io stats 
  102. check_command linux_disk_IO_stats 
  103. notifications_enabled 1 
  104.  
  105. define service{ 
  106. use local-service 
  107. host_name local 
  108. service_description linux network stats 
  109. check_command linux_network_stats 
  110. notifications_enabled 1 
  111.  
  112. define service{ 
  113. use local-service 
  114. host_name local 
  115. service_description linux openfiles stats 
  116. check_command linux_openfiles_stats 
  117. notifications_enabled 1 
  118.  
  119. [root@localhost objects]# ../../libexec/check_linux_stats.pl -h 
  120. check_linux_stats v1.1 
  121. Usage: ../../libexec/check_linux_stats.pl -H [-C|-P|-M|-N|-D|-I|-L|-F|-S] [-P ] -w -c [-s] [-h] [-V] 
  122. -h, –help 
  123. print this help message 
  124. -C, –cpu 
  125. check cpu usage 
  126. -P, –proc 
  127. check the processes number 
  128. -M, –memory 
  129. check memory usage (memory used, swap used and memory cached) 
  130. -N, –network=NETWORK USAGE 
  131. check network usage in resq or bytes (default bytes) 
  132. -D, –disk=DISK USAGE 
  133. check disk usage 
  134. -I, –io=DISK IO USAGE 
  135. check disk I/O (r/w on /dev/sd*) 
  136. -L, –load=LOAD AVERAGE 
  137. check load average 
  138. -F, –file=FILE STATS 
  139. check open files (file alloc, inode alloc) 
  140. -S, –socket=SOCKET STATS 
  141. socket usage (tcp, udp, raw) 
  142. -p, –pattern 
  143. eth0,eth1…sda1,sda2…/usr,/tmp 
  144. -w, –warning 
  145. warning thresold 
  146. -c, –critical 
  147. critical thresold 
  148. -s, –sleep 
  149. default 1 sec. 
  150. -u, –unit 
  151. %, KB, MB or GB left on disk usage, default : MB 
  152. REQS OR BYTES on disk io statistics, default : REQS 
  153. -V, –version 
  154. version number 
  155.  
  156. ex : 
  157. * Cpu usage : 
  158. ./check_linux_stats.pl -C -w 90 -c 100 -s 5 
  159. CPU OK : idle 99.80% | USER1=0.00% system=0.20% iowait=0.00% idle=99.80%;90;100 
  160.  
  161. * Load average : 
  162. ./check_linux_stats.pl -L -w 10,8,5 -c 20,18,15 
  163. LOAD AVERAGE OK : 0.20,0.07,0.16 | load1=0.20;10;20;0 load5=0.07;8;18;0 load15=0.16;5;15;0 
  164.  
  165. * Memory usage : 
  166. ./check_linux_stats.pl -M -w 99,50 -c 100,50 
  167. MEMORY OK : used 94.52% |MemUsed=94.52%;99;100 SwapUsed=0.01;50;50 MemCached=39.66 
  168.  
  169. * Disk usage : 
  170. ./check_linux_stats.pl -D -w 10 -c 5 -p /,/usr,/tmp,/var 
  171. DISK WARNING used : / 3331.80MB on 3875.09MB (8.86% free) /usr 10084.27MB on 14528.41MB (25.43% free)| /=3331.80MB /usr=10084.27MB 
  172.  
  173. * Disk I/O : 
  174. ./check_linux_stats.pl -I -w 100,70 -c 150,100 -p sda1,sda2,sda4 
  175. DISK I/O OK | sda2_read=0.00;100;150 sda2_write=0.00;70;100 sda4_read=0.00;100;150 sda4_write=0.00;70;100 sda1_read=0.00;100;150 sda1_write=0.00;70;100 
  176.  
  177. * Network usage : 
  178. ./check_linux_stats.pl -N -w 30000 -c 45000 -p eth0 
  179. NET USAGE OK eth0:8021.78KB | eth0_txbyt=3461.39KB eth0_txerrs=0.00KB eth0_rxbyt=4560.40KB eth0_rxerrs=0.00KB 
  180.  
  181. * Open files : 
  182. ./check_linux_stats.pl -F -w 10000,150000 -c 15000,250000 
  183. OPEN FILES OK allocated: 1728 (inodes: 70390) | fhalloc=1728;10000;15000;411810 inalloc=70390;150000;250000;100250 dentries=50754 
  184.  
  185. * Socket usage : 
  186. ./check_linux_stats.pl -S -w 1000 -c 2000 
  187. SOCKET USAGE OK : used 257 |used=257;1000;2000 tcp=18 udp=5 raw=0 
  188.  
  189. * Number of procs : 
  190. ./check_linux_stats.pl -P -w 1000 -c 2000 
  191. PROCS OK : count 272 |count=272;1000;2000 runqueue=2 blocked=0 running=2 new=0.98 
  192.  
  193. * Process mem & cpu : 
  194. ./check_linux_stats.pl -T -w 9551820 -c 9551890 -p /var/run/jonas.pid 
  195. PROCESSES OK | java_vsize=1804918784;2000000000;3000000000 java_nswap=0 java_cnswap=0 java_cpu=0 
  196.  
  197. /usr/local/nagios/libexec/check_linux_stats.pl -C -w 90 -c 100 -s 5 
  198. /usr/local/nagios/libexec/check_linux_stats.pl -L -w 10,8,5 -c 20,18,15 
  199. /usr/local/nagios/libexec/check_linux_stats.pl -M -w 99,50 -c 100,50 
  200. /usr/local/nagios/libexec/check_linux_stats.pl -D -w 10 -c 5 -p /,/usr,/tmp,/var 
  201. /usr/local/nagios/libexec/check_linux_stats.pl -I -w 100,70 -c 150,100 -p sda1,sda2,sda4 
  202. /usr/local/nagios/libexec/check_linux_stats.pl -N -w 30000 -c 45000 -p eth0 
  203. /usr/local/nagios/libexec/check_linux_stats.pl -F -w 10000,150000 -c 15000,250000 
  204. /usr/local/nagios/libexec/check_linux_stats.pl -S -w 1000 -c 2000 
  205. /usr/local/nagios/libexec/check_linux_stats.pl -P -w 1000 -c 2000 
  206. /usr/local/nagios/libexec/check_linux_stats.pl -T -w 9551820 -c 9551890 -p /var/run/jonas.pid