SNMP監控MYSQL資料庫
阿新 • • 發佈:2019-01-09
利用mysql-SNMP監控mysql
說明:mysql-snmp 為用PERL寫的一個為snmp的一個代理,用於獲取mysql資訊,僅支援 innodb引擎
部署方法:
1) 配置 EPEL YUM源
由於這個玩意是用PERL寫的,所以用了很多模組,慶幸的是EPEL提供了這些模組的RPM包,不然,真的很慘(以REDHAT6.4 X86_64 bit)
[EPEL]
name=epel
baseurl:http://dl.fedoraproject.org/pub/epel/6/x86_64/
enabled=1
gpgcheck=0
2)下載mysql-snmp
3)製作 mysql-snmp 的RPM包
shell> cd /usr/src/mysql-snmp-1.2/redhat
shell> rpmbuild -ba mysql-snmp.spec
會在對應的解壓處生成相關目錄如下:
shell> pwd
/root/rpmbuild <---我是將下載的檔案先上傳到/root,然後再解壓到/usr/src/ 所以,生成的rpmbuild目錄就會此處生成
在對應的RPMS目錄中就會生成對應RPM包 mysql-snmp-1.2-1.el6.noarch.rpm 了
4) 安裝對應的RPM包
shell> yum localinstall mysql-snmp -y <---若已配置好YUM源,不出意外,就會將所在依賴關係搞定了,反之,就只有手工解決。
安裝好的相關檔案如下:
shell> rpm -ql mysql-snmp-1.2-1.el6.noarch
/etc/rc.d/init.d/mysql-snmp
/etc/snmp/my.cnf
/etc/sysconfig/mysql-snmp
/usr/sbin/mysql-snmp
/usr/share/doc/mysql-snmp-1.2
/usr/share/doc/mysql-snmp-1.2/COPYING
/usr/share/doc/mysql-snmp-1.2/README
/usr/share/doc/mysql-snmp-1.2/mysql.datacollection-config.xml
/usr/share/doc/mysql-snmp-1.2/mysql.snmp-graph.properties
/usr/share/doc/mysql-snmp-1.2/tools
/usr/share/doc/mysql-snmp-1.2/tools/cacti2MIB.pl
/usr/share/doc/mysql-snmp-1.2/tools/cacti2opennms.pl
/usr/share/man/man1/mysql-snmp.1.gz
/usr/share/snmp/mibs/MYSQL-SERVER-MIB.txt
5)修改/etc/snmp/my.cnf 指定相關資訊
[client]
host=localhost
#port=3306
user=monitor
password=secret
6)登陸mysql資料庫, 新增 使用者monitor及設定密碼為secret,授權大小最好只具有本地查詢許可權
7)啟動mysql-snmp服務,並設定成開機啟動
shell> /etc/init.d/mysql-snmp start && chkconfig mysql-snmp on
8) 修改/etc/snmp/snmpd.conf 新增第三方MIB庫資訊,同時授權SNMP採集mysql-snmp資訊(snmp已能正常採集系統資訊),增加如下內容:
mibs +MYSQL-SERVER-MIB
master agentx
9) 重啟snmpd 服務,並測試是否成功。
shell> /etc/init.d/snmpd restart
shell> snmpwalk -v 2c -c public 127.0.0.1 .1.3.6.1.4.1.20267.200.1.43
SNMPv2-SMI::enterprises.20267.200.1.43.0 = Counter32: 0
能返回正常資訊即OK了
--------------- 配置完成 -------------------
說明:mysql-snmp 為用PERL寫的一個為snmp的一個代理,用於獲取mysql資訊,僅支援 innodb引擎
部署方法:
1) 配置 EPEL YUM源
由於這個玩意是用PERL寫的,所以用了很多模組,慶幸的是EPEL提供了這些模組的RPM包,不然,真的很慘(以REDHAT6.4 X86_64 bit)
[EPEL]
name=epel
baseurl:http://dl.fedoraproject.org/pub/epel/6/x86_64/
enabled=1
gpgcheck=0
2)下載mysql-snmp
下載地址;https://github.com/masterzen/mysql-snmp/releases
或 http://download.csdn.net/detail/nerissa/7070631
並解壓至/usr/src3)製作 mysql-snmp 的RPM包
shell> cd /usr/src/mysql-snmp-1.2/redhat
shell> rpmbuild -ba mysql-snmp.spec
會在對應的解壓處生成相關目錄如下:
shell> pwd
/root/rpmbuild <---我是將下載的檔案先上傳到/root,然後再解壓到/usr/src/ 所以,生成的rpmbuild目錄就會此處生成
在對應的RPMS目錄中就會生成對應RPM包 mysql-snmp-1.2-1.el6.noarch.rpm 了
4) 安裝對應的RPM包
shell> yum localinstall mysql-snmp -y <---若已配置好YUM源,不出意外,就會將所在依賴關係搞定了,反之,就只有手工解決。
安裝好的相關檔案如下:
shell> rpm -ql mysql-snmp-1.2-1.el6.noarch
/etc/rc.d/init.d/mysql-snmp
/etc/snmp/my.cnf
/etc/sysconfig/mysql-snmp
/usr/sbin/mysql-snmp
/usr/share/doc/mysql-snmp-1.2
/usr/share/doc/mysql-snmp-1.2/COPYING
/usr/share/doc/mysql-snmp-1.2/README
/usr/share/doc/mysql-snmp-1.2/mysql.datacollection-config.xml
/usr/share/doc/mysql-snmp-1.2/mysql.snmp-graph.properties
/usr/share/doc/mysql-snmp-1.2/tools
/usr/share/doc/mysql-snmp-1.2/tools/cacti2MIB.pl
/usr/share/doc/mysql-snmp-1.2/tools/cacti2opennms.pl
/usr/share/man/man1/mysql-snmp.1.gz
/usr/share/snmp/mibs/MYSQL-SERVER-MIB.txt
5)修改/etc/snmp/my.cnf 指定相關資訊
[client]
host=localhost
#port=3306
user=monitor
password=secret
6)登陸mysql資料庫, 新增 使用者monitor及設定密碼為secret,授權大小最好只具有本地查詢許可權
7)啟動mysql-snmp服務,並設定成開機啟動
shell> /etc/init.d/mysql-snmp start && chkconfig mysql-snmp on
8) 修改/etc/snmp/snmpd.conf 新增第三方MIB庫資訊,同時授權SNMP採集mysql-snmp資訊(snmp已能正常採集系統資訊),增加如下內容:
mibs +MYSQL-SERVER-MIB
master agentx
9) 重啟snmpd 服務,並測試是否成功。
shell> /etc/init.d/snmpd restart
shell> snmpwalk -v 2c -c public 127.0.0.1 .1.3.6.1.4.1.20267.200.1.43
SNMPv2-SMI::enterprises.20267.200.1.43.0 = Counter32: 0
能返回正常資訊即OK了
--------------- 配置完成 -------------------
附: OID 列表
MYSQL檢查項 | OID |
Key_read_requests | .1.3.6.1.4.1.20267.200.1.1 |
Key_reads | .1.3.6.1.4.1.20267.200.1.2 |
Key_write_requests | .1.3.6.1.4.1.20267.200.1.3 |
Key_writes | .1.3.6.1.4.1.20267.200.1.4 |
history_list | .1.3.6.1.4.1.20267.200.1.5 |
innodb_transactions | .1.3.6.1.4.1.20267.200.1.6 |
read_views | .1.3.6.1.4.1.20267.200.1.7 |
current_transactions | .1.3.6.1.4.1.20267.200.1.8 |
locked_transactions | .1.3.6.1.4.1.20267.200.1.9 |
active_transactions | .1.3.6.1.4.1.20267.200.1.10 |
pool_size | .1.3.6.1.4.1.20267.200.1.11 |
free_pages | .1.3.6.1.4.1.20267.200.1.12 |
database_pages | .1.3.6.1.4.1.20267.200.1.13 |
modified_pages | .1.3.6.1.4.1.20267.200.1.14 |
pages_read | .1.3.6.1.4.1.20267.200.1.15 |
pages_created | .1.3.6.1.4.1.20267.200.1.16 |
pages_written | .1.3.6.1.4.1.20267.200.1.17 |
file_fsyncs | .1.3.6.1.4.1.20267.200.1.18 |
file_reads | .1.3.6.1.4.1.20267.200.1.19 |
file_writes | .1.3.6.1.4.1.20267.200.1.20 |
log_writes | .1.3.6.1.4.1.20267.200.1.21 |
pending_aio_log_ios | .1.3.6.1.4.1.20267.200.1.22 |
pending_aio_sync_ios | .1.3.6.1.4.1.20267.200.1.23 |
pending_buf_pool_flushes | .1.3.6.1.4.1.20267.200.1.24 |
pending_chkp_writes | .1.3.6.1.4.1.20267.200.1.25 |
pending_ibuf_aio_reads | .1.3.6.1.4.1.20267.200.1.26 |
pending_log_flushes | .1.3.6.1.4.1.20267.200.1.27 |
pending_log_writes | .1.3.6.1.4.1.20267.200.1.28 |
pending_normal_aio_reads | .1.3.6.1.4.1.20267.200.1.29 |
pending_normal_aio_writes | .1.3.6.1.4.1.20267.200.1.30 |
ibuf_inserts | .1.3.6.1.4.1.20267.200.1.31 |
ibuf_merged | .1.3.6.1.4.1.20267.200.1.32 |
ibuf_merges | .1.3.6.1.4.1.20267.200.1.33 |
spin_waits | .1.3.6.1.4.1.20267.200.1.34 |
spin_rounds | .1.3.6.1.4.1.20267.200.1.35 |
os_waits | .1.3.6.1.4.1.20267.200.1.36 |
rows_inserted | .1.3.6.1.4.1.20267.200.1.37 |
rows_updated | .1.3.6.1.4.1.20267.200.1.38 |
rows_deleted | .1.3.6.1.4.1.20267.200.1.39 |
rows_read | .1.3.6.1.4.1.20267.200.1.40 |
Table_locks_waited | .1.3.6.1.4.1.20267.200.1.41 |
Table_locks_immediate | .1.3.6.1.4.1.20267.200.1.42 |
Slow_queries | .1.3.6.1.4.1.20267.200.1.43 |
Open_files | .1.3.6.1.4.1.20267.200.1.44 |
Open_tables | .1.3.6.1.4.1.20267.200.1.45 |
Opened_tables | .1.3.6.1.4.1.20267.200.1.46 |
innodb_open_files | .1.3.6.1.4.1.20267.200.1.47 |
open_files_limit | .1.3.6.1.4.1.20267.200.1.48 |
table_cache | .1.3.6.1.4.1.20267.200.1.49 |
Aborted_clients | .1.3.6.1.4.1.20267.200.1.50 |
Aborted_connects | .1.3.6.1.4.1.20267.200.1.51 |
Max_used_connections | .1.3.6.1.4.1.20267.200.1.52 |
Slow_launch_threads | .1.3.6.1.4.1.20267.200.1.53 |
Threads_cached | .1.3.6.1.4.1.20267.200.1.54 |
Threads_connected | .1.3.6.1.4.1.20267.200.1.55 |
Threads_created | .1.3.6.1.4.1.20267.200.1.56 |
Threads_running | .1.3.6.1.4.1.20267.200.1.57 |
max_connections | .1.3.6.1.4.1.20267.200.1.58 |
thread_cache_size | .1.3.6.1.4.1.20267.200.1.59 |
Connections | .1.3.6.1.4.1.20267.200.1.60 |
slave_running | .1.3.6.1.4.1.20267.200.1.61 |
slave_stopped | .1.3.6.1.4.1.20267.200.1.62 |
Slave_retried_transactions | .1.3.6.1.4.1.20267.200.1.63 |
slave_lag | .1.3.6.1.4.1.20267.200.1.64 |
Slave_open_temp_tables | .1.3.6.1.4.1.20267.200.1.65 |
Qcache_free_blocks | .1.3.6.1.4.1.20267.200.1.66 |
Qcache_free_memory | .1.3.6.1.4.1.20267.200.1.67 |
Qcache_hits | .1.3.6.1.4.1.20267.200.1.68 |
Qcache_inserts | .1.3.6.1.4.1.20267.200.1.69 |
Qcache_lowmem_prunes | .1.3.6.1.4.1.20267.200.1.70 |
Qcache_not_cached | .1.3.6.1.4.1.20267.200.1.71 |
Qcache_queries_in_cache | .1.3.6.1.4.1.20267.200.1.72 |
Qcache_total_blocks | .1.3.6.1.4.1.20267.200.1.73 |
query_cache_size | .1.3.6.1.4.1.20267.200.1.74 |
Questions | .1.3.6.1.4.1.20267.200.1.75 |
Com_update | .1.3.6.1.4.1.20267.200.1.76 |
Com_insert | .1.3.6.1.4.1.20267.200.1.77 |
Com_select | .1.3.6.1.4.1.20267.200.1.78 |
Com_delete | .1.3.6.1.4.1.20267.200.1.79 |
Com_replace | .1.3.6.1.4.1.20267.200.1.80 |
Com_load | .1.3.6.1.4.1.20267.200.1.81 |
Com_update_multi | .1.3.6.1.4.1.20267.200.1.82 |
Com_insert_select | .1.3.6.1.4.1.20267.200.1.83 |
Com_delete_multi | .1.3.6.1.4.1.20267.200.1.84 |
Com_replace_select | .1.3.6.1.4.1.20267.200.1.85 |
Select_full_join | .1.3.6.1.4.1.20267.200.1.86 |
Select_full_range_join | .1.3.6.1.4.1.20267.200.1.87 |
Select_range | .1.3.6.1.4.1.20267.200.1.88 |
Select_range_check | .1.3.6.1.4.1.20267.200.1.89 |
Select_scan | .1.3.6.1.4.1.20267.200.1.90 |
Sort_merge_passes | .1.3.6.1.4.1.20267.200.1.91 |
Sort_range | .1.3.6.1.4.1.20267.200.1.92 |
Sort_rows | .1.3.6.1.4.1.20267.200.1.93 |
Sort_scan | .1.3.6.1.4.1.20267.200.1.94 |
Created_tmp_tables | .1.3.6.1.4.1.20267.200.1.95 |
Created_tmp_disk_tables | .1.3.6.1.4.1.20267.200.1.96 |
Created_tmp_files | .1.3.6.1.4.1.20267.200.1.97 |
Bytes_sent | .1.3.6.1.4.1.20267.200.1.98 |
Bytes_received | .1.3.6.1.4.1.20267.200.1.99 |
innodb_log_buffer_size | .1.3.6.1.4.1.20267.200.1.100 |
unflushed_log | .1.3.6.1.4.1.20267.200.1.101 |
log_bytes_flushed | .1.3.6.1.4.1.20267.200.1.102 |
log_bytes_written | .1.3.6.1.4.1.20267.200.1.103 |
relay_log_space | .1.3.6.1.4.1.20267.200.1.104 |
binlog_cache_size | .1.3.6.1.4.1.20267.200.1.105 |
Binlog_cache_disk_use | .1.3.6.1.4.1.20267.200.1.106 |
Binlog_cache_use | .1.3.6.1.4.1.20267.200.1.107 |
binary_log_space | .1.3.6.1.4.1.20267.200.1.108 |
State_closing_tables | .1.3.6.1.4.1.20267.200.1.109 |
State_copying_to_tmp_table | .1.3.6.1.4.1.20267.200.1.110 |
State_end | .1.3.6.1.4.1.20267.200.1.111 |
State_freeing_items | .1.3.6.1.4.1.20267.200.1.112 |
State_init | .1.3.6.1.4.1.20267.200.1.113 |
State_locked | .1.3.6.1.4.1.20267.200.1.114 |
State_login | .1.3.6.1.4.1.20267.200.1.115 |
State_preparing | .1.3.6.1.4.1.20267.200.1.116 |
State_reading_from_net | .1.3.6.1.4.1.20267.200.1.117 |
State_sending_data | .1.3.6.1.4.1.20267.200.1.118 |
State_sorting_result | .1.3.6.1.4.1.20267.200.1.119 |
State_statistics | .1.3.6.1.4.1.20267.200.1.120 |
State_updating | .1.3.6.1.4.1.20267.200.1.121 |
State_writing_to_net | .1.3.6.1.4.1.20267.200.1.122 |
State_none | .1.3.6.1.4.1.20267.200.1.123 |
State_other | .1.3.6.1.4.1.20267.200.1.124 |
additional_pool_alloc | .1.3.6.1.4.1.20267.200.1.125 |
total_mem_alloc | .1.3.6.1.4.1.20267.200.1.126 |
hash_index_cells_total | .1.3.6.1.4.1.20267.200.1.127 |
hash_index_cells_used | .1.3.6.1.4.1.20267.200.1.128 |
innodb_lock_structs | .1.3.6.1.4.1.20267.200.1.129 |
innodb_lock_wait_secs | .1.3.6.1.4.1.20267.200.1.130 |
innodb_tables_in_use | .1.3.6.1.4.1.20267.200.1.131 |
innodb_locked_tables | .1.3.6.1.4.1.20267.200.1.132 |
uncheckpointed_bytes | .1.3.6.1.4.1.20267.200.1.133 |
ibuf_cell_count | .1.3.6.1.4.1.20267.200.1.134 |
ibuf_used_cells | .1.3.6.1.4.1.20267.200.1.135 |
ibuf_free_cells | .1.3.6.1.4.1.20267.200.1.136 |
adaptive_hash_memory | .1.3.6.1.4.1.20267.200.1.137 |
page_hash_memory | .1.3.6.1.4.1.20267.200.1.138 |
dictionary_cache_memory | .1.3.6.1.4.1.20267.200.1.139 |
file_system_memory | .1.3.6.1.4.1.20267.200.1.140 |
lock_system_memory | .1.3.6.1.4.1.20267.200.1.141 |
recovery_system_memory | .1.3.6.1.4.1.20267.200.1.142 |
thread_hash_memory | .1.3.6.1.4.1.20267.200.1.143 |
innodb_sem_waits | .1.3.6.1.4.1.20267.200.1.144 |
innodb_sem_wait_time_ms | .1.3.6.1.4.1.20267.200.1.145 |
key_buf_bytes_unflushed | .1.3.6.1.4.1.20267.200.1.146 |
key_buf_bytes_used | .1.3.6.1.4.1.20267.200.1.147 |
key_buffer_size | .1.3.6.1.4.1.20267.200.1.148 |
Innodb_row_lock_time | .1.3.6.1.4.1.20267.200.1.149 |
Innodb_row_lock_waits | .1.3.6.1.4.1.20267.200.1.150 |