監控mysql之orzdba和orztop
Orzdba
將MySQL效能統計資訊進行計算,統計MySQL/INNODB層面的各種指標(QPS/TPS/thread/buffer/log等), 將OS和MySQL統計引數放在一個螢幕中展現。
可選項
-L,--logfile Print to Logfile.
-l,--load Print Load Info.
-c,--cpu Print Cpu Info.
-s,--swap Print Swap Info.
-d,--disk Print Disk Info.
-n,--net Print Net Info.
-com Print MySQL Status(Com_select,Com_insert,Com_update,Com_delete).
-hit Print Innodb Hit%.
-innodb_rows Print Innodb Rows Status(Innodb_rows_inserted/updated/deleted/read).
-innodb_pages Print Innodb Buffer Pool Pages Status(Innodb_buffer_pool_pages_data/free/dirty/flushed)
-innodb_data Print Innodb Data Status(Innodb_data_reads/writes/read/written)
-innodb_log Print Innodb Log Status(Innodb_os_log_fsyncs/written)
-innodb_status Print Innodb Status from Command: 'Show Engine Innodb Status'
(history list/ log unflushed/uncheckpointed bytes/ read views/ queries inside/queued)
-T,--threads Print Threads Status(Threads_running,Threads_connected,Threads_created,Threads_cached).
以—com為例檢視原始碼
登入mysql,執行show global status並過濾出候選狀態變數
my $mysql = qq{$MYSQL -e 'show global status where Variable_name in ("Com_select","Com_insert","Com_update","Com_delete","Innodb_buffer_pool_read_requests","Innodb_buffer_pool_reads","Innodb_rows_inserted","Innodb_rows_updated","Innodb_rows_deleted","Innodb_rows_read","Threads_running","Threads_connected","Threads_cached","Threads_created","Bytes_received","Bytes_sent","Innodb_buffer_pool_pages_data","Innodb_buffer_pool_pages_free","Innodb_buffer_pool_pages_dirty","Innodb_buffer_pool_pages_flushed","Innodb_data_reads","Innodb_data_writes","Innodb_data_read","Innodb_data_written","Innodb_os_log_fsyncs","Innodb_os_log_written")'};
將兩次執行結果相減併除以時間間隔,即可得出每秒的資料
my $insert_diff = ( $mystat2{"Com_insert"} - $mystat1{"Com_insert"} ) / $interval;
my $update_diff = ( $mystat2{"Com_update"} - $mystat1{"Com_update"} ) / $interval;
my $delete_diff = ( $mystat2{"Com_delete"} - $mystat1{"Com_delete"} ) / $interval;
my $select_diff = ( $mystat2{"Com_select"} - $mystat1{"Com_select"} ) / $interval;
列印輸出
if ($com) {
# Com_insert # Com_update # Com_delete
print $LOG_OUT WHITE();
printf $LOG_OUT "%5d %5d %5d",$insert_diff,$update_diff,$delete_diff;
print $LOG_OUT YELLOW();
# Com_select
printf $LOG_OUT " %6d",$select_diff;
# Total TPS
printf $LOG_OUT " %5d",$insert_diff+$update_diff+$delete_diff;
print $LOG_OUT GREEN(),"|",RESET();
}
可以執行Orzdba持續監控mysql並把結果輸出到日誌,這樣當非工作時間系統執行慢的時候可以回頭檢視歷史資訊,透過com_select等指標同時配合OS cpu/mem/io資訊,可以快速做出一個大致判斷,
Orztop
可即時顯示mysql當前query list,以及每秒的DML/select以及邏輯讀等指標,用於即時的系統調優;
注:邏輯讀的計算來源於innodb_buffer_pool_read_requests,而innodb_buffer_pool_reads則是須從磁碟讀取的邏輯讀次數;
該工具選項比較少
-h,–host Hostname/Ip to use for mysql connection.
-u,–user User to use for mysql connection.
-p,–pwd Password to use for mysql connection.
-P,–port Port to use for mysql connection(default 3306).
-S,–socket Socket to use for mysql connection.
-t Time(second) Interval.
程式碼片段
my $sql_processlist = qq{show full processlist};
my @processlist = &hashes($sql_processlist);
@mysql_processlist = @processlist;
@mysql_processlist = sort{ $a->{time} <=> $b->{time} } @mysql_processlist;
對show full processlist的結果進行封裝,然後遍歷
foreach (@mysql_processlist) {
next if ($_->{command} eq "Sleep" or $_->{command} eq "Binlog Dump" or $_->{command} eq "Connect") and not $mysql_processlist_idle;
next if ($_->{db} !~ $mysql_processlist_filter_db);
next if ($_->{user} !~ $mysql_processlist_filter_user);
next if ($_->{info} !~ $mysql_processlist_filter_sql);
if ( 1 ) {
printf "%8s %20s %15s %15s %15s %10s", $_->{id},$_->{host}, $_->{user}, $_->{db}, $_->{command},$_->{time} ;
print color('magenta') ;
printf " %-50s\n",$_->{state};
if ($_->{info} ne '') {
if ( $mysql_filter ) {
$_->{info} =~ /$mysql_filter/i ;
print color('yellow') ;
print " ==> [ SQL ] ".$`;
print color('bold red') ;
print $& ;
print color('reset yellow') ;
print $'."\n" ;
} else {
print color('yellow') ;
print " ==> [ SQL ] ".$_->{info}."\n";
}
}
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15480802/viewspace-1425464/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL監控工具之orzdbaMySql
- MySQL監控工具-orztopMySql
- MySQL監控工具-orzdbaMySql
- 安裝實時監控mysql開源工具GitHub orzdba操作指南MySql開源工具Github
- 小花狸監控之MySQLMySql
- MYSQL和SQLServer效能監控指標MySqlServer指標
- MySQL調優效能監控之show profileMySql
- MySQL調優效能監控之performance schemaMySqlORM
- MySQL監控工具MySql
- MySQL監控--zabbixMySql
- cacti監控mysqlMySql
- 【MySQL】MHA原始碼之監控檢查(一)MySql原始碼
- MySQL監控利器-InnotopMySql
- mysql監控指令碼MySql指令碼
- Mysql 監控系統MySql
- Mysql監控快速指南MySql
- MySQL sys效能監控MySql
- Kubernetes監控實踐(2):可行監控方案之Prometheus和SensuPrometheus
- Java監控神器之psi-probe監控Tomcat和應用JavaTomcat
- mysql 的一個監控指令碼,監控heartbeatMySql指令碼
- MongoDB之監控MongoDB
- 使用夜鶯和 Categraf 快速建設 MySQL 監控MySql
- MySQL調優使用者監控之show processlistMySql
- 伺服器監控之 ping 監控伺服器
- MySQL監控-Datadog資料庫監控調研MySql資料庫
- mysql mon 的一個監控指令碼,監控heartbeatMySql指令碼
- 配置CACTI監控MySQL資料庫狀態(5)增加MySQL監控模板MySql資料庫
- 搭建Lepus 天兔 監控MySQLMySql
- mysql效能監控相關MySql
- Prometheus MySQL監控+grafana展示PrometheusMySqlGrafana
- Mysql事件監控日誌MySql事件
- Cacti0.8.8a監控mysqlMySql
- mysql效能監控指標MySql指標
- Nagios使用check_mysql監控mysqliOSMySql
- zabbix和mysql performance monitor模板實現mysql資料庫的監控MySqlORM資料庫
- 監控和優化RMAN之SET COMMAND ID優化
- Mysql效能監控視覺化MySql視覺化
- zabbix使用perconaplugin監控mysqlPluginMySql