use DBI;
use Net::SMTP;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
# mail_user should be your_mail@163.com
sub send_mail{
if (@_ != 2){print "please input message and mailto";exit 1};
my $message= shift;
my $CurrTime = time2iso(time());
my $to_address = shift;
my $mail_user = 'yjzhao@podinns.com';
my $mail_pwd = 'xx';
my $mail_server = 'smtp.exmail.qq.com';
my $from = "From: $mail_user\n";
my $subject = "Subject: zjcap info\n";
my $info = "$message";
my $message = <<CONTENT;
$info
CONTENT
my $smtp = Net::SMTP->new($mail_server); $smtp->auth($mail_user, $mail_pwd) || die "Auth Error! $!";
$smtp->mail($mail_user);
$smtp->to($to_address); $smtp->data(); # begin the data
$smtp->datasend($from); # set user
$smtp->datasend($subject); # set subject
$smtp->datasend("\n\n");
$smtp->datasend("$message\n"); # set content
$smtp->dataend();
$smtp->quit();
};
if ( $#ARGV != 1 ){
print "input your root password and ip address"."\n";
exit(-1);
};
my $message='information_schema';
my $ip="$ARGV[1]";
my $user="root";
my $passwd="$ARGV[0]";
my $dbh = DBI->connect("dbi:mysql:database=$message;host=$ip;port=3306",$user,$passwd) or die "can't connect to database ". DBI-errstr;
@arr2=();
##防止utf-8中文乱码
$dbh->do("SET NAMES utf8");
my $hostSql = qq{SELECT
NOW(), (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(a.trx_started)) diff_sec,
b.id,
b.user,
b.host,
b.db
FROM
information_schema.innodb_trx a
INNER JOIN
information_schema.PROCESSLIST b ON a.TRX_MYSQL_THREAD_ID = b.id};
my ($a1, $a2, $a3,$a4,$a5,$a6,$a7,$a8,$a9);
my $selStmt = $dbh->prepare($hostSql);
$selStmt->execute();
$selStmt->bind_columns(undef, \$a1, \$a2, \$a3,\$a4,\$a5,\$a6);
print "$a1,$a2,$a3,$a4,$a5,$a6\n";
while( $selStmt->fetch() )
{
if ($a2 >= 20){
print "$a1,$a2,$a3,$a4,$a5,$a6\n";
print " mysq\[$ip\] processid\[$a3\] $a4\@$a5 in db\[$a6\] hold transaction time $a2 "."\n";
send_mail(" mysq\[$ip\] processid\[$a3\] $a4\@$a5 in db\[$a6\] hold transaction time $a2 ",'yjzhao@podinns.com');
};
};
my $hostSql = qq{SELECT
r.trx_id waiting_trx_id,
r.trx_mysql_thread_id waiting_thread,
r.trx_query waiting_query,
b.trx_id blocking_trx_id,
b.trx_mysql_thread_id blocking_thread,
b.trx_query blocking_query
FROM
information_schema.innodb_lock_waits w
INNER JOIN
information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id
INNER JOIN
information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id};
my ($a1, $a2, $a3,$a4,$a5,$a6,$a7,$a8,$a9);
my $selStmt = $dbh->prepare($hostSql);
$selStmt->execute();
$selStmt->bind_columns(undef, \$a1, \$a2, \$a3,\$a4,\$a5,\$a6);
while( $selStmt->fetch() )
{
if ($a1&&$a2&&$a3&&$a4&&$a5){
print "$a1,$a2,$a3,$a4,$a5,$a6\n";
print " blocking_thread\[$5\] blocking waiting_thread\[$a2\]'s $a3"."\n";
send_mail(" blocking_thread\[$a5\] blocking waiting_thread\[$a2\]'s $a3" ,'yjzhao@podinns.com');
};
};

最新文章

  1. win7 去快捷箭头
  2. 不谈业务运维的IT主管早晚被淘汰 这里是10条干货
  3. JavaWeb前端基础复习笔记系列 二
  4. 6/14 Sprint2 看板和燃尽图
  5. 总结 output 用法
  6. nginx error_page 404 用 php header 无法跳转
  7. c#泛型方法重载
  8. 【微信公众号】将微信公众号消息里的FromUserName即OpenID转成UnionID
  9. leetcode_最长公共前缀
  10. vs2010中iostream.h出错
  11. tf.train.ExponentialMovingAverage
  12. strlen出错
  13. 高可用之KeepAlived(2):keepalived+lvs
  14. 渗透测试环境DVWA搭建
  15. EF Core 相关的千倍性能之差: AutoMapper ProjectTo VS Mapster ProjectToType
  16. Sketch 和 PS中的设计图如何实现“自动切图”?
  17. Docker 图形化页面管理工具使用
  18. Android开发-新建线程崩溃
  19. OpenStack之日志
  20. msyql int(x) 中的x

热门文章

  1. StyleCop 安装
  2. LSJ_NHibernate第二章 ManagerPage
  3. Java线程间通信-回调的实现方式
  4. iOS app提交审核 11.13条款问题
  5. struts2标签学习笔记(一)
  6. 注释玩转webapi
  7. 一些简单的帮助类(1)-- String的类型验证
  8. 九度OJ 1131 合唱队形 -- 动态规划(最长递增子序列)
  9. 排序算法——QuickSort、MergeSort、HeapSort(C++实现)
  10. MyBatis 拦截器 (实现分页功能)