最新消息:

nagios pnp4nagios 图形监控 mysql

mysql admin 3034浏览 0评论

nagios图形界面还是比较麻烦的,下面以mysql为例来说一下。监控mysql的插件比较多,在这里了解方法,而不是死搬硬套。

一,安装pnp4nagios

请参考:nagios pnp4nagios 安装 配置

二,安装perl mysql扩展

# yum install perl-Class-DBI-mysql

三,check_mysqld.php和check_mysqld.pl

1,下载

http://exchange.nagios.org/components/com_mtree/attachment.php?link_id=174&cf_id=30
http://exchange.nagios.org/components/com_mtree/attachment.php?link_id=174&cf_id=36

2,修改check_mysqld.php和check_mysqld.pl,本机是64位,根本没有/usr/lib/nagios,所以要把文件中的lib改成lib64

3,copy和修改文件权限

# cp check_mysqld.pl /usr/lib64/nagios/plugins  
  
# chmod 755 /usr/lib64/nagios/plugins/check_mysqld.pl  
# chgrp nagios /usr/lib64/nagios/plugins/check_mysqld.pl  
  
# cp check_mysqld.php /usr/share/nagios/html/pnp4nagios/templates.dist

四,nagios配置

1,修改command.cfg

# vim /etc/nagios/objects/commands.cfg  
  
define command{  
 command_name check_mysqld  
 command_line $USER1$/check_mysqld.pl -H $HOSTADDRESS$ -u nagios -p $USER7$ -a uptime,threads_connected,questions,slow_queries,open_tables -w ',,,,' -c ',,,,' -A $USER21$  
}

2,修改resource.cfg

# vim /etc/nagios/objects/resource.cfg   
  
$USER7$=nagios  
$USER21$='com_select,com_update,com_insert,com_insert_select, 
com_commit,com_delete,com_rollback,aborted_clients, 
aborted_connects,binlog_cache_disk_use,binlog_cache_use, 
bytes_received,bytes_sent,connections,created_tmp_disk_tables, 
created_tmp_files,created_tmp_tables,delayed_errors, 
delayed_insert_threads,delayed_writes,handler_update,handler_write, 
handler_delete,handler_read_first,handler_read_key, 
handler_read_next,handler_read_prev,handler_read_rnd, 
handler_read_rnd_next,key_blocks_not_flushed, 
key_blocks_unused,key_blocks_used,key_read_requests,key_reads, 
key_write_requests,key_writes,max_used_connections, 
not_flushed_delayed_rows,open_files,open_streams,open_tables, 
opened_tables,prepared_stmt_count,qcache_free_blocks, 
qcache_free_memory,qcache_hits,qcache_inserts, 
qcache_lowmem_prunes,qcache_not_cached, 
qcache_queries_in_cache,qcache_total_blocks,questions, 
select_full_join,select_rangle_check,slow_launch_threads, 
slow_queries,table_locks_immediate,table_locks_waited, 
threads_cached,threads_connected,threads_created, 
threads_running'

在这里要注意,$USER21$后面的内容要在一行。

3,修改localhost.cfg

# vim /etc/nagios/objects/localhost.cfg   
  
define service {  
 use local-service,srv-pnp //srv-pnp换成你自定义的  
 host_name localhost  
 service_description MYSQLD  
 check_command check_mysqld!localhost!nagios!nagios  
}

4,pnp4nagios中增加check_mysqld.cfg

# vim /etc/pnp4nagios/check_commands/check_mysqld.cfg  
  
DATATYPE = COUNTER

五,重启nagios

# /etc/init.d/npcd restart  
# /etc/init.d/nrpe restart  
# /etc/init.d/nagios restart

六,查看结果

nagios_mysql

上图可以看出,nagios配置图形监控mysql,已ok了,如果没有数据-nan的话,不要急,等一会就有数据了。

转载请注明:爱开源 » nagios pnp4nagios 图形监控 mysql

您必须 登录 才能发表评论!