Skip to content

Commit c7b2b61

Browse files
committed
Update myawr.pl
1 parent feff290 commit c7b2b61

File tree

1 file changed

+111
-1
lines changed

1 file changed

+111
-1
lines changed

myawr.pl

+111-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
Getopt::Long::Configure qw(no_ignore_case); #
88

9+
10+
( my $sript_name = $0 ) =~ s!.*/(.*)!$1! ;
11+
my $is_running = `ps -ef | grep $sript_name | grep -v grep | wc -l`;
12+
exit if($is_running>2) ;
13+
14+
15+
916
my %opt; # Get options info
1017

1118
# Options
@@ -472,6 +479,10 @@ sub get_mysqlstat {
472479
$vars->{"$row->[0]"} = $row->[1];
473480
}
474481

482+
my ($running_thread_threshold,$times_per_hour)=$dbh_save->selectrow_array("select running_thread_threshold,times_per_hour from myawr.myawr_host where id=$tid");
483+
my $times_saved= $dbh_save->selectrow_array("select count(DISTINCT snap_id) cnt from myawr_engine_innodb_status where snap_time>=DATE_ADD(now(),INTERVAL -1 HOUR) and host_id=$tid");
484+
my $now_running_threads=$mystat2->{"Threads_running"};
485+
my $order_id=1;
475486

476487
# Func : Get Innodb Status from Command: 'Show Engine Innodb Status' ________________start
477488

