diff --git a/apps/centreon/local/mode/bamservice.pm b/apps/centreon/local/mode/bamservice.pm index 8eb982913..d7fd3fce2 100644 --- a/apps/centreon/local/mode/bamservice.pm +++ b/apps/centreon/local/mode/bamservice.pm @@ -84,7 +84,7 @@ sub run { value => $current_level, warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, max => 0, + min => 0, max => 100, ); $self->{output}->display(); diff --git a/database/mysql/mode/threadsconnected.pm b/database/mysql/mode/threadsconnected.pm index b5c544055..0f955678b 100644 --- a/database/mysql/mode/threadsconnected.pm +++ b/database/mysql/mode/threadsconnected.pm @@ -20,69 +20,95 @@ package database::mysql::mode::threadsconnected; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub custom_usage_output { + my ($self, %options) = @_; + + my $msg = sprintf("Client Connection Threads Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $self->{result_values}->{total_absolute}, + $self->{result_values}->{used_absolute}, + $self->{result_values}->{prct_used_absolute}, + $self->{result_values}->{free_absolute}, + $self->{result_values}->{prct_free_absolute}); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'usage', nlabel => 'threads.connected.count', set => { + key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { label => 'threads_connected', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute' }, + ], + } + }, + { label => 'usage-prct', display_ok => 0, nlabel => 'threads.connected.percentage', set => { + key_values => [ { name => 'prct_used' } ], + output_template => 'Client Connection Threads Used : %.2f %%', + perfdatas => [ + { label => 'threads_connected_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, + unit => '%' }, + ], + } + }, + ]; +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); + $options{options}->add_options(arguments => { + }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } -} - -sub run { +sub manage_selection { my ($self, %options) = @_; $options{sql}->connect(); - if (!($options{sql}->is_version_minimum(version => '5'))) { $self->{output}->add_option_msg(short_msg => "MySQL version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.x')."); $self->{output}->option_exit(); } - $options{sql}->query(query => q{SHOW /*!50000 global */ STATUS LIKE 'Threads_connected'}); - my ($name, $value) = $options{sql}->fetchrow_array(); - if (!defined($value)) { + $options{sql}->query(query => q{ + SELECT 'max_connections' as name, @@GLOBAL.max_connections as value + UNION + SELECT VARIABLE_NAME as name, VARIABLE_VALUE as value fROM information_schema.GLOBAL_STATUS WHERE VARIABLE_NAME = 'Threads_connected' + }); + my $infos = {}; + while (my ($name, $value) = $options{sql}->fetchrow_array()) { + $infos->{lc($name)} = $value; + } + + if (scalar(keys %$infos) == 0) { $self->{output}->add_option_msg(short_msg => "Cannot get number of open connections."); $self->{output}->option_exit(); } - - my $exit_code = $self->{perfdata}->threshold_check(value => $value, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("%d client connection threads", $value) - ); - $self->{output}->perfdata_add(label => 'threads_connected', - value => $value, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); - $self->{output}->display(); - $self->{output}->exit(); + my $prct_used = $infos->{threads_connected} * 100 / $infos->{max_connections}; + $self->{global} = { + total => $infos->{max_connections}, + used => $infos->{threads_connected}, + free => $infos->{max_connections} - $infos->{threads_connected}, + prct_used => $prct_used, + prct_free => 100 - $prct_used, + }; } 1; diff --git a/snmp_standard/mode/memory.pm b/snmp_standard/mode/memory.pm index 78849fb02..b059566d4 100644 --- a/snmp_standard/mode/memory.pm +++ b/snmp_standard/mode/memory.pm @@ -80,7 +80,7 @@ sub set_counters { key_values => [ { name => 'prct_used' } ], output_template => 'Used : %.2f %%', perfdatas => [ - { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 0, + { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, ], } @@ -139,7 +139,7 @@ sub set_counters { key_values => [ { name => 'prct_used' } ], output_template => 'Used : %.2f %%', perfdatas => [ - { label => 'swap_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 0, + { label => 'swap_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, ], } diff --git a/snmp_standard/mode/swap.pm b/snmp_standard/mode/swap.pm index d2a2e59cd..fe0f5bd53 100644 --- a/snmp_standard/mode/swap.pm +++ b/snmp_standard/mode/swap.pm @@ -67,7 +67,7 @@ sub set_counters { key_values => [ { name => 'prct_used' } ], output_template => 'Used : %.2f %%', perfdatas => [ - { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 0, + { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, ], } diff --git a/storage/hp/3par/ssh/mode/diskusage.pm b/storage/hp/3par/ssh/mode/diskusage.pm index 731f9ab99..d012d64fd 100644 --- a/storage/hp/3par/ssh/mode/diskusage.pm +++ b/storage/hp/3par/ssh/mode/diskusage.pm @@ -84,7 +84,7 @@ sub set_counters { key_values => [ { name => 'prct_used' }, { name => 'display' } ], output_template => 'Used : %.2f %%', perfdatas => [ - { label => 'used_prct', value => 'prct_used_absolute', template => '%d', min => 0, max => 0, + { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, ], } diff --git a/storage/hp/3par/ssh/mode/volumeusage.pm b/storage/hp/3par/ssh/mode/volumeusage.pm index 18bbcf013..a98c28c42 100644 --- a/storage/hp/3par/ssh/mode/volumeusage.pm +++ b/storage/hp/3par/ssh/mode/volumeusage.pm @@ -68,7 +68,7 @@ sub set_counters { key_values => [ { name => 'prct_used' }, { name => 'display' } ], output_template => 'Used : %.2f %%', perfdatas => [ - { label => 'used_prct', value => 'prct_used_absolute', template => '%d', min => 0, max => 0, + { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, ], }