fix mysql longqueries

This commit is contained in:
garnier-quentin 2019-10-14 17:04:16 +02:00
parent 995f8a781b
commit 8cea2ae071
1 changed files with 30 additions and 20 deletions

View File

@ -30,14 +30,13 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
"seconds:s" => { name => 'seconds', default => 60 },
"filter-user:s" => { name => 'filter_user' },
"filter-command:s" => { name => 'filter_command', default => '^(?!(sleep)$)' },
});
$options{options}->add_options(arguments => {
'warning:s' => { name => 'warning', },
'critical:s' => { name => 'critical', },
'seconds:s' => { name => 'seconds', default => 60 },
'filter-user:s' => { name => 'filter_user' },
'filter-command:s' => { name => 'filter_command', default => '^(?!(sleep)$)' },
});
return $self;
}
@ -84,19 +83,30 @@ sub run {
my $exit_code = $self->{perfdata}->threshold_check(value => $long_queries, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit_code,
short_msg => sprintf("%s queries over %s seconds",
$long_queries, $self->{option_results}->{seconds}));
$self->{output}->perfdata_add(label => 'longqueries',
value => $long_queries,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0);
$self->{output}->output_add(
severity => $exit_code,
short_msg => sprintf(
"%s queries over %s seconds",
$long_queries, $self->{option_results}->{seconds}
)
);
$self->{output}->perfdata_add(
label => 'longqueries',
value => $long_queries,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0
);
for (my $i = 0; $i < 10 && $i < scalar(@queries); $i++) {
$queries[$i]->{query} =~ s/\|/-/mg;
$self->{output}->output_add(long_msg => sprintf("[time: %s] [query: %s]",
$queries[$i]->{time}, substr($queries[$i]->{query}, 0, 1024)));
$queries[$i]->{query} =~ s/\|/-/mg if (defined($queries[$i]->{query}));
$self->{output}->output_add(long_msg =>
sprintf(
"[time: %s] [query: %s]",
$queries[$i]->{time},
defined($queries[$i]->{query}) ? substr($queries[$i]->{query}, 0, 1024) : '-'
)
);
}
$self->{output}->display();