Statistiques


git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@40 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
Quentin Garnier 2012-10-08 12:17:43 +00:00
parent c4cdaceee4
commit 397f505699
3 changed files with 56 additions and 19 deletions

View File

@ -159,6 +159,10 @@ sub print_usage () {
print "\n"; print "\n";
print "'getmap':\n"; print "'getmap':\n";
print " -e (--esx-host) Esx Host to check\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 () { sub print_help () {
@ -524,6 +528,20 @@ sub getmap_get_str {
return "getmap|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'}; 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(); print_usage();
exit $ERRORS{'UNKNOWN'}; 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 value is unknown\n";
print_usage(); print_usage();
exit $ERRORS{'UNKNOWN'}; exit $ERRORS{'UNKNOWN'};

View File

@ -368,10 +368,10 @@ foreach (keys %vsphere_server) {
my $socket_fileno = fileno($server); my $socket_fileno = fileno($server);
writeLogFile(LOG_ESXD_INFO, "[Server accepting clients]\n"); writeLogFile(LOG_ESXD_INFO, "[Server accepting clients]\n");
while (1) { while (1) {
my @rh_set = $read_select->can_read(30); my @rh_set = $read_select->can_read(15);
if ($stop == 1) { if ($stop == 1) {
writeLogFile(LOG_ESXD_INFO, "Send STOP command to thread.\n");
foreach (keys %vsphere_server) { foreach (keys %vsphere_server) {
writeLogFile(LOG_ESXD_INFO, "Send STOP command to '$_' child.\n");
my $writer_handle = $vsphere_server{$_}->{'writer_two'}; my $writer_handle = $vsphere_server{$_}->{'writer_two'};
print $writer_handle "STOP\n"; print $writer_handle "STOP\n";
} }
@ -427,37 +427,30 @@ while (1) {
if (defined($line) && $line ne "") { if (defined($line) && $line ne "") {
chomp $line; chomp $line;
my ($name, $vsphere_name, @args) = split /\|/, $line; my ($name, $vsphere_name, @args) = split /\|/, $line;
if ($name eq 'stats') {
stats_info($rh, $current_fileno, \@args);
next;
}
if (!defined($checks_descr{$name})) { if (!defined($checks_descr{$name})) {
$rh->send("3|Unknown method name '$name'\n"); response_client1($rh, $current_fileno, "3|Unknown method name '$name'\n");
delete $sockets{$current_fileno};
$read_select->remove($rh);
close $rh;
next; next;
} }
if ($checks_descr{$name}->{'arg'}(@args)) { if ($checks_descr{$name}->{'arg'}(@args)) {
$rh->send("3|Params error '$name'\n"); response_client1($rh, $current_fileno, "3|Params error '$name'\n");
delete $sockets{$current_fileno};
$read_select->remove($rh);
close $rh;
next; next;
} }
$vsphere_name = 'default' if (!defined($vsphere_name) || $vsphere_name eq ''); $vsphere_name = 'default' if (!defined($vsphere_name) || $vsphere_name eq '');
if (!defined($vsphere_server{$vsphere_name})) { if (!defined($vsphere_server{$vsphere_name})) {
$rh->send("3|Vsphere name unknown\n"); response_client1($rh, $current_fileno, "3|Vsphere name unknown\n");
delete $sockets{$current_fileno};
$read_select->remove($rh);
close $rh;
next; next;
} }
my $tmp_handle = ${$vsphere_server{$vsphere_name}->{'writer_two'}}; my $tmp_handle = ${$vsphere_server{$vsphere_name}->{'writer_two'}};
print $tmp_handle $current_fileno . "." . $sockets{$current_fileno}->{'counter'} . "|$name|" . join('|', @args) . "\n"; print $tmp_handle $current_fileno . "." . $sockets{$current_fileno}->{'counter'} . "|$name|" . join('|', @args) . "\n";
} else { } else {
delete $sockets{$current_fileno}; response_client1($rh, $current_fileno, "3|Need arguments\n");
$rh->send("3|Need arguments\n");
$read_select->remove($rh);
close $rh;
} }
} }
} }

View File

@ -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 { sub connect_vsphere {
my ($service_url, $username, $password) = @_; my ($service_url, $username, $password) = @_;
writeLogFile(LOG_ESXD_INFO, "'$whoaim' Vsphere connection in progress\n"); writeLogFile(LOG_ESXD_INFO, "'$whoaim' Vsphere connection in progress\n");
@ -198,4 +206,22 @@ sub get_entities_host {
return $entity_views; 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; 1;