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