手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Nagios通过check_http监控一台Web应用服务器上多个Tomcat服务

[日期:2014-06-17] 来源:Linux社区  作者:mchdba [字体:大 中 小]

2,去nagios服务器端添加host等监控信息。

2.1 在hosts.cfg里面添加主机信息

  1. define host{
  2. use linux-server
  3. host_name webserver
  4. alias webserver
  5. address 10.xx.xx.10
  6. check_command check-host-alive
  7. max_check_attempts 5
  8. check_period 24x7
  9. contact_groups ops
  10. notification_interval 60
  11. notification_period 24x7
  12. notification_options d,u,r
  13. }

2.2 在service.cfg里面添加web机器监控的命令信息

  1. # No.007 webserver
  2. # service definition
  3. define service{
  4. host_name webserver
  5. service_description check_load
  6. check_command check_nrpe!check_load
  7. max_check_attempts 5
  8. normal_check_interval 3
  9. retry_check_interval 2
  10. check_period 24x7
  11. notification_interval 10
  12. notification_period 24x7
  13. notification_options w,u,c,r
  14. contact_groups opsweb
  15. }
  16. define service{
  17. host_name webserver
  18. service_description check-host-alive
  19. check_command check-host-alive
  20. max_check_attempts 5
  21. normal_check_interval 3
  22. retry_check_interval 2
  23. check_period 24x7
  24. notification_interval 10
  25. notification_period 24x7
  26. notification_options w,u,c,r
  27. contact_groups opsweb
  28. }
  29. define service{
  30. host_name webserver
  31. service_description Check Disk sda1
  32. check_command check_nrpe!check_sda1
  33. max_check_attempts 5
  34. normal_check_interval 3
  35. retry_check_interval 2
  36. check_period 24x7
  37. notification_interval 10
  38. notification_period 24x7
  39. notification_options w,u,c,r
  40. contact_groups opsweb
  41. }
  42. define service{
  43. host_name webserver
  44. service_description Total Processes
  45. check_command check_nrpe!check_total_procs
  46. max_check_attempts 5
  47. normal_check_interval 3
  48. retry_check_interval 2
  49. check_period 24x7
  50. notification_interval 10
  51. notification_period 24x7
  52. notification_options w,u,c,r
  53. contact_groups opsweb
  54. }
  55. define service{
  56. host_name webserver
  57. service_description Current Users
  58. check_command check_nrpe!check_users
  59. max_check_attempts 5
  60. normal_check_interval 3
  61. retry_check_interval 2
  62. check_period 24x7
  63. notification_interval 10
  64. notification_period 24x7
  65. notification_options w,u,c,r
  66. contact_groups opsweb
  67. }
  68. define service{
  69. host_name webserver
  70. service_description Check Zombie Procs
  71. check_command check_nrpe!check_zombie_procs
  72. max_check_attempts 5
  73. normal_check_interval 3
  74. retry_check_interval 2
  75. check_period 24x7
  76. notification_interval 10
  77. notification_period 24x7
  78. notification_options w,u,c,r
  79. contact_groups opsweb
  80. }
  81. define service{
  82. host_name webserver
  83. service_description Check Tomcat 9300 Status
  84. check_command check_nrpe!check_tomcat_9300_status
  85. max_check_attempts 5
  86. normal_check_interval 3
  87. retry_check_interval 2
  88. check_period 24x7
  89. notification_interval 10
  90. notification_period 24x7
  91. notification_options w,u,c,r
  92. contact_groups opsweb
  93. }

2.3 在vim contacts.cfg添加新的opsweb邮件组信息

  1. define contactgroup{
  2. contactgroup_name opsweb
  3. alias pl ops team
  4. members tim,mch,nagiosadmin
  5. }

2.4 添加新的监控tomcat的命令,check_tomcat_9300_status

这里不采用check_tcp!8080端口的方式,是因为在实际中tomcat服务假死之后,jsp的网页都是打不开的,但是这个监控端口8080都是正常的,不会报警出来;所以采用check_http的方式,新建立一个通用的/nagios_test_0611/nagios_test_0611.jsp文件,来检测这个jsp的访问情况,如下所示:

  1. vim commands.cfg
  2. # add by tim on 20140611
  3. define command{
  4. command_name check_tomcat_9300_status
  5. command_line $USER1$/check_http -I $HOSTADDRESS$ -p $PORT$ -u $URL$ -e $N200$ -w $Warning$ -c$Cri$
  6. }

Jsp文件内容如下:

  1. [root@webserver webapps]# vim . /nagios_test_0611/nagios_test_0611.jsp
  2. <%@ page language="java"contentType="text/html; charset=gb2312"
  3. pageEncoding="gb2312"%>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  5. <html>
  6. <head>
  7. <metahttp-equiv="Content-Type"content="text/html; charset=gb2312">
  8. <title>nagios test here</title>
  9. </head>
  10. <body>
  11. <center>Now time is: <%=new java.util.Date()%></center>
  12. </body>
  13. </html>

2.5 在被监控客户端的nrpe.cfg配置文件里面添加tomcat端口配置信息:

  1. command[check_tomcat_9300_status]=/usr/local/nagios/libexec/check_http -I 10.xx.xx.10 -p 9444 -u /nagios_test_0611/nagios_test_0611.jsp -e 200 -w 5 -c 10
  2. command[check_tomcat_8300_status]=/usr/local/nagios/libexec/check_http -I 10.xx.xx.10 -p 8300 -u /nagios_test_0611/nagios_test_0611.jsp -e 200 -w 5 -c 10

2.6 测试报错

  1. [root@cache-2 objects]# /usr/local/nagios/libexec/check_nrpe -H 10.xx.xx.10 -c check_load
  2. NRPE: Unable to read output
  3. [root@cache-2 objects]#

已经添加了tomcat930端口,现在再添加一个tomcat8300端口

去服务器端shell命令行里面check下

  1. /usr/local/nagios/libexec/check_nrpe -H 192.168.15.178 -c check_mysql_myisam_lock
  2. [root@cache-2 etc]# /usr/local/nagios/libexec/check_nrpe -H 10.xx.xx.10 -c check_load
  3. NRPE: Unable to read output
  4. [root@cache-2 etc]#

同样报错,那么可能就是nagios被监控端的问题。

最终检查是nrpe.cfg里面路径有误,源码安装默认路径是:/usr/local/nagios/libexec/check_http,rpm安装默认路径是:/usr/lib/nagios/plugins/。这里是rpm安装,所以nrpe.cfg配置文件里面用后面rpm的路径/usr/lib/nagios/plugins/,替换下service nrpe restart之后,问题解决,如下图所示:

linux
相关资讯       Nagios监控  Nagios监控Tomcat