Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/centreon/plugins/values.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ sub new {
$self->{threshold_crit} = undef;

$self->{per_second} = 0;
$self->{per_minute} = 0;
$self->{manual_keys} = 0;
$self->{last_timestamp} = undef;

Expand Down Expand Up @@ -96,14 +97,15 @@ sub calc {

# manage only one value ;)
foreach my $value (@{$self->{key_values}}) {
if (defined($value->{diff}) && $value->{diff} == 1) {
$self->{result_values}->{$value->{name}} = $options{new_datas}->{$self->{instance} . '_' . $value->{name}} - $options{old_datas}->{$self->{instance} . '_' . $value->{name}};
} elsif (defined($value->{per_second}) && $value->{per_second} == 1) {
$self->{result_values}->{$value->{name}} = ($options{new_datas}->{$self->{instance} . '_' . $value->{name}} - $options{old_datas}->{$self->{instance} . '_' . $value->{name}}) / $options{delta_time};
} elsif (defined($value->{per_minute}) && $value->{per_minute} == 1) {
$self->{result_values}->{$value->{name}} = ($options{new_datas}->{$self->{instance} . '_' . $value->{name}} - $options{old_datas}->{$self->{instance} . '_' . $value->{name}}) / ($options{delta_time} / 60);
my $instance_name = $self->{instance} . '_' . $value->{name};
if ($value->{diff}) {
$self->{result_values}->{$value->{name}} = $options{new_datas}->{$instance_name} - $options{old_datas}->{$instance_name};
} elsif ($value->{per_second}) {
$self->{result_values}->{$value->{name}} = ($options{new_datas}->{$instance_name} - $options{old_datas}->{$instance_name}) / $options{delta_time};
} elsif ($value->{per_minute}) {
$self->{result_values}->{$value->{name}} = ($options{new_datas}->{$instance_name} - $options{old_datas}->{$instance_name}) / ($options{delta_time} / 60);
} else {
$self->{result_values}->{$value->{name}} = $options{new_datas}->{$self->{instance} . '_' . $value->{name}};
$self->{result_values}->{$value->{name}} = $options{new_datas}->{$instance_name};
}
}

Expand Down
91 changes: 71 additions & 20 deletions src/database/mssql/mode/deadlocks.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2024 Centreon (http://www.centreon.com/)
# Copyright 2026-Present Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
Expand All @@ -23,34 +23,58 @@ package database::mssql::mode::deadlocks;
use strict;
use warnings;
use base qw(centreon::plugins::templates::counter);
use centreon::plugins::constants qw(:counters);
use centreon::plugins::misc qw(is_excluded);
use Digest::SHA qw(sha256_hex);

sub prefix_by_instance_output {
my ($self, %options) = @_;

return "instance '" . $options{instance_value}->{display} . "' ";
}

sub set_counters {
my ($self, %options) = @_;

$self->{maps_counters_type} = [
{ name => 'deadlocks', type => 0 },
{ name => 'total', type => COUNTER_TYPE_GLOBAL },
{ name => 'by_instance', type => COUNTER_TYPE_INSTANCE}
];

$self->{maps_counters}->{deadlocks} = [
{ label => 'deadlocks', nlabel => 'mssql.deadlocks.count', set => {
key_values => [ { name => 'value' } ],
output_template => '%.2f dead locks/s',
$self->{maps_counters}->{total} = [
{ label => 'deadlocks', type => COUNTER_KIND_METRIC, nlabel => 'total#mssql.deadlocks.perminute', set => {
key_values => [ { name => 'total', per_minute => 1 } ],
output_template => '%.2f total dead locks/min',
perfdatas => [
{ template => '%.2f', min => 0 },
],
}
},
];
}

$self->{maps_counters}->{by_instance} = [
{
label => 'deadlocks-by-instance', type => COUNTER_KIND_METRIC, nlabel => 'mssql.deadlocks.perminute',
set => {
key_values => [ { name => 'value', per_minute => 1 }, { name => 'display' } ],
output_template => '%.2f dead locks/min',
perfdatas => [
{ template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'display' },
],
}
},
];
}

sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;

$options{options}->add_options(arguments => {
"filter-database:s" => { name => 'filter_database' },
$options{options}->add_options(arguments => {
"filter-database:s" => { redirect => 'include_instance' },
"include-instance:s" => { name => 'include_instance', default => '' },
"exclude-instance:s" => { name => 'exclude_instance', default => '' },
});

return $self;
Expand All @@ -72,13 +96,24 @@ sub manage_selection {
});

my $query_result = $options{sql}->fetchall_arrayref();
$self->{deadlocks}->{value} = 0;
$self->{total}->{total} = 0;

foreach my $row (@{$query_result}) {
next if (defined($self->{option_results}->{filter_database}) && $self->{option_results}->{filter_database} ne ''
&& $$row[0] !~ /$self->{option_results}->{filter_database}/);
$self->{deadlocks}->{value} += $$row[1];
my ($instance, $value) = @$row;
next if $instance eq '_Total';
next if is_excluded($instance, $self->{option_results}->{include_instance}, $self->{option_results}->{exclude_instance}, output => $self->{output});
$self->{by_instance}->{$instance} = {
display => $instance,
value => $value
};
$self->{total}->{total} += $value;
}
$self->{output}->option_exit(short_msg => "No locks counter found with given filters")
unless $self->{by_instance} && keys %{$self->{by_instance}};

$self->{cache_name} = 'mssql_' . $self->{mode} . '_' . $options{sql}->get_unique_id4save() . '_' .
sha256_hex($self->{option_results}->{include_instance}) . '_' .
sha256_hex($self->{option_results}->{exclude_instance});
}

1;
Expand All @@ -87,21 +122,37 @@ __END__

=head1 MODE

Check MSSQL dead locks per second
Check MSSQL dead locks per minute

=over 8

=item B<--warning-deadlocks>
=item B<--include-instance>

Warning threshold number of dead locks per second.
Filter to include instances (types of locks) to monitor with a regular expression.

=item B<--critical-deadlocks>
=item B<--exclude-instance>

Critical threshold number of dead locks per second.
Filter to exclude instances (types of locks) to monitor with a regular expression.

=item B<--filter-database>

Filter the databases to monitor with a regular expression.
Deprecated option: use C<--include-instance> instead.

=item B<--warning-deadlocks-by-instance>

Threshold that applies to each type (instance) of deadlock individually.

=item B<--critical-deadlocks-by-instance>

Threshold that applies to each type (instance) of deadlock individually.

=item B<--warning-deadlocks>

Threshold that applies to the total amount of deadlocks once the filters have been applied.

=item B<--critical-deadlocks>

Threshold that applies to the total amount of deadlocks once the filters have been applied.

=back

Expand Down
98 changes: 76 additions & 22 deletions src/database/mssql/mode/lockswaits.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2025 Centreon (http://www.centreon.com/)
# Copyright 2026-Present Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
Expand All @@ -23,34 +23,60 @@ package database::mssql::mode::lockswaits;
use strict;
use warnings;
use base qw(centreon::plugins::templates::counter);
use centreon::plugins::constants qw(:counters);
use centreon::plugins::misc qw(is_excluded);
use Digest::SHA qw(sha256_hex);

sub prefix_by_instance_output {
my ($self, %options) = @_;

return "instance '" . $options{instance_value}->{display} . "' ";
}

sub set_counters {
my ($self, %options) = @_;

$self->{maps_counters_type} = [
{ name => 'lockswaits', type => 0 }
{ name => 'total', type => COUNTER_TYPE_GLOBAL },
{ name => 'by_instance', type => COUNTER_TYPE_INSTANCE}
];

$self->{maps_counters}->{lockswaits} = [
{ label => 'lockswaits', nlabel => 'mssql.lockswaits.count', set => {
key_values => [ { name => 'value' } ],
output_template => '%.2f locks waits/s',
perfdatas => [
{ template => '%.2f', min => 0 }
]
$self->{maps_counters}->{total} = [
{
label => 'lockswaits', type => COUNTER_KIND_METRIC, nlabel => 'total#mssql.lockswaits.perminute',
set => {
key_values => [ { name => 'total', per_minute => 1 } ],
output_template => '%.2f total locks waits/min',
perfdatas => [
{ template => '%.2f', min => 0 },
],
}
}
},
];
}

$self->{maps_counters}->{by_instance} = [
{
label => 'lockswaits-by-instance', type => COUNTER_KIND_METRIC, nlabel => 'mssql.lockswaits.perminute',
set => {
key_values => [ { name => 'value', per_minute => 1 }, { name => 'display' } ],
output_template => '%.2f locks waits/min',
perfdatas => [
{ template => '%.2f', min => 0, label_extra_instance => 1, instance_use => 'display' },
],
}
},
];
}

sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;

$options{options}->add_options(arguments => {
'filter-database:s' => { name => 'filter_database' }
"filter-database:s" => { redirect => 'include_instance' },
"include-instance:s" => { name => 'include_instance', default => '' },
"exclude-instance:s" => { name => 'exclude_instance', default => '' },
});

return $self;
Expand All @@ -72,13 +98,25 @@ sub manage_selection {
});

my $query_result = $options{sql}->fetchall_arrayref();
$self->{lockswaits}->{value} = 0;
$self->{total}->{total} = 0;

foreach my $row (@{$query_result}) {
next if (defined($self->{option_results}->{filter_database}) && $self->{option_results}->{filter_database} ne ''
&& $$row[0] !~ /$self->{option_results}->{filter_database}/);
$self->{lockswaits}->{value} += $$row[1];
my ($instance, $value) = @$row;
next if $instance eq '_Total';
next if is_excluded($instance, $self->{option_results}->{include_instance}, $self->{option_results}->{exclude_instance}, output => $self->{output});
$self->{by_instance}->{$instance} = {
display => $instance,
value => $value
};
$self->{total}->{total} += $value;
}

$self->{output}->option_exit(short_msg => "No locks waits counter found with given filters")
unless $self->{by_instance} && keys %{$self->{by_instance}};

$self->{cache_name} = 'mssql_' . $self->{mode} . '_' . $options{sql}->get_unique_id4save() . '_' .
sha256_hex($self->{option_results}->{include_instance}) . '_' .
sha256_hex($self->{option_results}->{exclude_instance});
}

1;
Expand All @@ -87,21 +125,37 @@ __END__

=head1 MODE

Check MSSQL locks-waits per second
Check MSSQL locks-waits per minute

=over 8

=item B<--include-instance>

Filter to include instances (types of locks) to monitor with a regular expression.

=item B<--exclude-instance>

Filter to exclude instances (types of locks) to monitor with a regular expression.

=item B<--filter-database>

Deprecated option: use C<--include-instance> instead.

=item B<--warning-lockswaits>

Warning threshold number of lock-waits per second.
Threshold.

=item B<--critical-lockswaits>

Critical threshold number of lock-waits per second.
Threshold.

=item B<--filter-database>
=item B<--warning-lockswaits-by-instance>

Threshold.

=item B<--critical-lockswaits-by-instance>

Filter the databases to monitor with a regular expression.
Threshold.

=back

Expand Down
24 changes: 24 additions & 0 deletions tests/database/mssql/DBD/Sybase.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2026-Present Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package DBD::Sybase;
use strict;
use warnings;
1;


Loading
Loading