From eb370da61aa959c8a52aaaae2c65826fff82fd42 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 30 Oct 2015 17:12:33 +0100 Subject: [PATCH] + Fix #1 Add option to handle timeshift and sampling period Also manage some errors on counters --- .../vmware/src/centreon/vmware/cmdcpuhost.pm | 15 +-- .../vmware/src/centreon/vmware/cmdcpuvm.pm | 18 +++- .../src/centreon/vmware/cmddatastorehost.pm | 5 +- .../src/centreon/vmware/cmddatastoreio.pm | 5 +- .../src/centreon/vmware/cmddatastoreiops.pm | 7 +- .../src/centreon/vmware/cmddatastorevm.pm | 15 ++- .../vmware/src/centreon/vmware/cmdmemhost.pm | 5 +- .../vmware/src/centreon/vmware/cmdmemvm.pm | 11 ++- .../vmware/src/centreon/vmware/cmdnethost.pm | 5 +- .../vmware/src/centreon/vmware/cmdswaphost.pm | 9 +- .../vmware/src/centreon/vmware/cmdswapvm.pm | 5 +- .../centreon/vmware/cmdvmoperationcluster.pm | 3 +- .../vmware/src/centreon/vmware/common.pm | 93 ++++++++++++++----- 13 files changed, 138 insertions(+), 58 deletions(-) diff --git a/connectors/vmware/src/centreon/vmware/cmdcpuhost.pm b/connectors/vmware/src/centreon/vmware/cmdcpuhost.pm index d9a69fe79..36d760436 100644 --- a/connectors/vmware/src/centreon/vmware/cmdcpuhost.pm +++ b/connectors/vmware/src/centreon/vmware/cmdcpuhost.pm @@ -113,10 +113,13 @@ sub run { $result, [{'label' => 'cpu.usage.average', 'instances' => \@instances}, {'label' => 'cpu.usagemhz.average', 'instances' => \@instances}], - $self->{connector}->{perfcounter_speriod}, + $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}, skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1); return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1); + my $interval_min = centreon::vmware::common::get_interval_min(speriod => $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}); if ($multiple == 1) { $self->{manager}->{output}->output_add(severity => 'OK', short_msg => sprintf("All Total Average CPU usages are ok")); @@ -128,19 +131,19 @@ sub run { status => $self->{disconnect_status}, multiple => $multiple) == 0); my $entity_value = $entity_view->{mo_ref}->{value}; - my $total_cpu_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usage.average'}->{'key'} . ":"}[0] * 0.01)); - my $total_cpu_mhz_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{'key'} . ":"}[0])); + my $total_cpu_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usage.average'}->{'key'} . ":"} * 0.01)); + my $total_cpu_mhz_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{'key'} . ":"})); my $exit = $self->{manager}->{perfdata}->threshold_check(value => $total_cpu_average, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{manager}->{output}->output_add(long_msg => sprintf("'%s' Total Average CPU usage '%s%%' on last %s min", - $entity_view->{name}, $total_cpu_average, int($self->{connector}->{perfcounter_speriod} / 60))); + $entity_view->{name}, $total_cpu_average, $interval_min)); if ($multiple == 0 || !$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{manager}->{output}->output_add(severity => $exit, short_msg => sprintf("'%s' Total Average CPU usage '%s%%' on last %s min", - $entity_view->{name}, $total_cpu_average, int($self->{connector}->{perfcounter_speriod} / 60))); + $entity_view->{name}, $total_cpu_average, $interval_min)); } my $extra_label = ''; @@ -162,7 +165,7 @@ sub run { my ($counter_id, $instance) = split /:/, $id; if ($instance ne "") { $self->{manager}->{output}->perfdata_add(label => 'cpu' . $instance . $extra_label, unit => '%', - value => centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$id}[0]) * 0.01), + value => centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$id}) * 0.01), min => 0, max => 100); } } diff --git a/connectors/vmware/src/centreon/vmware/cmdcpuvm.pm b/connectors/vmware/src/centreon/vmware/cmdcpuvm.pm index c9ae45354..21828e001 100644 --- a/connectors/vmware/src/centreon/vmware/cmdcpuvm.pm +++ b/connectors/vmware/src/centreon/vmware/cmdcpuvm.pm @@ -122,6 +122,7 @@ sub run { {'label' => 'cpu.usagemhz.average', 'instances' => \@instances}, {'label' => 'cpu.ready.summation', 'instances' => \@instances}], $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}, skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1); return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1); @@ -132,6 +133,13 @@ sub run { $self->{manager}->{output}->output_add(severity => 'OK', short_msg => sprintf("All cpu usages are ok")); } + + my $interval_sec = $self->{connector}->{perfcounter_speriod}; + if (defined($self->{sampling_period}) && $self->{sampling_period} ne '') { + $interval_sec = $self->{sampling_period}; + } + my $interval_min = centreon::vmware::common::get_interval_min(speriod => $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}); foreach my $entity_view (@$result) { next if (centreon::vmware::common::vm_state(connector => $self->{connector}, hostname => $entity_view->{name}, @@ -141,9 +149,9 @@ sub run { powerstatus => $self->{nopoweredon_status}, multiple => $multiple) == 0); my $entity_value = $entity_view->{mo_ref}->{value}; - my $total_cpu_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usage.average'}->{'key'} . ":"}[0] * 0.01)); - my $total_cpu_mhz_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{'key'} . ":"}[0])); - my $total_cpu_ready = centreon::vmware::common::simplify_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.ready.summation'}->{'key'} . ":"}[0] / ($self->{connector}->{perfcounter_speriod} * 1000) * 100); + my $total_cpu_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usage.average'}->{'key'} . ":"} * 0.01)); + my $total_cpu_mhz_average = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{'key'} . ":"})); + my $total_cpu_ready = centreon::vmware::common::simplify_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'cpu.ready.summation'}->{'key'} . ":"} / ($interval_sec * 1000) * 100); my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); my @exits; @@ -173,7 +181,7 @@ sub run { min => $entry->{perf_min}, max => $entry->{perf_max}); } - $long_msg .= ' on last ' . int($self->{connector}->{perfcounter_speriod} / 60) . ' min'; + $long_msg .= ' on last ' . $interval_min . ' min'; my $prefix_msg = "'$entity_view->{name}'"; if (defined($self->{display_description}) && defined($entity_view->{'config.annotation'}) && $entity_view->{'config.annotation'} ne '') { @@ -200,7 +208,7 @@ sub run { next if ($self->{connector}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{key} != $counter_id); if ($instance ne "") { $self->{manager}->{output}->perfdata_add(label => 'cpu_' . $instance . '_MHz' . $extra_label, unit => 'MHz', - value => centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$id}[0])), + value => centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$id})), min => 0); } } diff --git a/connectors/vmware/src/centreon/vmware/cmddatastorehost.pm b/connectors/vmware/src/centreon/vmware/cmddatastorehost.pm index a1520573f..11c298d50 100644 --- a/connectors/vmware/src/centreon/vmware/cmddatastorehost.pm +++ b/connectors/vmware/src/centreon/vmware/cmddatastorehost.pm @@ -174,6 +174,7 @@ sub run { undef, $query_perfs, $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}, skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1); return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1); @@ -189,8 +190,8 @@ sub run { next if (defined($checked->{$uuid})); $checked->{$uuid} = 1; - my $read_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'datastore.totalReadLatency.average'}->{'key'} . ":" . $uuid}[0])); - my $write_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'datastore.totalWriteLatency.average'}->{'key'} . ":" . $uuid}[0])); + my $read_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'datastore.totalReadLatency.average'}->{'key'} . ":" . $uuid})); + my $write_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'datastore.totalWriteLatency.average'}->{'key'} . ":" . $uuid})); my $exit = $self->{manager}->{perfdata}->threshold_check(value => $read_counter, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{manager}->{output}->output_add(long_msg => sprintf("'%s' read on '%s' is %s ms", diff --git a/connectors/vmware/src/centreon/vmware/cmddatastoreio.pm b/connectors/vmware/src/centreon/vmware/cmddatastoreio.pm index 1a9c6d00f..66108d125 100644 --- a/connectors/vmware/src/centreon/vmware/cmddatastoreio.pm +++ b/connectors/vmware/src/centreon/vmware/cmddatastoreio.pm @@ -107,6 +107,7 @@ sub run { [{'label' => 'datastore.read.average', 'instances' => ['']}, {'label' => 'datastore.write.average', 'instances' => ['']}], $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}, skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1); return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1); @@ -127,8 +128,8 @@ sub run { my $entity_value = $entity_view->{mo_ref}->{value}; # in KBps - my $read_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'datastore.read.average'}->{'key'} . ":"}[0])) * 1024; - my $write_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'datastore.write.average'}->{'key'} . ":"}[0])) * 1024; + my $read_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'datastore.read.average'}->{'key'} . ":"})) * 1024; + my $write_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'datastore.write.average'}->{'key'} . ":"})) * 1024; my $exit1 = $self->{manager}->{perfdata}->threshold_check(value => $read_counter, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my $exit2 = $self->{manager}->{perfdata}->threshold_check(value => $write_counter, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); diff --git a/connectors/vmware/src/centreon/vmware/cmddatastoreiops.pm b/connectors/vmware/src/centreon/vmware/cmddatastoreiops.pm index d88efd646..5839e28c0 100644 --- a/connectors/vmware/src/centreon/vmware/cmddatastoreiops.pm +++ b/connectors/vmware/src/centreon/vmware/cmddatastoreiops.pm @@ -188,17 +188,22 @@ sub run { [{'label' => 'disk.numberRead.summation', 'instances' => ['*']}, {'label' => 'disk.numberWrite.summation', 'instances' => ['*']}], $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}, skip_undef_counter => 1, multiples => 1); return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1); + my $interval_sec = $self->{connector}->{perfcounter_speriod}; + if (defined($self->{sampling_period}) && $self->{sampling_period} ne '') { + $interval_sec = $self->{sampling_period}; + } foreach (keys %$values) { my ($vm_id, $id, $disk_name) = split(/:/); # RDM Disk. We skip. Don't know how to manage it right now. next if (!defined($disk_name{$disk_name})); - my $tmp_value = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$_}[0] / $self->{connector}->{perfcounter_speriod})); + my $tmp_value = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$_} / $interval_sec)); $datastore_lun{$disk_name{$disk_name}}{$self->{connector}->{perfcounter_cache_reverse}->{$id}} += $tmp_value; if (!defined($datastore_lun{$disk_name{$disk_name}}{$vm_id . '_' . $self->{connector}->{perfcounter_cache_reverse}->{$id}})) { $datastore_lun{$disk_name{$disk_name}}{$vm_id . '_' . $self->{connector}->{perfcounter_cache_reverse}->{$id}} = $tmp_value; diff --git a/connectors/vmware/src/centreon/vmware/cmddatastorevm.pm b/connectors/vmware/src/centreon/vmware/cmddatastorevm.pm index 093e27ae1..280b03182 100644 --- a/connectors/vmware/src/centreon/vmware/cmddatastorevm.pm +++ b/connectors/vmware/src/centreon/vmware/cmddatastorevm.pm @@ -180,9 +180,14 @@ sub run { [{'label' => 'disk.numberRead.summation', 'instances' => ['*']}, {'label' => 'disk.numberWrite.summation', 'instances' => ['*']}], $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}, skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1); return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1); + my $interval_sec = $self->{connector}->{perfcounter_speriod}; + if (defined($self->{sampling_period}) && $self->{sampling_period} ne '') { + $interval_sec = $self->{sampling_period}; + } $self->{manager}->{output}->output_add(severity => 'OK', short_msg => sprintf("All Datastore IOPS counters are ok")); my $finded = 0; @@ -207,15 +212,15 @@ sub run { next if ($disk_name{$disk_name} !~ /$ds_regexp/); $datastore_lun{$disk_name{$disk_name}} = { 'disk.numberRead.summation' => 0, 'disk.numberWrite.summation' => 0 } if (!defined($datastore_lun{$disk_name{$disk_name}})); - $datastore_lun{$disk_name{$disk_name}}->{$self->{connector}->{perfcounter_cache_reverse}->{$id}} += $values->{$entity_value}->{$_}[0]; + $datastore_lun{$disk_name{$disk_name}}->{$self->{connector}->{perfcounter_cache_reverse}->{$id}} += $values->{$entity_value}->{$_}; } foreach (sort keys %datastore_lun) { $finded |= 2; - my $read_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($datastore_lun{$_}{'disk.numberRead.summation'} / $self->{connector}->{perfcounter_speriod})); - my $write_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($datastore_lun{$_}{'disk.numberWrite.summation'} / $self->{connector}->{perfcounter_speriod})); + my $read_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($datastore_lun{$_}{'disk.numberRead.summation'} / $interval_sec)); + my $write_counter = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($datastore_lun{$_}{'disk.numberWrite.summation'} / $interval_sec)); - my $exit = $self->{manager}->{perfdata}->threshold_check(value => $read_counter, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit = $self->{manager}->{perfdata}->threshold_check(value => $read_counter, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{manager}->{output}->output_add(long_msg => sprintf("%s read iops on '%s' is %s", $prefix_msg, $_, $read_counter)); if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { @@ -223,7 +228,7 @@ sub run { short_msg => sprintf("%s read iops on '%s' is %s", $prefix_msg, $_, $read_counter)); } - $exit = $self->{manager}->{perfdata}->threshold_check(value => $write_counter, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $exit = $self->{manager}->{perfdata}->threshold_check(value => $write_counter, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{manager}->{output}->output_add(long_msg => sprintf("%s write iops on '%s' is %s", $prefix_msg, $_, $write_counter)); if (!$self->{manager}->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { diff --git a/connectors/vmware/src/centreon/vmware/cmdmemhost.pm b/connectors/vmware/src/centreon/vmware/cmdmemhost.pm index be06c740d..77d7287c4 100644 --- a/connectors/vmware/src/centreon/vmware/cmdmemhost.pm +++ b/connectors/vmware/src/centreon/vmware/cmdmemhost.pm @@ -112,6 +112,7 @@ sub run { [{'label' => 'mem.consumed.average', 'instances' => ['']}, {'label' => 'mem.overhead.average', 'instances' => ['']}], $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}, skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1); return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1); @@ -129,8 +130,8 @@ sub run { my $memory_size = $entity_view->{'summary.hardware.memorySize'}; # in B # in KB - my $mem_used = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.consumed.average'}->{'key'} . ":"}[0])) * 1024; - my $mem_overhead = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.overhead.average'}->{'key'} . ":"}[0])) * 1024; + my $mem_used = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.consumed.average'}->{'key'} . ":"})) * 1024; + my $mem_overhead = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.overhead.average'}->{'key'} . ":"})) * 1024; my $mem_free = $memory_size - $mem_used; my $prct_used = $mem_used * 100 / $memory_size; my $prct_free = 100 - $prct_used; diff --git a/connectors/vmware/src/centreon/vmware/cmdmemvm.pm b/connectors/vmware/src/centreon/vmware/cmdmemvm.pm index 8f126b4ee..9b4e952c9 100644 --- a/connectors/vmware/src/centreon/vmware/cmdmemvm.pm +++ b/connectors/vmware/src/centreon/vmware/cmdmemvm.pm @@ -125,6 +125,7 @@ sub run { {label => 'mem.consumed.average', instances => ['']}, {label => 'mem.shared.average', instances => ['']}], $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}, skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1); return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1); @@ -147,11 +148,11 @@ sub run { my $memory_size = $entity_view->{'summary.config.memorySizeMB'} * 1024 * 1024; # in KB - my $mem_consumed = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.consumed.average'}->{'key'} . ":"}[0])) * 1024; - my $mem_active = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.active.average'}->{'key'} . ":"}[0])) * 1024; - my $mem_overhead = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.overhead.average'}->{'key'} . ":"}[0])) * 1024; - my $mem_ballooning = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.vmmemctl.average'}->{'key'} . ":"}[0])) * 1024; - my $mem_shared = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.shared.average'}->{'key'} . ":"}[0])) * 1024; + my $mem_consumed = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.consumed.average'}->{'key'} . ":"})) * 1024; + my $mem_active = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.active.average'}->{'key'} . ":"})) * 1024; + my $mem_overhead = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.overhead.average'}->{'key'} . ":"})) * 1024; + my $mem_ballooning = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.vmmemctl.average'}->{'key'} . ":"})) * 1024; + my $mem_shared = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.shared.average'}->{'key'} . ":"})) * 1024; my $mem_free = $memory_size - $mem_consumed; my $prct_used = $mem_consumed * 100 / $memory_size; diff --git a/connectors/vmware/src/centreon/vmware/cmdnethost.pm b/connectors/vmware/src/centreon/vmware/cmdnethost.pm index a754603eb..e7407bad9 100644 --- a/connectors/vmware/src/centreon/vmware/cmdnethost.pm +++ b/connectors/vmware/src/centreon/vmware/cmdnethost.pm @@ -209,6 +209,7 @@ sub run { undef, $query_perfs, $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}, skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1); return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1); @@ -225,8 +226,8 @@ sub run { my @exits; foreach (sort keys %{$pnic_def_up->{$entity_value}}) { # KBps - my $traffic_in = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'net.received.average'}->{key} . ":" . $_}[0])) * 1024 * 8; - my $traffic_out = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'net.transmitted.average'}->{key} . ":" . $_}[0])) * 1024 * 8; + my $traffic_in = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'net.received.average'}->{key} . ":" . $_})) * 1024 * 8; + my $traffic_out = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'net.transmitted.average'}->{key} . ":" . $_})) * 1024 * 8; my $interface_speed = $pnic_def_up->{$entity_value}->{$_} * 1024 * 1024; my $in_prct = $traffic_in * 100 / $interface_speed; my $out_prct = $traffic_out * 100 / $interface_speed; diff --git a/connectors/vmware/src/centreon/vmware/cmdswaphost.pm b/connectors/vmware/src/centreon/vmware/cmdswaphost.pm index 8dd4e58e6..a2f627e26 100644 --- a/connectors/vmware/src/centreon/vmware/cmdswaphost.pm +++ b/connectors/vmware/src/centreon/vmware/cmdswaphost.pm @@ -112,6 +112,7 @@ sub run { [{'label' => 'mem.swapinRate.average', 'instances' => ['']}, {'label' => 'mem.swapoutRate.average', 'instances' => ['']}], $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}, skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1); return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1); @@ -128,11 +129,11 @@ sub run { my $entity_value = $entity_view->{mo_ref}->{value}; # KBps - my $swap_in = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.swapinRate.average'}->{'key'} . ":"}[0])) * 1024; - my $swap_out = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.swapoutRate.average'}->{'key'} . ":"}[0])) * 1024; + my $swap_in = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.swapinRate.average'}->{'key'} . ":"})) * 1024; + my $swap_out = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.swapoutRate.average'}->{'key'} . ":"})) * 1024; - my $exit1 = $self->{manager}->{perfdata}->threshold_check(value => $swap_in, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - my $exit2 = $self->{manager}->{perfdata}->threshold_check(value => $swap_out, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit1 = $self->{manager}->{perfdata}->threshold_check(value => $swap_in, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit2 = $self->{manager}->{perfdata}->threshold_check(value => $swap_out, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my $exit = $self->{manager}->{output}->get_most_critical(status => [ $exit1, $exit2 ]); my ($swap_in_value, $swap_in_unit) = $self->{manager}->{perfdata}->change_bytes(value => $swap_in); my ($swap_out_value, $swap_out_unit) = $self->{manager}->{perfdata}->change_bytes(value => $swap_out); diff --git a/connectors/vmware/src/centreon/vmware/cmdswapvm.pm b/connectors/vmware/src/centreon/vmware/cmdswapvm.pm index 457ad4604..e75897ab0 100644 --- a/connectors/vmware/src/centreon/vmware/cmdswapvm.pm +++ b/connectors/vmware/src/centreon/vmware/cmdswapvm.pm @@ -123,6 +123,7 @@ sub run { [{label => 'mem.swapinRate.average', instances => ['']}, {label => 'mem.swapoutRate.average', instances => ['']}], $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}, skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1); return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1); @@ -145,8 +146,8 @@ sub run { my $entity_value = $entity_view->{mo_ref}->{value}; # KBps - my $swap_in = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.swapinRate.average'}->{'key'} . ":"}[0])) * 1024; - my $swap_out = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.swapoutRate.average'}->{'key'} . ":"}[0])) * 1024; + my $swap_in = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.swapinRate.average'}->{'key'} . ":"})) * 1024; + my $swap_out = centreon::vmware::common::simplify_number(centreon::vmware::common::convert_number($values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'mem.swapoutRate.average'}->{'key'} . ":"})) * 1024; my $exit1 = $self->{manager}->{perfdata}->threshold_check(value => $swap_in, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my $exit2 = $self->{manager}->{perfdata}->threshold_check(value => $swap_out, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); diff --git a/connectors/vmware/src/centreon/vmware/cmdvmoperationcluster.pm b/connectors/vmware/src/centreon/vmware/cmdvmoperationcluster.pm index 6ef2d9589..822a926b3 100644 --- a/connectors/vmware/src/centreon/vmware/cmdvmoperationcluster.pm +++ b/connectors/vmware/src/centreon/vmware/cmdvmoperationcluster.pm @@ -116,6 +116,7 @@ sub run { {'label' => 'vmop.numSVMotion.latest', 'instances' => ['']}, {'label' => 'vmop.numClone.latest', 'instances' => ['']}], $self->{connector}->{perfcounter_speriod}, + sampling_period => $self->{sampling_period}, time_shift => $self->{time_shift}, skip_undef_counter => 1, multiples => 1, multiples_result_by_entity => 1); return if (centreon::vmware::common::performance_errors($self->{connector}, $values) == 1); @@ -135,7 +136,7 @@ sub run { my @exits; foreach my $label (('Clone', 'VMotion', 'SVMotion')) { - $new_datas->{$label . '_' . $entity_value} = $values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'vmop.num' . $label . '.latest'}->{key} . ":"}[0]; + $new_datas->{$label . '_' . $entity_value} = $values->{$entity_value}->{$self->{connector}->{perfcounter_cache}->{'vmop.num' . $label . '.latest'}->{key} . ":"}; $old_datas->{$label . '_' . $entity_value} = $self->{statefile_cache}->get(name => $label . '_' . $entity_value); next if (!defined($old_datas->{$label . '_' . $entity_value})); diff --git a/connectors/vmware/src/centreon/vmware/common.pm b/connectors/vmware/src/centreon/vmware/common.pm index e51297319..4bee216ff 100644 --- a/connectors/vmware/src/centreon/vmware/common.pm +++ b/connectors/vmware/src/centreon/vmware/common.pm @@ -203,19 +203,26 @@ sub search_in_datastore { } sub get_perf_metric_ids { - my $obj_vmware = shift; - my $perf_names = $_[0]; + my (%options) = @_; my $filtered_list = []; - foreach (@$perf_names) { - if (defined($obj_vmware->{perfcounter_cache}->{$_->{label}})) { + foreach (@{$options{metrics}}) { + if (defined($options{connector}->{perfcounter_cache}->{$_->{label}})) { foreach my $instance (@{$_->{instances}}) { - my $metric = PerfMetricId->new(counterId => $obj_vmware->{perfcounter_cache}->{$_->{label}}{key}, - instance => $instance); + if ($options{connector}->{perfcounter_cache}->{$_->{label}}{level} > $options{connector}->{sampling_periods}->{$options{interval}}->{level}) { + $manager_display->{output}->output_add(severity => 'UNKNOWN', + short_msg => sprintf("Cannot get counter '%s' for the sampling period '%s' (counter level: %s, sampling level: %s)", + $_->{label}, $options{interval}, + $options{connector}->{perfcounter_cache}->{$_->{label}}{level}, + $options{connector}->{sampling_periods}->{$options{interval}}->{level})); + return undef; + } + my $metric = PerfMetricId->new(counterId => $options{connector}->{perfcounter_cache}->{$_->{label}}{key}, + instance => $instance); push @$filtered_list, $metric; } } else { - $obj_vmware->{logger}->writeLogError("Metric '" . $_->{label} . "' unavailable."); + $options{connector}->{logger}->writeLogError("Metric '" . $_->{label} . "' unavailable."); $manager_display->{output}->output_add(severity => 'UNKNOWN', short_msg => "Counter doesn't exist. VMware version can be too old."); return undef; @@ -227,13 +234,16 @@ sub get_perf_metric_ids { sub performance_builder_specific { my (%options) = @_; + my $time_shift = defined($options{time_shift}) ? $options{time_shift} : 0; my @perf_query_spec; foreach my $entry (@{$options{metrics}}) { - my $perf_metric_ids = get_perf_metric_ids($options{connector}, $entry->{metrics}); + my $perf_metric_ids = get_perf_metric_ids(connector => $options{connector}, + metrics => $entry->{metrics}, + interval => $options{interval}); return undef if (!defined($perf_metric_ids)); my $tstamp = time(); - my (@t) = gmtime($tstamp - $options{interval}); + my (@t) = gmtime($tstamp - $options{interval} - $time_shift); my $startTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", (1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]); (@t) = gmtime($tstamp); @@ -245,8 +255,9 @@ sub performance_builder_specific { format => 'normal', intervalId => 20, startTime => $startTime, - endTime => $endTime, - maxSample => 1); + endTime => $endTime + ); + #maxSample => 1); } else { push @perf_query_spec, PerfQuerySpec->new(entity => $entry->{entity}, metricId => $perf_metric_ids, @@ -265,12 +276,15 @@ sub performance_builder_specific { sub performance_builder_global { my (%options) = @_; + my $time_shift = defined($options{time_shift}) ? $options{time_shift} : 0; my @perf_query_spec; - my $perf_metric_ids = get_perf_metric_ids($options{connector}, $options{metrics}); + my $perf_metric_ids = get_perf_metric_ids(connector => $options{connector}, + metrics => $options{metrics}, + interval => $options{interval}); return undef if (!defined($perf_metric_ids)); my $tstamp = time(); - my (@t) = gmtime($tstamp - $options{interval}); + my (@t) = gmtime($tstamp - $options{interval} - $time_shift); my $startTime = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", (1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1],$t[0]); (@t) = gmtime($tstamp); @@ -284,8 +298,8 @@ sub performance_builder_global { format => 'normal', intervalId => 20, startTime => $startTime, - endTime => $endTime, - maxSample => 1); + endTime => $endTime); + #maxSample => 1); } else { push @perf_query_spec, PerfQuerySpec->new(entity => $_, metricId => $perf_metric_ids, @@ -306,6 +320,21 @@ sub generic_performance_values_historic { my $counter = 0; my %results; + # overload the default sampling choosen + if (defined($options{sampling_period}) && $options{sampling_period} ne '') { + $interval = $options{sampling_period}; + } + # check sampling period exist + if (!defined($obj_vmware->{sampling_periods}->{$interval})) { + $manager_display->{output}->output_add(severity => 'UNKNOWN', + short_msg => sprintf("Sampling period '%s' not managed.", $interval)); + return undef; + } + if ($obj_vmware->{sampling_periods}->{$interval}->{enabled} != 1) { + $manager_display->{output}->output_add(severity => 'UNKNOWN', + short_msg => sprintf("Sampling period '%s' collection data no enabled.", $interval)); + return undef; + } eval { my $perfdata; @@ -313,11 +342,11 @@ sub generic_performance_values_historic { $perfdata = performance_builder_global(connector => $obj_vmware, views => $views, metrics => $perfs, - interval => $interval); + interval => $interval, time_shift => $options{time_shift}); } else { $perfdata = performance_builder_specific(connector => $obj_vmware, metrics => $perfs, - interval => $interval); + interval => $interval, time_shift => $options{time_shift}); } return undef if (!defined($perfdata)); @@ -337,15 +366,23 @@ sub generic_performance_values_historic { return undef; } + my $aggregated_counter_value = 0; + foreach my $counter_value (@{$_->value}) { + $aggregated_counter_value += $counter_value; + } + if (scalar(@{$_->value}) > 1) { + $aggregated_counter_value /= scalar(@{$_->value}); + } + if (defined($options{multiples}) && $options{multiples} == 1) { if (defined($options{multiples_result_by_entity}) && $options{multiples_result_by_entity} == 1) { $results{$val->{entity}->{value}} = {} if (!defined($results{$val->{entity}->{value}})); - $results{$val->{entity}->{value}}->{$_->id->counterId . ":" . (defined($_->id->instance) ? $_->id->instance : "")} = $_->value; + $results{$val->{entity}->{value}}->{$_->id->counterId . ":" . (defined($_->id->instance) ? $_->id->instance : "")} = $aggregated_counter_value; } else { - $results{$val->{entity}->{value} . ":" . $_->id->counterId . ":" . (defined($_->id->instance) ? $_->id->instance : "")} = $_->value; + $results{$val->{entity}->{value} . ":" . $_->id->counterId . ":" . (defined($_->id->instance) ? $_->id->instance : "")} = $aggregated_counter_value; } } else { - $results{$_->id->counterId . ":" . (defined($_->id->instance) ? $_->id->instance : "")} = $_->value; + $results{$_->id->counterId . ":" . (defined($_->id->instance) ? $_->id->instance : "")} = $aggregated_counter_value; } } } @@ -364,16 +401,18 @@ sub cache_perf_counters { $obj_vmware->{perfmanager_view} = $obj_vmware->{session1}->get_view(mo_ref => $obj_vmware->{session1}->get_service_content()->perfManager, properties => ['perfCounter', 'historicalInterval']); foreach (@{$obj_vmware->{perfmanager_view}->perfCounter}) { my $label = $_->groupInfo->key . "." . $_->nameInfo->key . "." . $_->rollupType->val; - $obj_vmware->{perfcounter_cache}->{$label} = {'key' => $_->key, 'unitkey' => $_->unitInfo->key}; + $obj_vmware->{perfcounter_cache}->{$label} = { key => $_->key, unitkey => $_->unitInfo->key, level => $_->level }; $obj_vmware->{perfcounter_cache_reverse}->{$_->key} = $label; } my $historical_intervals = $obj_vmware->{perfmanager_view}->historicalInterval; + $obj_vmware->{sampling_periods} = {}; foreach (@$historical_intervals) { if ($obj_vmware->{perfcounter_speriod} == -1 || $obj_vmware->{perfcounter_speriod} > $_->samplingPeriod) { $obj_vmware->{perfcounter_speriod} = $_->samplingPeriod; } + $obj_vmware->{sampling_periods}->{$_->samplingPeriod} = $_; } # Put refresh = 20 (for ESX check) @@ -493,6 +532,18 @@ sub performance_errors { return 0; } +sub get_interval_min { + my (%options) = @_; + + my $interval = $options{speriod}; + my $time_shift = defined($options{time_shift}) ? $options{time_shift} : 0; + if (defined($options{sampling_period}) && $options{sampling_period} ne '') { + $interval = $options{sampling_period}; + } + + return int(($interval + $time_shift) / 60); +} + sub is_accessible { my (%options) = @_;