Evolution #4012
[vm] Vérification du swap git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@41 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
parent
397f505699
commit
4cbffb1235
|
@ -148,6 +148,11 @@ sub print_usage () {
|
|||
print " -w (--warning) Warning Threshold in percent (default 80)\n";
|
||||
print " -c (--critical) Critical Threshold in percent (default 90)\n";
|
||||
print "\n";
|
||||
print "'swapvm':\n";
|
||||
print " --vm VM to check (required)\n";
|
||||
print " -w (--warning) Warning Threshold in MB/s (default 0.8)\n";
|
||||
print " -c (--critical) Critical Threshold in MB/s (default 1)\n";
|
||||
print "\n";
|
||||
print "'listhost':\n";
|
||||
print " None\n";
|
||||
print "\n";
|
||||
|
@ -487,6 +492,25 @@ sub memvm_get_str {
|
|||
return "memvm|" . $OPTION{'vsphere'} . "|" . $OPTION{'vm'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
}
|
||||
|
||||
sub swapvm_check_arg {
|
||||
if (!defined($OPTION{'vm'})) {
|
||||
print "Option --vm is required\n";
|
||||
print_usage();
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
if (!defined($OPTION{'warning'})) {
|
||||
$OPTION{'warning'} = 0.8;
|
||||
}
|
||||
if (!defined($OPTION{'critical'})) {
|
||||
$OPTION{'critical'} = 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub swapvm_get_str {
|
||||
return "swapvm|" . $OPTION{'vsphere'} . "|" . $OPTION{'vm'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
}
|
||||
|
||||
|
||||
sub listhost_check_arg {
|
||||
return 0;
|
||||
|
@ -556,7 +580,7 @@ if (!defined($OPTION{'usage'})) {
|
|||
print_usage();
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
}
|
||||
if ($OPTION{'usage'} !~ /^(healthhost|datastore-usage|datastore-io|maintenancehost|statushost|cpuhost|datastoreshost|nethost|memhost|swaphost|countvmhost|cpuvm|toolsvm|snapshotvm|datastoresvm|memvm|listhost|listdatastore|listnichost|getmap|stats)$/) {
|
||||
if ($OPTION{'usage'} !~ /^(healthhost|datastore-usage|datastore-io|maintenancehost|statushost|cpuhost|datastoreshost|nethost|memhost|swaphost|countvmhost|cpuvm|toolsvm|snapshotvm|datastoresvm|memvm|swapvm|listhost|listdatastore|listnichost|getmap|stats)$/) {
|
||||
print "Usage value is unknown\n";
|
||||
print_usage();
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
|
|
|
@ -58,6 +58,7 @@ require $libpath . '/command-nethost.pm';
|
|||
require $libpath . '/command-snapshotvm.pm';
|
||||
require $libpath . '/command-statushost.pm';
|
||||
require $libpath . '/command-swaphost.pm';
|
||||
require $libpath . '/command-swapvm.pm';
|
||||
require $libpath . '/command-toolsvm.pm';
|
||||
|
||||
|
||||
|
@ -113,6 +114,7 @@ our %checks_descr = (
|
|||
"snapshotvm" => {'arg' => \&snapshotvm_check_args, 'compute' => \&snapshotvm_compute_args, 'exec' => \&snapshotvm_do},
|
||||
"datastoresvm" => {'arg' => \&datastoresvm_check_args, 'compute' => \&datastoresvm_compute_args, 'exec' => \&datastoresvm_do},
|
||||
"memvm" => {'arg' => \&memvm_check_args, 'compute' => \&memvm_compute_args, 'exec' => \&memvm_do},
|
||||
"swapvm" => {'arg' => \&swapvm_check_args, 'compute' => \&swapvm_compute_args, 'exec' => \&swapvm_do},
|
||||
"listhost" => {'arg' => \&listhost_check_args, 'compute' => \&listhost_compute_args, 'exec' => \&listhost_do},
|
||||
"listdatastore" => {'arg' => \&listdatastore_check_args, 'compute' => \&listdatastore_compute_args, 'exec' => \&listdatastore_do},
|
||||
"listnichost" => {'arg' => \&listnichost_check_args, 'compute' => \&listnichost_compute_args, 'exec' => \&listnichost_do},
|
||||
|
|
|
@ -35,8 +35,7 @@ sub swaphost_do {
|
|||
}
|
||||
|
||||
my %filters = ('name' => $lhost);
|
||||
#my @properties = ('summary');
|
||||
my @properties = ();
|
||||
my @properties = ('name');
|
||||
my $result = get_entities_host('HostSystem', \%filters, \@properties);
|
||||
if (!defined($result)) {
|
||||
return ;
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
sub swapvm_check_args {
|
||||
my ($vm, $warn, $crit) = @_;
|
||||
if (!defined($vm) || $vm eq "") {
|
||||
writeLogFile(LOG_ESXD_ERROR, "ARGS error: need vm name\n");
|
||||
return 1;
|
||||
}
|
||||
if (defined($warn) && $warn !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
|
||||
writeLogFile(LOG_ESXD_ERROR, "ARGS error: warn threshold must be a positive number\n");
|
||||
return 1;
|
||||
}
|
||||
if (defined($crit) && $crit !~ /^-?(?:\d+\.?|\.\d)\d*\z/) {
|
||||
writeLogFile(LOG_ESXD_ERROR, "ARGS error: crit threshold must be a positive number\n");
|
||||
return 1;
|
||||
}
|
||||
if (defined($warn) && defined($crit) && $warn > $crit) {
|
||||
writeLogFile(LOG_ESXD_ERROR, "ARGS error: warn threshold must be lower than crit threshold\n");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub swapvm_compute_args {
|
||||
my $lvm = $_[0];
|
||||
my $warn = (defined($_[1]) ? $_[1] : 0.8);
|
||||
my $crit = (defined($_[2]) ? $_[2] : 1);
|
||||
return ($lvm, $warn, $crit);
|
||||
}
|
||||
|
||||
sub swapvm_do {
|
||||
my ($lvm, $warn, $crit) = @_;
|
||||
if (!($perfcounter_speriod > 0)) {
|
||||
my $status |= $MYERRORS_MASK{'UNKNOWN'};
|
||||
print_response($ERRORS{$MYERRORS{$status}} . "|Can't retrieve perf counters.\n");
|
||||
return ;
|
||||
}
|
||||
|
||||
my %filters = ('name' => $lvm);
|
||||
my @properties = ('name');
|
||||
my $result = get_entities_host('VirtualMachine', \%filters, \@properties);
|
||||
if (!defined($result)) {
|
||||
return ;
|
||||
}
|
||||
|
||||
my $values = generic_performance_values_historic($$result[0],
|
||||
[{'label' => 'mem.swapinRate.average', 'instances' => ['']},
|
||||
{'label' => 'mem.swapoutRate.average', 'instances' => ['']}],
|
||||
$perfcounter_speriod);
|
||||
|
||||
my $swap_in = simplify_number(convert_number($values->{$perfcounter_cache{'mem.swapinRate.average'}->{'key'} . ":"}[0]));
|
||||
my $swap_out = simplify_number(convert_number($values->{$perfcounter_cache{'mem.swapoutRate.average'}->{'key'} . ":"}[0]));
|
||||
my $status = 0; # OK
|
||||
my $output = '';
|
||||
|
||||
if (($swap_in / 1024) >= $warn || ($swap_out / 1024) >= $warn) {
|
||||
$status |= $MYERRORS_MASK{'WARNING'};
|
||||
}
|
||||
if (($swap_in / 1024) >= $crit || ($swap_out / 1024) >= $crit) {
|
||||
$status |= $MYERRORS_MASK{'CRITICAL'};
|
||||
}
|
||||
|
||||
$output = "Swap In : " . simplify_number($swap_in / 1024 * 8) . " Mb/s , Swap Out : " . simplify_number($swap_out / 1024 * 8) . " Mb/s ";
|
||||
$output .= "|swap_in=" . ($swap_in * 1024 * 8) . "b/s swap_out=" . (($swap_out * 1024 * 8)) . "b/s";
|
||||
|
||||
print_response($ERRORS{$MYERRORS{$status}} . "|$output\n");
|
||||
}
|
||||
|
||||
1;
|
Loading…
Reference in New Issue