git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@79 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
Quentin Garnier 2013-09-12 12:06:45 +00:00
parent 002b8c1af0
commit 2c6bb7bdd0
2 changed files with 43 additions and 11 deletions

View File

@ -61,11 +61,11 @@ GetOptions(
"on" => \$OPTION{on},
"w|warning=i" => \$OPTION{warning},
"c|critical=i" => \$OPTION{critical},
"w|warning=f" => \$OPTION{warning},
"c|critical=f" => \$OPTION{critical},
"warning2=i" => \$OPTION{warning2},
"critical2=i" => \$OPTION{critical2},
"warning2=f" => \$OPTION{warning2},
"critical2=f" => \$OPTION{critical2},
);
if (defined($OPTION{version})) {
@ -163,8 +163,10 @@ sub print_usage () {
print "\n";
print "'cpuvm':\n";
print " --vm VM to check (required)\n";
print " -w (--warning) Warning Threshold in percent (default 80)\n";
print " -c (--critical) Critical Threshold in percent (default 90)\n";
print " -w (--warning) Warning Threshold in percent for cpu average (default 80)\n";
print " -c (--critical) Critical Threshold in percent for cpu average (default 90)\n";
print " --warning2 Warning Threshold in percent for cpu ready (default 5)\n";
print " --critical2 Critical Threshold in percent for cpu ready (default 10)\n";
print "\n";
print "'toolsvm':\n";
print " --vm VM to check (required)\n";
@ -547,12 +549,18 @@ sub cpuvm_check_arg {
if (!defined($OPTION{critical})) {
$OPTION{critical} = 90;
}
if (!defined($OPTION{warning2})) {
$OPTION{warning2} = 5;
}
if (!defined($OPTION{critical2})) {
$OPTION{critical2} = 10;
}
return 0;
}
sub cpuvm_get_str {
return join($separatorin,
('cpuvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{warning}, $OPTION{critical}));
('cpuvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{warning}, $OPTION{critical}, $OPTION{warning2}, $OPTION{critical2}));
}
sub toolsvm_check_arg {

View File

@ -23,7 +23,7 @@ sub getCommandName {
sub checkArgs {
my $self = shift;
my ($vm, $warn, $crit) = @_;
my ($vm, $warn, $crit, $warn2, $crit2) = @_;
if (!defined($vm) || $vm eq "") {
$self->{logger}->writeLogError("ARGS error: need vm hostname");
@ -41,6 +41,18 @@ sub checkArgs {
$self->{logger}->writeLogError("ARGS error: warn threshold must be lower than crit threshold");
return 1;
}
if (defined($warn2) && $warn2 !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
$self->{logger}->writeLogError("ARGS error: warn2 threshold must be a positive number");
return 1;
}
if (defined($crit2) && $crit2 !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
$self->{logger}->writeLogError("ARGS error: crit2 threshold must be a positive number");
return 1;
}
if (defined($warn2) && defined($crit2) && $warn2 > $crit2) {
$self->{logger}->writeLogError("ARGS error: warn2 threshold must be lower than crit2 threshold");
return 1;
}
return 0;
}
@ -49,6 +61,8 @@ sub initArgs {
$self->{lvm} = $_[0];
$self->{warn} = (defined($_[1]) ? $_[1] : 80);
$self->{crit} = (defined($_[2]) ? $_[2] : 90);
$self->{warn2} = (defined($_[3]) ? $_[3] : 5);
$self->{crit2} = (defined($_[4]) ? $_[4] : 10);
}
sub run {
@ -76,14 +90,16 @@ sub run {
my $values = centreon::esxd::common::generic_performance_values_historic($self->{obj_esxd},
$$result[0],
[{'label' => 'cpu.usage.average', 'instances' => \@instances},
{'label' => 'cpu.usagemhz.average', 'instances' => \@instances}],
{'label' => 'cpu.usagemhz.average', 'instances' => \@instances},
{'label' => 'cpu.ready.summation', 'instances' => \@instances}],
$self->{obj_esxd}->{perfcounter_speriod});
return if (centreon::esxd::common::performance_errors($self->{obj_esxd}, $values) == 1);
my $status = 0; # OK
my $output = '';
my $total_cpu_average = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'cpu.usage.average'}->{'key'} . ":"}[0] * 0.01));
my $total_cpu_mhz_average = centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{'key'} . ":"}[0]));
my $total_cpu_ready = centreon::esxd::common::simplify_number($values->{$self->{obj_esxd}->{perfcounter_cache}->{'cpu.ready.summation'}->{'key'} . ":"}[0] / ($self->{obj_esxd}->{perfcounter_speriod} * 1000) * 100);
if ($total_cpu_average >= $self->{warn}) {
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
@ -91,8 +107,15 @@ sub run {
if ($total_cpu_average >= $self->{crit}) {
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
}
if ($total_cpu_ready >= $self->{warn2}) {
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
}
if ($total_cpu_ready >= $self->{crit2}) {
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
}
$output = "Total Average CPU usage '$total_cpu_average%', Total Average CPU '" . $total_cpu_mhz_average . "MHz' on last " . int($self->{obj_esxd}->{perfcounter_speriod} / 60) . "min | cpu_total=$total_cpu_average%;$self->{warn};$self->{crit};0;100 cpu_total_MHz=" . $total_cpu_mhz_average . "MHz";
$output = "CPU ready '$total_cpu_ready%', Total Average CPU usage '$total_cpu_average%', Total Average CPU '" . $total_cpu_mhz_average . "MHz' on last " . int($self->{obj_esxd}->{perfcounter_speriod} / 60) . "min | cpu_ready=$total_cpu_ready%;$self->{warn2};$self->{crit2};0; cpu_total=$total_cpu_average%;$self->{warn};$self->{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;
@ -100,6 +123,7 @@ sub run {
$cib = -1 if (!defined($cib) || $cib eq "");
$cia <=> $cib} keys %$values) {
my ($counter_id, $instance) = split /:/, $id;
next if ($self->{obj_esxd}->{perfcounter_cache}->{'cpu.usagemhz.average'}->{'key'} != $counter_id);
if ($instance ne "") {
$output .= " cpu" . $instance . "_MHz=" . centreon::esxd::common::simplify_number(centreon::esxd::common::convert_number($values->{$id}[0])) . "MHz";
}