From 967d577d8b3277ee417f544347476682f6f82eab Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Wed, 6 Feb 2013 15:47:39 +0000 Subject: [PATCH] Fix #4863 git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@51 a5eaa968-4c79-4d68-970d-af6011b5b055 --- connectors/vmware/lib/command-cpuhost.pm | 2 +- connectors/vmware/lib/command-cpuvm.pm | 2 +- connectors/vmware/lib/esxd-common.pm | 34 +++++++++++++++++------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/connectors/vmware/lib/command-cpuhost.pm b/connectors/vmware/lib/command-cpuhost.pm index 864aa737a..1ff1d4896 100644 --- a/connectors/vmware/lib/command-cpuhost.pm +++ b/connectors/vmware/lib/command-cpuhost.pm @@ -59,7 +59,7 @@ sub cpuhost_do { $status |= $MYERRORS_MASK{'CRITICAL'}; } - $output = "Total Average CPU usage '$total_cpu_average%' on last " . ($perfcounter_speriod / 60) . "min | cpu_total=$total_cpu_average%;$warn;$crit;0;100"; + $output = "Total Average CPU usage '$total_cpu_average%' on last " . int($perfcounter_speriod / 60) . "min | cpu_total=$total_cpu_average%;$warn;$crit;0;100"; foreach my $id (sort { my ($cida, $cia) = split /:/, $a; my ($cidb, $cib) = split /:/, $b; diff --git a/connectors/vmware/lib/command-cpuvm.pm b/connectors/vmware/lib/command-cpuvm.pm index d8eda8544..67789cc52 100644 --- a/connectors/vmware/lib/command-cpuvm.pm +++ b/connectors/vmware/lib/command-cpuvm.pm @@ -61,7 +61,7 @@ sub cpuvm_do { $status |= $MYERRORS_MASK{'CRITICAL'}; } - $output = "Total Average CPU usage '$total_cpu_average%', Total Average CPU '" . $total_cpu_mhz_average . "MHz' on last " . ($perfcounter_speriod / 60) . "min | cpu_total=$total_cpu_average%;$warn;$crit;0;100 cpu_total_MHz=" . $total_cpu_mhz_average . "MHz"; + $output = "Total Average CPU usage '$total_cpu_average%', Total Average CPU '" . $total_cpu_mhz_average . "MHz' on last " . int($perfcounter_speriod / 60) . "min | cpu_total=$total_cpu_average%;$warn;$crit;0;100 cpu_total_MHz=" . $total_cpu_mhz_average . "MHz"; foreach my $id (sort { my ($cida, $cia) = split /:/, $a; my ($cidb, $cib) = split /:/, $b; diff --git a/connectors/vmware/lib/esxd-common.pm b/connectors/vmware/lib/esxd-common.pm index a64d6b6f4..787f83a84 100644 --- a/connectors/vmware/lib/esxd-common.pm +++ b/connectors/vmware/lib/esxd-common.pm @@ -116,16 +116,25 @@ sub generic_performance_values_historic { eval { my @perf_metric_ids = get_perf_metric_ids($perfs); - my (@t) = gmtime(time() - $interval); - my $start = sprintf("%04d-%02d-%02dT%02d:%02d:00Z", - (1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1]); - my $perf_query_spec = PerfQuerySpec->new(entity => $view, - metricId => @perf_metric_ids, - format => 'normal', - intervalId => $interval, - startTime => $start - ); - #maxSample => 1); + my $perf_query_spec; + if ($interval == 20) { + $perf_query_spec = PerfQuerySpec->new(entity => $view, + metricId => @perf_metric_ids, + format => 'normal', + intervalId => 20, + maxSample => 1); + } else { + my (@t) = gmtime(time() - $interval); + my $start = sprintf("%04d-%02d-%02dT%02d:%02d:00Z", + (1900+$t[5]),(1+$t[4]),$t[3],$t[2],$t[1]); + $perf_query_spec = PerfQuerySpec->new(entity => $view, + metricId => @perf_metric_ids, + format => 'normal', + intervalId => $interval, + startTime => $start + ); + #maxSample => 1); + } my $perfdata = $perfmanager_view->QueryPerf(querySpec => $perf_query_spec); foreach (@{$$perfdata[0]->value}) { $results{$_->id->counterId . ":" . (defined($_->id->instance) ? $_->id->instance : "")} = $_->value; @@ -154,6 +163,11 @@ sub cache_perf_counters { $perfcounter_speriod = $_->samplingPeriod; } } + + # Put refresh = 20 (for ESX check) + if ($perfcounter_speriod == -1) { + $perfcounter_speriod = 20; + } }; if ($@) { writeLogFile(LOG_ESXD_ERROR, "'$whoaim' $@");