Chinaunix首页 | 论坛 | 博客
  • 博客访问: 204484
  • 博文数量: 75
  • 博客积分: 2049
  • 博客等级: 大尉
  • 技术积分: 780
  • 用 户 组: 普通用户
  • 注册时间: 2009-04-08 12:37
文章分类

全部博文(75)

文章存档

2011年(1)

2010年(9)

2009年(65)

我的朋友

分类: LINUX

2009-04-24 14:24:25


#!/usr/bin/perl

#####################################################################


#


require 5.004;

sub usage;

my $TIMEOUT = 15;
my $MYSQL = "mysql";

my %ERRORS = ('UNKNOWN' , '-1',
              'OK' , '0',
              'WARNING', '1',
              'CRITICAL', '2');

my $host = shift || &usage(%ERRORS);
my $user = shift || &usage(%ERRORS);
my $pass = shift || "";
my $TABLE = shift || "mysql";
my $warn = shift || 20;
my $crit = shift || 30;

my $state = "OK";
my $count = 0;
my $status = "";

# Just in case of problems, let's not hang Nagios

$SIG{'ALRM'} = sub {
     print ("ERROR: No response from MySQL server (alarm)\n");
     exit $ERRORS{"UNKNOWN"};
};
alarm($TIMEOUT);

open (OUTPUT, "$MYSQL -h $host -u $user --password=\"$pass\" $TABLE -e 'show tables;' | wc -l 2>&1 |");

while (<OUTPUT>) {
  if (/failed/) { $state="CRITICAL"; s/.*://; last; }
  chomp;
  $count = $_ - 1;
}

if ($count >= $warn) { $state = "WARNING"; }
if ($count >= $crit) { $state = "CRITICAL"; }

$status = "Tables $state - $count Tables\n";

print $status;
exit $ERRORS{$state};

sub usage {
   print "Required arguments not given!\n\n";
   print "MySQL table count plugin for Nagios, V1.01\n";
   print "Copyright (c) 2005 Brian Zammit \n\n";
   print "Usage: check_mysql.pl [

[ []]]\n\n";
   print " = password to use for at \n";
   print "
= table to use\n";
   print " = number of threads to warn us about\n";
   print " = number of threads to scream at us about\n";
   exit $ERRORS{"UNKNOWN"};
}

阅读(1044) | 评论(0) | 转发(0) |
0

上一篇:check_mysql_stats

下一篇:mysql完全备份

给主人留下些什么吧!~~