Evolution #3971
Statistiques git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@40 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
parent
c4cdaceee4
commit
397f505699
|
@ -159,6 +159,10 @@ sub print_usage () {
|
|||
print "\n";
|
||||
print "'getmap':\n";
|
||||
print " -e (--esx-host) Esx Host to check\n";
|
||||
print "\n";
|
||||
print "'stats':\n";
|
||||
print " -w (--warning) Warning Threshold in total client connections (default none)\n";
|
||||
print " -c (--critical) Critical Threshold in total client connections (default none)\n";
|
||||
}
|
||||
|
||||
sub print_help () {
|
||||
|
@ -524,6 +528,20 @@ sub getmap_get_str {
|
|||
return "getmap|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'};
|
||||
}
|
||||
|
||||
sub stats_check_arg {
|
||||
if (!defined($OPTION{'warning'})) {
|
||||
$OPTION{'warning'} = "";
|
||||
}
|
||||
if (!defined($OPTION{'critical'})) {
|
||||
$OPTION{'critical'} = "";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub stats_get_str {
|
||||
return "stats||" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
||||
}
|
||||
|
||||
#################
|
||||
#################
|
||||
|
||||
|
@ -538,7 +556,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)$/) {
|
||||
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)$/) {
|
||||
print "Usage value is unknown\n";
|
||||
print_usage();
|
||||
exit $ERRORS{'UNKNOWN'};
|
||||
|
|
|
@ -368,10 +368,10 @@ foreach (keys %vsphere_server) {
|
|||
my $socket_fileno = fileno($server);
|
||||
writeLogFile(LOG_ESXD_INFO, "[Server accepting clients]\n");
|
||||
while (1) {
|
||||
my @rh_set = $read_select->can_read(30);
|
||||
my @rh_set = $read_select->can_read(15);
|
||||
if ($stop == 1) {
|
||||
writeLogFile(LOG_ESXD_INFO, "Send STOP command to thread.\n");
|
||||
foreach (keys %vsphere_server) {
|
||||
writeLogFile(LOG_ESXD_INFO, "Send STOP command to '$_' child.\n");
|
||||
my $writer_handle = $vsphere_server{$_}->{'writer_two'};
|
||||
print $writer_handle "STOP\n";
|
||||
}
|
||||
|
@ -427,37 +427,30 @@ while (1) {
|
|||
if (defined($line) && $line ne "") {
|
||||
chomp $line;
|
||||
my ($name, $vsphere_name, @args) = split /\|/, $line;
|
||||
|
||||
if ($name eq 'stats') {
|
||||
stats_info($rh, $current_fileno, \@args);
|
||||
next;
|
||||
}
|
||||
if (!defined($checks_descr{$name})) {
|
||||
$rh->send("3|Unknown method name '$name'\n");
|
||||
delete $sockets{$current_fileno};
|
||||
$read_select->remove($rh);
|
||||
close $rh;
|
||||
response_client1($rh, $current_fileno, "3|Unknown method name '$name'\n");
|
||||
next;
|
||||
}
|
||||
if ($checks_descr{$name}->{'arg'}(@args)) {
|
||||
$rh->send("3|Params error '$name'\n");
|
||||
delete $sockets{$current_fileno};
|
||||
$read_select->remove($rh);
|
||||
close $rh;
|
||||
response_client1($rh, $current_fileno, "3|Params error '$name'\n");
|
||||
next;
|
||||
}
|
||||
|
||||
$vsphere_name = 'default' if (!defined($vsphere_name) || $vsphere_name eq '');
|
||||
if (!defined($vsphere_server{$vsphere_name})) {
|
||||
$rh->send("3|Vsphere name unknown\n");
|
||||
delete $sockets{$current_fileno};
|
||||
$read_select->remove($rh);
|
||||
close $rh;
|
||||
response_client1($rh, $current_fileno, "3|Vsphere name unknown\n");
|
||||
next;
|
||||
}
|
||||
|
||||
my $tmp_handle = ${$vsphere_server{$vsphere_name}->{'writer_two'}};
|
||||
print $tmp_handle $current_fileno . "." . $sockets{$current_fileno}->{'counter'} . "|$name|" . join('|', @args) . "\n";
|
||||
} else {
|
||||
delete $sockets{$current_fileno};
|
||||
$rh->send("3|Need arguments\n");
|
||||
$read_select->remove($rh);
|
||||
close $rh;
|
||||
response_client1($rh, $current_fileno, "3|Need arguments\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,14 @@ sub writeLogFile($$) {
|
|||
}
|
||||
}
|
||||
|
||||
sub response_client1 {
|
||||
my ($rh, $current_fileno, $msg) = @_;
|
||||
$rh->send($msg);
|
||||
delete $sockets{$current_fileno};
|
||||
$read_select->remove($rh);
|
||||
close $rh;
|
||||
}
|
||||
|
||||
sub connect_vsphere {
|
||||
my ($service_url, $username, $password) = @_;
|
||||
writeLogFile(LOG_ESXD_INFO, "'$whoaim' Vsphere connection in progress\n");
|
||||
|
@ -198,4 +206,22 @@ sub get_entities_host {
|
|||
return $entity_views;
|
||||
}
|
||||
|
||||
sub stats_info {
|
||||
my ($rh, $current_fileno, $args) = @_;
|
||||
my $output;
|
||||
my $status = 0;
|
||||
|
||||
$$args[0] ='' if (!defined($$args[0]));
|
||||
$$args[1] = '' if (!defined($$args[1]));
|
||||
|
||||
my $num_connection = scalar(keys(%sockets));
|
||||
$output = "'$num_connection' total client connections | connection=$num_connection;$$args[0];$$args[1] requests=$counter";
|
||||
if ($$args[1] ne '' and $num_connection >= $$args[1]) {
|
||||
$status |= $MYERRORS_MASK{'CRITICAL'};
|
||||
} elsif ($$args[0] ne '' and $num_connection >= $$args[0]) {
|
||||
$status |= $MYERRORS_MASK{'WARNING'};
|
||||
}
|
||||
response_client1($rh, $current_fileno, $ERRORS{$MYERRORS{$status}}. "|$output\n");
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
Loading…
Reference in New Issue