@@ -487,7 +498,8 @@ sub get_mysqlstat {
487498
# http://code.google.com/p/mysql-cacti-templates/source/browse/trunk/scripts/ss_get_mysql_stats.php
488499
foreach (@result) {
489500
chomp($_);
490-
#print $_ . "\n";
501+
502+
#print $_ . "\n";
491503
# ------------
492504
# TRANSACTIONS
493505
# ------------
@@ -543,6 +555,11 @@ sub get_mysqlstat {
543555
# $innodb_status{""} = $tmp[3];
544556
# }
545557

558+
if($running_thread_threshold<=$now_running_threads and $times_saved<$times_per_hour){
559+
$sql =qq{insert into myawr.myawr_engine_innodb_status(snap_id,host_id,order_id,row_status,snap_time) values($snap_id,$tid,$order_id, \"$_\", \"$snap_time\")};
560+
$dbh_save->do($sql);
561+
$order_id +=1;
562+
}
546563
}
547564
$innodb_status{"unflushed_log"} =
548565
$innodb_status{"log_bytes_written"} - $innodb_status{"log_bytes_flushed"};
@@ -551,6 +568,99 @@ sub get_mysqlstat {
551568

552569
# Func : Get Innodb Status from Command: 'Show Engine Innodb Status' ________________end
553570

571+
if($running_thread_threshold<=$now_running_threads and $times_saved<$times_per_hour){
572+
573+
my $sql2 = qq{ insert into myawr_active_session(snap_id,host_id,USER,HOST,DB,COMMAND,TIME,STATE,INFO,snap_time) values ($snap_id,$tid, ?,?,?, ?, ? ,?,?,?) };
574+
my $sth2 = $dbh_save->prepare( $sql2 );
575+
576+
$sth = $dbh->prepare("select USER,HOST,DB,COMMAND,TIME,STATE,INFO from information_schema.PROCESSLIST where COMMAND<>'Sleep'");
577+
$sth->execute();
578+
while( my @result2 = $sth->fetchrow_array ) {
579+
$sth2->bind_param( 1, $result2[0], SQL_VARCHAR );
580+
$sth2->bind_param( 2, $result2[1], SQL_VARCHAR);
581+
$sth2->bind_param( 3, $result2[2], SQL_VARCHAR );
582+
$sth2->bind_param( 4, $result2[3], SQL_VARCHAR );
583+
$sth2->bind_param( 5, $result2[4], SQL_INTEGER );
584+
$sth2->bind_param( 6, $result2[5], SQL_VARCHAR );
585+
$sth2->bind_param( 7, $result2[6] );
586+
$sth2->bind_param( 8, $snap_time, SQL_DATE );
587+
$sth2->execute();
588+
}
589+
590+
$sql2 = qq{ insert into myawr_innodb_trx(snap_id,host_id,trx_id,trx_state,trx_started,trx_requested_lock_id,trx_wait_started,trx_weight,trx_mysql_thread_id,trx_query,trx_operation_state,trx_tables_in_use,trx_tables_locked,trx_lock_structs,trx_lock_memory_bytes,trx_rows_locked,trx_rows_modified,trx_concurrency_tickets,trx_isolation_level,trx_unique_checks,trx_foreign_key_checks,trx_last_foreign_key_error,trx_adaptive_hash_latched,trx_adaptive_hash_timeout,snap_time) values ($snap_id,$tid,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)};
591+
$sth2 = $dbh_save->prepare( $sql2 );
592+
593+
$sth = $dbh->prepare("select trx_id,trx_state,trx_started,trx_requested_lock_id,trx_wait_started,trx_weight,trx_mysql_thread_id,trx_query,trx_operation_state,trx_tables_in_use,trx_tables_locked,trx_lock_structs,trx_lock_memory_bytes,trx_rows_locked,trx_rows_modified,trx_concurrency_tickets,trx_isolation_level,trx_unique_checks,trx_foreign_key_checks,trx_last_foreign_key_error,trx_adaptive_hash_latched,trx_adaptive_hash_timeout from information_schema.INNODB_TRX");
594+
$sth->execute();
595+
while( my @result2 = $sth->fetchrow_array ) {
596+
$sth2->bind_param( 1, $result2[0], SQL_VARCHAR );
597+
$sth2->bind_param( 2, $result2[1], SQL_VARCHAR);
598+
$sth2->bind_param( 3, $result2[2], SQL_DATE );
599+
$sth2->bind_param( 4, $result2[3], SQL_VARCHAR );
600+
$sth2->bind_param( 5, $result2[4], SQL_DATE );
601+
602+
$sth2->bind_param( 6, $result2[5], SQL_INTEGER );
603+
$sth2->bind_param( 7, $result2[6], SQL_INTEGER );
604+
$sth2->bind_param( 8, $result2[7], SQL_VARCHAR );
605+
$sth2->bind_param( 9, $result2[8], SQL_VARCHAR);
606+
$sth2->bind_param( 10,$result2[9], SQL_INTEGER );
607+
608+
$sth2->bind_param( 11,$result2[10], SQL_INTEGER );
609+
$sth2->bind_param( 12, $result2[11], SQL_INTEGER );
610+
$sth2->bind_param( 13, $result2[12], SQL_INTEGER );
611+
$sth2->bind_param( 14, $result2[13], SQL_INTEGER );
612+
$sth2->bind_param( 15, $result2[14], SQL_INTEGER );
613+
$sth2->bind_param( 16, $result2[15], SQL_INTEGER);
614+
615+
$sth2->bind_param( 17, $result2[16], SQL_VARCHAR );
616+
$sth2->bind_param( 18, $result2[17], SQL_INTEGER );
617+
$sth2->bind_param( 19, $result2[18], SQL_INTEGER );
618+
$sth2->bind_param( 20, $result2[19], SQL_VARCHAR );
619+
$sth2->bind_param( 21, $result2[20], SQL_INTEGER );
620+
$sth2->bind_param( 22, $result2[21], SQL_INTEGER );
621+
$sth2->bind_param( 23, $snap_time, SQL_DATE );
622+
$sth2->execute();
623+
}
624+
625+
$sql2 = qq{ insert into myawr_innodb_locks(snap_id,host_id,lock_id,lock_trx_id,lock_mode,lock_type,lock_table,lock_index,lock_space,lock_page,lock_rec,lock_data,snap_time) values ($snap_id,$tid,?,?,?,?,?,?,?,?,?,?,?)};
626+
$sth2 = $dbh_save->prepare( $sql2 );
627+
628+
$sth = $dbh->prepare("select lock_id,lock_trx_id,lock_mode,lock_type,lock_table,lock_index,lock_space,lock_page,lock_rec,lock_data from information_schema.INNODB_LOCKS");
629+
$sth->execute();
630+
while( my @result2 = $sth->fetchrow_array ) {
631+
$sth2->bind_param( 1, $result2[0], SQL_VARCHAR );
632+
$sth2->bind_param( 2, $result2[1], SQL_VARCHAR);
633+
$sth2->bind_param( 3, $result2[2], SQL_VARCHAR );
634+
$sth2->bind_param( 4, $result2[3], SQL_VARCHAR );
635+
$sth2->bind_param( 5, $result2[4], SQL_VARCHAR );
636+
637+
$sth2->bind_param( 6, $result2[5], SQL_VARCHAR );
638+
$sth2->bind_param( 7, $result2[6], SQL_INTEGER );
639+
$sth2->bind_param( 8, $result2[7], SQL_INTEGER );
640+
$sth2->bind_param( 9, $result2[8], SQL_INTEGER);
641+
$sth2->bind_param( 10,$result2[9], SQL_VARCHAR );
642+
$sth2->bind_param( 11, $snap_time, SQL_DATE );
643+
$sth2->execute();
644+
}
645+
646+
$sql2 = qq{ insert into myawr_innodb_lock_waits(snap_id,host_id,requesting_trx_id,requested_lock_id,blocking_trx_id,blocking_lock_id,snap_time) values ($snap_id,$tid,?,?,?,?,?)};
647+
$sth2 = $dbh_save->prepare( $sql2 );
648+
649+
$sth = $dbh->prepare("select requesting_trx_id,requested_lock_id,blocking_trx_id,blocking_lock_id from information_schema.INNODB_LOCK_WAITS");
650+
$sth->execute();
651+
while( my @result2 = $sth->fetchrow_array ) {
652+
$sth2->bind_param( 1, $result2[0], SQL_VARCHAR );
653+
$sth2->bind_param( 2, $result2[1], SQL_VARCHAR);
654+
$sth2->bind_param( 3, $result2[2], SQL_VARCHAR );
655+
$sth2->bind_param( 4, $result2[3], SQL_VARCHAR );
656+
$sth2->bind_param( 5, $snap_time, SQL_DATE );
657+
$sth2->execute();
658+
}
659+
660+
$sth2->finish;
661+
}
662+
663+
554664
$sql =
555665
qq{insert into myawr.myawr_mysql_info(snap_id,host_id,query_cache_size,thread_cache_size,table_definition_cache,max_connections,table_open_cache,slow_launch_time,max_heap_table_size,tmp_table_size,open_files_limit,Max_used_connections,Threads_connected,Threads_cached,Threads_created,Threads_running,Connections,Questions,Com_select,Com_insert,Com_update,Com_delete,Bytes_received,Bytes_sent,Qcache_hits,Qcache_inserts,Select_full_join,Select_scan,Slow_queries,Com_commit,Com_rollback,Open_files,Open_table_definitions,Open_tables,Opened_files,Opened_table_definitions,Opened_tables,Created_tmp_disk_tables,Created_tmp_files,Created_tmp_tables,Binlog_cache_disk_use,Binlog_cache_use,Aborted_clients,Sort_merge_passes,Sort_range,Sort_rows,Sort_scan,Table_locks_immediate,Table_locks_waited,Handler_read_first,Handler_read_key,Handler_read_last,Handler_read_next,Handler_read_prev,Handler_read_rnd,Handler_read_rnd_next,snap_time) values($snap_id,$tid,$vars->{"query_cache_size"},$vars->{"thread_cache_size"},$vars->{"table_definition_cache"},$vars->{"max_connections"},$vars->{"table_open_cache"},$vars->{"slow_launch_time"},$vars->{"max_heap_table_size"},$vars->{"tmp_table_size"},$vars->{"open_files_limit"},$mystat2->{"Max_used_connections"},$mystat2->{"Threads_connected"},$mystat2->{"Threads_cached"},$mystat2->{"Threads_created"},$mystat2->{"Threads_running"},$mystat2->{"Connections"},$mystat2->{"Questions"},$mystat2->{"Com_select"},$mystat2->{"Com_insert"},$mystat2->{"Com_update"},$mystat2->{"Com_delete"},$mystat2->{"Bytes_received"},$mystat2->{"Bytes_sent"},$mystat2->{"Qcache_hits"},$mystat2->{"Qcache_inserts"},$mystat2->{"Select_full_join"},$mystat2->{"Select_scan"},$mystat2->{"Slow_queries"},$mystat2->{"Com_commit"},$mystat2->{"Com_rollback"},$mystat2->{"Open_files"},$mystat2->{"Open_table_definitions"},$mystat2->{"Open_tables"},$mystat2->{"Opened_files"},$mystat2->{"Opened_table_definitions"},$mystat2->{"Opened_tables"},$mystat2->{"Created_tmp_disk_tables"},$mystat2->{"Created_tmp_files"},$mystat2->{"Created_tmp_tables"},$mystat2->{"Binlog_cache_disk_use"},$mystat2->{"Binlog_cache_use"},$mystat2->{"Aborted_clients"},$mystat2->{"Sort_merge_passes"},$mystat2->{"Sort_range"},$mystat2->{"Sort_rows"},$mystat2->{"Sort_scan"},$mystat2->{"Table_locks_immediate"},$mystat2->{"Table_locks_waited"},$mystat2->{"Handler_read_first"},$mystat2->{"Handler_read_key"},$mystat2->{"Handler_read_last"},$mystat2->{"Handler_read_next"},$mystat2->{"Handler_read_prev"},$mystat2->{"Handler_read_rnd"},$mystat2->{"Handler_read_rnd_next"}, \"$snap_time\")};
556666

0 commit comments

Comments
 (0)