~ubuntu-branches/ubuntu/trusty/nagios-plugins-contrib/trusty-proposed

« back to all changes in this revision

Viewing changes to check_mysql_health/check_mysql_health-2.1.8.2/contrib/CheckMySQLHealthExt1.pm

  • Committer: Package Import Robot
  • Author(s): Bernd Zeimetz
  • Date: 2013-05-21 22:11:50 UTC
  • mfrom: (5.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130521221150-k5bda5v5euvt7wg9
Tags: 6.20130521
* [e68c82e1] check_raid: do not run hpacucli if cciss_vol_status is available.
* [4a1c57e8] Also support tw-cli as additional name for the 3ware binary.
  Thanks to Dennis Hoppe
* [eb5e1c7c] Add /run/ to the check_libs ignore file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package MyQueue;
 
2
 
 
3
our @ISA = qw(DBD::MySQL::Server);
 
4
 
 
5
sub init {
 
6
  my $self = shift;
 
7
  my %params = @_;
 
8
  $self->{running} = 0;
 
9
  $self->{waiting} = 0;
 
10
  $self->{held} = 20;
 
11
  $self->{cancelled} = 0;
 
12
  $self->{length} = 100;
 
13
  if ($params{mode} =~ /my::queue::status/) {
 
14
    ($self->{running}, $self->{waiting}, $self->{held}, $self->{cancelled}) = 
 
15
        $self->{handle}->fetchrow_array(q{
 
16
          SELECT COUNT(*) FROM queues WHERE 
 
17
            status IN ('running', 'waiting', 'held', 'cancelled')
 
18
            GROUP BY status 
 
19
        });
 
20
  } elsif ($params{mode} =~ /my::queue::length/) {
 
21
    $self->{length} = $self->{handle}->fetchrow_array(q{
 
22
        SELECT COUNT(*) FROM queues
 
23
    });
 
24
  } elsif ($params{mode} =~ /my::queue::througput/) {
 
25
    $self->{processed_items} = $self->{handle}->fetchrow_array(q{
 
26
        SELECT processed FROM queue_status
 
27
    });
 
28
    $self->valdiff(\%params, qw(processed_items));
 
29
    # this automatically creates
 
30
    # $self->{delta_timestamp}
 
31
    #   the time in seconds since the last run of check_mysql_health
 
32
    # $self->{delta_processed_items}
 
33
    #   the difference between processed_items now and
 
34
    #   processed_items when check_mysql_health was run last time
 
35
    $self->{throughput} = $self->{delta_processed_items} / $self->{delta_timestamp};
 
36
  } else {
 
37
  }
 
38
}
 
39
 
 
40
sub nagios {
 
41
  my $self = shift;
 
42
  my %params = @_;
 
43
  if ($params{mode} =~ /my::queue::status/) {
 
44
    if ($self->{held} > 10 || $self->{cancelled} > 10) {
 
45
      $self->add_nagios_critical("more than 10 queues are held or cancelled");
 
46
    } elsif ($self->{waiting} > 20 && $self->{running} < 3) {
 
47
      $self->add_nagios_warning("more than 20 queues are waiting and less than 3 queues are running");
 
48
    } else {
 
49
      $self->add_nagios_ok("queues are running normal");
 
50
    }
 
51
    $self->add_perfdata(sprintf "held=%d cancelled=%d waiting=%d running=%d",
 
52
        $self->{running}, $self->{waiting}, $self->{held}, $self->{cancelled});
 
53
  } elsif ($params{mode} =~ /my::queue::length/) {
 
54
    $self->add_nagios(
 
55
        $self->check_thresholds($self->{length}, 100, 500),
 
56
        sprintf "queue length is %d", $self->{length});
 
57
    $self->add_perfdata(sprintf "queuelen=%d;%d;%d",
 
58
        $self->{length}, $self->{warningrange}, $self->{criticalrange});
 
59
  } elsif ($params{mode} =~ /my::queue::througput/) {
 
60
    $self->add_nagios(
 
61
        $self->check_thresholds($self->{throughput}, "50:", "10:"),
 
62
        sprintf "queue throughput is %d", $self->{throughput});
 
63
    $self->add_perfdata(sprintf "throughput=%.2f;%d;%d",
 
64
        $self->{throughput}, $self->{warningrange}, $self->{criticalrange});
 
65
  } else {
 
66
    $self->add_nagios_unknown("unknown mode");
 
67
  }
 
68
}