Debian Codegraph @

check_mysql_health/check_mysql_health-2.2.2/contrib/CheckMySQLHealthExt1.pm

raw
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 }