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

[经验分享] 开源监控解决方案:icinga(nagios)监控linux与tomcat

[复制链接]

尚未签到

发表于 2018-11-30 09:28:54 | 显示全部楼层 |阅读模式
[root@zxweb ~]# useradd nagios
[root@zxweb ~]# tar zxvf nagios-plugins-2.2.1.tar.gz
[root@zxweb ~]# cd nagios-plugins-2.2.1
[root@zxweb nagios-plugins-2.2.1]# ./configure --prefix=/usr/local/nagios \
--with-cgiurl=/nagios/cgi-bin \
--with-nagios-user=nagios \
--with-nagios-group=nagios
[root@zxweb nagios-plugins-2.2.1]# make
[root@zxweb nagios-plugins-2.2.1]# make install
[root@zxweb ~]# yum install -y xinetd
[root@zxweb ~]# tar zxvf nrpe-3.2.1.tar.gz
[root@zxweb ~]# cd nrpe-3.2.1
[root@zxweb nrpe-3.2.1]# ./configure --prefix=/usr/local/nagios --enable-ssl
[root@zxweb nrpe-3.2.1]# make all
[root@zxweb nrpe-3.2.1]# make install
[root@zxweb nrpe-3.2.1]# make install-plugin
[root@zxweb nrpe-3.2.1]# make install-daemon
[root@zxweb nrpe-3.2.1]# make install-config
[root@zxweb nrpe-3.2.1]# make install-inetd
[root@zxweb ~]# vi /etc/xinetd.d/nrpe
# default: off
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
    disable         = no
    socket_type     = stream
    port            = 5666
    wait            = no
    user            = nagios
    group           = nagios
    server          = /usr/local/nagios/bin/nrpe
    server_args     = -c /usr/local/nagios/etc/nrpe.cfg --inetd
    only_from       = 192.168.1.200
    log_on_success  =
}
[root@zxweb ~]# vi /etc/services
nrpe            5666/tcp                # nagios
[root@zxweb ~]# yum -y  install perl-Time-HiRes
[root@zxweb ~]# rpm -ivh perl-UNIVERSAL-require-0.13-1.el6.rf.noarch.rpm
[root@zxweb ~]# tar zxvf Sys-Statistics-Linux-0.66.tar.gz
[root@zxweb ~]# cd Sys-Statistics-Linux-0.66
[root@zxweb Sys-Statistics-Linux-0.66]# perl Makefile.PL
[root@zxweb Sys-Statistics-Linux-0.66]# make
[root@zxweb Sys-Statistics-Linux-0.66]# make install
[root@zxweb ~]# vi /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=192.168.1.200
command[check_cpu]=/usr/local/nagios/libexec/check_linux_stats.pl -C -w 50 -c 80 -s 5
command[check_memory]=/usr/local/nagios/libexec/check_memory.py -w 20 -c 10
command[check_disk]=/usr/local/nagios/libexec/check_disk.pl -w 20 -c 10
command[check_network]=/usr/local/nagios/libexec/check_linux_stats.pl -N -w 1048576 -c 2097152 -p eth0
command[check_uptime]=/usr/local/nagios/libexec/check_linux_stats.pl -U -w 5
[root@zxweb ~]# cd /usr/local/nagios/libexec
[root@zxweb libexec]# chmod a+x check_linux_stats.pl
[root@zxweb libexec]# chmod a+x check_memory.py
[root@zxweb libexec]# chmod a+x check_disk.pl
[root@zxweb libexec]# ./check_linux_stats.pl -C -w 50 -c 80 -s 5
CPU OK : idle 97.79% |idle=97.79%;50;80 user=0.00% system=0.00% iowait=2.21% steal=0.00%
[root@zxweb ~]# /etc/init.d/xinetd start
Starting xinetd:                                           [  OK  ]
[root@zxweb ~]# netstat -tunlp | grep 5666
tcp        0      0 :::5666                     :::*                        LISTEN      2409/xinetd
[root@zxweb ~]# cd /usr/local/tomcat/conf
[root@zxweb conf]# vi tomcat-users.xml
  
  
[root@zxweb ~]# cd /usr/local/icinga/libexec
[root@zxweb libexec]# ./check_tomcat.py -h
usage: check_tomcat.py [-h] [-V] [-v] -H HOST -p PORT [-u USER] [-a PASS]
                       [-U URL] [-C CONNECTOR] [-t TIMEOUT] [-e EXPIRE_TIME]
                       [-n NAMEAPP] [-w WARNING] [-c CRITICAL] -m
                       {status,mem,thread,app}
Nagios plugin for check an apache tomcat server
optional arguments:
  -h, --help            show this help message and exit
  -V, --version         Show plugin version
  -v, --verbosity       increase output verbosity:
                                            -v Single line, additional information (eg list processes that fail)
                                            -vv Multi line, configuration debug output (eg ps command used)
                                            -vvv Lots of detail for plugin problem diagnosis

