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

Ubuntu 10.04下构建Nagios监控平台

[日期:2011-07-05] 来源:mike.org.cn  作者:mike [字体: ]
5、监控被监控主机上的运行的总进程数
1
2
3
4
5
6
7
8
vi /usr/local/nagios/etc/server/linuxsever.cfg
 
define service{
        use                             generic-service         ; Name of service template to use
        host_name                       linuxsever1
        service_description             Total Processes
	check_command			check_nrpe!check_total_procs
        }

  B、监控被监控主机上的应用服务

  1、监控MySQL

  监控MySQL有两种方法,一种是通过官方的check_mysql插件,另一种是通过第三方的check_mysql_health的插件。check_mysql_health的功能更为强大一些,这里我两种都简单的说下。
  
  a、通过官方的check_mysql插件实现

  在被监控主机上的数据库添加监控帐号密码

1
2
GRANT ALL PRIVILEGES ON *.* TO 'nagios'@'192.168.1.%' IDENTIFIED BY '000000';
Flush Privileges;

  commands.cfg加入以下内容

1
2
3
4
5
6
vi /usr/local/nagios/etc/objects/commands.cfg
 
define command{
	command_name check_mysql
	command_line $USER1$/check_mysql -H $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$
	}

  linuxsever.cfg中加入以下内容

1
2
3
4
5
6
7
8
9
vi /usr/local/nagios/etc/server/linuxsever.cfg
 
define service{
	 use                     generic-service
	 host_name               linuxsever1
	 service_description     mysql
	 check_command           check_mysql!192.168.1.106!3306!nagios!000000
	 notifications_enabled   1
	}

  b、通过check_mysql_health插件实现MySQL监控

  check_mysql_health插件比起官方的check_mysql插件功能更为强大,check_mysql_health不但能监控MySQL是否正常运行,还能监控MySQL主从、MySQL连接数情况、MySQL慢查询等多种监控指标。

  check_mysql_health官方主页:http://labs.consol.de/nagios/check_mysql_health/

  安装check_mysql_health

1
2
3
4
5
6
wget http://labs.consol.de/wp-content/uploads/2011/04/check_mysql_health-2.1.5.1.tar.gz
tar xvzf check_mysql_health-2.1.5.1.tar.gz 
cd check_mysql_health-2.1.5.1
./configure
make
make install

  check_mysql_health插件基本用法

1
check_mysql_health --hostname 192.168.1.106 --port 3306 --username nagios --password 000000 --mode slave-io-running

  各参数具体含义

1
2
3
4
5
--hostname 定义被监控主机的IP或机器名
--port     定义被监控主机上MySQL的运行端口
--username 定义被监控主机上MySQL的用户名
--password  定义被监控主机上MySQL的密码
--mode   定义被监控主机上MySQL的监控指标

  监控MySQL主从

1
2
GRANT super,process ON *.* TO 'nagios'@'192.168.1.%' IDENTIFIED BY '000000';
Flush Privileges;

  commands.cfg加入以下内容

1
2
3
4
5
6
vi /usr/local/nagios/etc/objects/commands.cfg
 
define command{
        command_name check_mysql_health
        command_line $USER1$/check_mysql_health --hostname $ARG1$ --port $ARG2$ --username $ARG3$ --password $ARG4$ --mode $ARG5$
        }

  linuxsever.cfg中加入以下内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
vi /usr/local/nagios/etc/server/linuxsever.cfg
 
define service{
        use                             generic-service         ; Name of service template to use
        host_name                       linuxsever1
        service_description             check_mysql_slave_io
        check_command                   check_mysql_health!192.168.1.106!3306!nagios!000000!slave-io-running
        notifications_enabled           1
        }
 
define service{
        use                             generic-service         ; Name of service template to use
        host_name                       linuxsever1
        service_description             check_mysql_slave_sql
        check_command                   check_mysql_health!192.168.1.106!3306!nagios!000000!slave-sql-running
        notifications_enabled           1
        }

  监控MySQL连接时间

1
2
3
4
5
6
7
8
9
vi /usr/local/nagios/etc/server/linuxsever.cfg
 
define service{
        use                             generic-service         ; Name of service template to use
        host_name                       linuxsever1
        service_description             check_mysql_connection_time
        check_command                   check_mysql_health!192.168.2.50!3306!nagios!PoGtvEu4qkhP8jILruo0!connection-time
        notifications_enabled           1
        }

  监控MySQL连接数

1
2
3
4
5
6
7
8
9
vi /usr/local/nagios/etc/server/linuxsever.cfg
 
define service{
        use                             generic-service         ; Name of service template to use
        host_name                       linuxsever1
        service_description             check_mysql_threads_connected
        check_command                   check_mysql_health!192.168.2.50!3306!nagios!PoGtvEu4qkhP8jILruo0!threads-connected
        notifications_enabled           1
        }

  监控MySQL慢查询情况

1
2
3
4
5
6
7
8
9
vi /usr/local/nagios/etc/server/linuxsever.cfg
 
define service{
        use                             generic-service         ; Name of service template to use
        host_name                       linuxsever1
        service_description             check_mysql_slow_queries
        check_command                   check_mysql_health!192.168.2.50!3306!nagios!PoGtvEu4qkhP8jILruo0!slow-queries
        notifications_enabled           1
        }

  监控MySQL锁表情况

1
2
3
4
5
6
7
8
9
vi /usr/local/nagios/etc/server/linuxsever.cfg
 
define service{
        use                             generic-service         ; Name of service template to use
        host_name                       linuxsever1
        service_description             check_mysql_table_lock_contention
        check_command                   check_mysql_health!192.168.2.50!3306!nagios!PoGtvEu4qkhP8jILruo0!table-lock-contention
        notifications_enabled           1
        }

  2、监控Rsync

  下载监控脚本check_rsync2

1
2
3
4
cd /usr/local/nagios/libexec/
wget -O check_rsync2 'http://exchange.nagios.org/components/com_mtree/attachment.php?link_id=307&cf_id=29' 
chown nagios:nagios check_rsync2
chmod 755 check_rsync2

  commands.cfg加入以下内容

1
2
3
4
5
6
vi /usr/local/nagios/etc/objects/commands.cfg
 
define command{
	command_name check_rsync
	command_line $USER1$/check_rsync2 -H $HOSTADDRESS$ -p $ARG1$
	}

  linuxsever.cfg中加入以下内容

1
2
3
4
5
6
7
8
9
vi /usr/local/nagios/etc/server/linuxsever.cfg
 
define service{
	 use                     generic-service
	 host_name               linuxsever1
	 service_description     rsync
	 check_command           check_rsync!873
	 notifications_enabled   1
	}

  3、监控HTTP

  linuxsever.cfg中加入以下内容

1
2
3
4
5
6
7
8
9
vi /usr/local/nagios/etc/server/linuxsever.cfg
 
define service{
        use                             generic-service         ; Name of service template to use
        host_name                       linuxsever1
        service_description             HTTP
	check_command			check_http
	notifications_enabled		1
        }

  

linux
本文评论   查看全部评论 (1)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
第 1 楼
* 十年 发表于 2011/8/24 16:36:01
我想问下 你的apt源是什么啊?我安装GD和libgd2-noxpm libgd2-noxpm-dev 这三个东西的时候找不到啊,我用的是163的源。