Connection parameters:
  parameters for Tomcat connection
  -H HOST, --host HOST  Name or Ip of tomcat host
  -p PORT, --port PORT  Tomcat port (Example:8080)
  -u USER, --user USER  Tomcat user
  -a PASS, --authentication PASS
                        Tomcat authentication password
  -U URL, --URL URL     Tomcat manager app url "/manager" by default
  -C CONNECTOR, --connector CONNECTOR
                        Connector name, used in thread mode
  -t TIMEOUT, --timeout TIMEOUT
                        Timeout for connection (5 seconds by default)
  -e EXPIRE_TIME, --expire_time EXPIRE_TIME
                        Expire time for sessions created in tomcat manager app
                                            value in minutes (0 minutes by default)
Check parameters:
  Parameters for tomcat check
  -n NAMEAPP, --nameapp NAMEAPP
                        Name of the java application you want to check, only for app mode
  -w WARNING, --warning WARNING
                        Warning value
  -c CRITICAL, --critical CRITICAL
                        Critical value
  -m {status,mem,thread,app}, --mode {status,mem,thread,app}
                        Tomcat monitorizacion mode:
                            status: The status of tomcat server
                            mem:    Tomcat server used percentage memory status, warning and critical
                                    values. Requiered in percentage.
                            thread: Tomcat connectors Threads used, warning and critical values requiered.
                                    The parameter connector is optional, if not exists, all connector were shown.
                            app:    Application status in tomcat server, the name of the application
                                    must be defined with the parameter -n or --nameapp.
                                    This option check the status of java application running on tomcat server[root@nagios ~]# cd /usr/local/icinga/etc/objects/
[root@nagios objects]# vi commands.cfg
define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }
define command{
        command_name    check_tomcat
        command_line    $USER1$/check_tomcat.py -H $HOSTADDRESS$ -p $ARG1$ -u $ARG2$ -a $ARG3$ -w $ARG4$ -c $ARG5$ -m $ARG6$
        }
define command{
        command_name    check_http
        command_line    $USER1$/check_http -H $HOSTADDRESS$ -p $ARG1$ -e 200
        }      
[root@nagios objects]# vi tomcat.cfg
# define a host
define host{
        use                     linux-server
        host_name               zxweb
        alias                   zxweb
        icon_image              redhat.gif
        statusmap_image         redhat.gd2
        address                 192.168.1.201
        }
# define an hostgroup
define hostgroup{
        hostgroup_name  sale-tomcat
        alias        webapp
        members      zxweb
        }
# define an servicegroup
define servicegroup {
        servicegroup_name  ping
        alias   alive
        }
define servicegroup {
        servicegroup_name  os
        alias   linux
        }
# define an servicegroup
define servicegroup {
        servicegroup_name  webapp
        alias   tomcat
}
# Define a service
define service{
        hostgroup_name                  sale-tomcat
        use                             generic-service
        service_description             alive
        servicegroups                   ping
        check_command                   check_ping!100.0,20%!500.0,60%
        }
define service{
        hostgroup_name                  sale-tomcat
        use                             generic-service
        service_description             os cpu usage
        servicegroups                   os
        check_command                   check_nrpe!check_cpu
        }
define service{
        hostgroup_name                  sale-tomcat
        use                             generic-service
        service_description             os memory usage
        servicegroups                   os
        check_command                   check_nrpe!check_memory
        }
define service{
        hostgroup_name                  sale-tomcat
        use                             generic-service
        service_description             os disk usage
        servicegroups                   os
        check_command                   check_nrpe!check_disk
        }
define service{
        hostgroup_name                  sale-tomcat
        use                             generic-service
        service_description             os network usage
        servicegroups                   os
        check_command                   check_nrpe!check_network
        }
define service{
        hostgroup_name                  sale-tomcat
        use                             generic-service
        service_description             os uptime
        servicegroups                   os
        check_command                   check_nrpe!check_uptime
        }
define service{
        hostgroup_name                  zxweb
        use                             generic-service
        service_description             zxweb status
        servicegroups                   webapp
        check_command                   check_http!8080
        }               
define service{
        hostgroup_name                  zxweb
        use                             generic-service
        service_description             tomcat status
        servicegroups                   webapp
        check_command                   check_tomcat!8080!admin!abcd.1234!80!90!status
        }
define service{
        hostgroup_name                  zxweb
        use                             generic-service
        service_description             tomcat memory
        servicegroups                   webapp
        check_command                   check_tomcat!8080!admin!abcd.1234!80!90!mem
        }
define service{
        hostgroup_name                  zxweb
        use                             generic-service
        service_description             tomcat thread
        servicegroups                   webapp
        check_command                   check_tomcat!8080!admin!abcd.1234!80!90!thread
        }
[root@nagios ~]# cd /usr/local/icinga/etc        
[root@nagios etc]# vi icinga.cfg
cfg_file=/usr/local/icinga/etc/objects/tomcat.cfg
[root@nagios ~]# service icinga restart
Running configuration check...OK
Stopping Icinga: Waiting for icinga to exit ..Stopping icinga done.
Starting icinga: Starting icinga done.



运维网声明 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-641428-1-1.html 上篇帖子: 检测tomcat假死时重新启动及邮件通知 下篇帖子: Centos6.5系统搭建tomcat7.0.57通过msm实现session共享
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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