This commit is contained in:
garnier-quentin 2020-03-27 15:10:40 +01:00 committed by Lotfi zaouche
parent 780694ddff
commit 043878a7f7
7 changed files with 56 additions and 71 deletions

View File

@ -43,15 +43,16 @@ sub new {
if (!defined($options{noptions})) {
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port' },
"protocol:s" => { name => 'protocol' },
"username:s" => { name => 'username' },
"password:s" => { name => 'password' },
"timeout:s" => { name => 'timeout' },
"ssl-opt:s@" => { name => 'ssl_opt' },
'hostname:s' => { name => 'hostname' },
'port:s' => { name => 'port' },
'protocol:s' => { name => 'protocol' },
'username:s' => { name => 'username' },
'password:s' => { name => 'password' },
'timeout:s' => { name => 'timeout' },
'ssl-opt:s@' => { name => 'ssl_opt' },
});
}
$options{options}->add_help(package => __PACKAGE__, sections => 'DRIVER OPTIONS', once => 1);
$self->{output} = $options{output};
@ -127,7 +128,7 @@ sub connect {
$uri = $self->{protocol} . '://';
$uri .= $encoded_username . ':' . $encoded_password . '@' if ($encoded_username ne '' && $encoded_password ne '');
$uri .= $self->{hostname} if ($self->{hostname} ne '');
$uri .= ':' . $self->{port} if ($self->{port} ne '');
$uri .= ':' . $self->{port} if ($self->{port} ne '' && $self->{protocol} eq 'mongodb+srv');
$self->{output}->output_add(long_msg => 'Connection URI: ' . $uri, debug => 1);

View File

@ -106,24 +106,21 @@ sub new {
sub manage_selection {
my ($self, %options) = @_;
$self->{custom} = $options{custom};
my $databases = $options{custom}->list_databases();
$self->{databases} = {};
my $databases = $self->{custom}->list_databases();
foreach my $database (sort @{$databases}) {
next if (defined($self->{option_results}->{filter_database}) && $self->{option_results}->{filter_database} ne ''
&& $database !~ /$self->{option_results}->{filter_database}/);
my $collections = $self->{custom}->list_collections(database => $database);
my $collections = $options{custom}->list_collections(database => $database);
$self->{databases}->{$database}->{display} = $database;
foreach my $collection (sort @{$collections}) {
my $cl_stats = $self->{custom}->run_command(
my $cl_stats = $options{custom}->run_command(
database => $database,
command => $self->{custom}->ordered_hash(collStats => $collection),
command => $options{custom}->ordered_hash(collStats => $collection),
);
$self->{databases}->{$database}->{collections}->{$collection} = {

View File

@ -89,13 +89,11 @@ sub new {
sub manage_selection {
my ($self, %options) = @_;
$self->{custom} = $options{custom};
$self->{global} = {};
my $server_stats = $self->{custom}->run_command(
my $server_stats = $options{custom}->run_command(
database => 'admin',
command => $self->{custom}->ordered_hash(serverStatus => 1),
command => $options{custom}->ordered_hash(serverStatus => 1),
);
$self->{global}->{active} = $server_stats->{connections}->{active};
@ -103,7 +101,7 @@ sub manage_selection {
$self->{global}->{usage} = $server_stats->{connections}->{current} / ($server_stats->{connections}->{current} + $server_stats->{connections}->{available});
$self->{global}->{totalCreated} = $server_stats->{connections}->{totalCreated};
$self->{cache_name} = "mongodb_" . $self->{mode} . '_' . $self->{custom}->get_hostname() . '_' . $self->{custom}->get_port() . '_' .
$self->{cache_name} = "mongodb_" . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . $options{custom}->get_port() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}

View File

@ -59,10 +59,8 @@ sub new {
sub manage_selection {
my ($self, %options) = @_;
$self->{custom} = $options{custom};
my $start = Time::HiRes::time();
$self->{custom}->connect();
$options{custom}->connect();
my $end = Time::HiRes::time();
$self->{global}->{connection_time} = ($end - $start) * 1000;

View File

@ -115,7 +115,7 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"filter-database:s" => { name => 'filter_database' },
'filter-database:s' => { name => 'filter_database' }
});
return $self;
}
@ -123,19 +123,16 @@ sub new {
sub manage_selection {
my ($self, %options) = @_;
$self->{custom} = $options{custom};
my $databases = $options{custom}->list_databases();
$self->{databases} = {};
my $databases = $self->{custom}->list_databases();
foreach my $database (sort @{$databases}) {
next if (defined($self->{option_results}->{filter_database}) && $self->{option_results}->{filter_database} ne ''
&& $database !~ /$self->{option_results}->{filter_database}/);
my $db_stats = $self->{custom}->run_command(
my $db_stats = $options{custom}->run_command(
database => $database,
command => $self->{custom}->ordered_hash('dbStats' => 1),
command => $options{custom}->ordered_hash(dbStats => 1),
);
$self->{databases}->{$db_stats->{db}} = {

View File

@ -71,7 +71,7 @@ sub set_counters {
sub prefix_output {
my ($self, %options) = @_;
return "Requests ";
return 'Requests ';
}
sub new {
@ -87,13 +87,10 @@ sub new {
sub manage_selection {
my ($self, %options) = @_;
$self->{custom} = $options{custom};
$self->{global} = {};
my $server_stats = $self->{custom}->run_command(
my $server_stats = $options{custom}->run_command(
database => 'admin',
command => $self->{custom}->ordered_hash(serverStatus => 1),
command => $options{custom}->ordered_hash(serverStatus => 1),
);
foreach my $querie (keys %{$server_stats->{opcounters}}) {
@ -101,7 +98,7 @@ sub manage_selection {
$self->{global}->{total} += $server_stats->{opcounters}->{$querie};
}
$self->{cache_name} = "mongodb_" . $self->{mode} . '_' . $self->{custom}->get_hostname() . '_' . $self->{custom}->get_port() . '_' .
$self->{cache_name} = 'mongodb_' . $self->{mode} . '_' . $options{custom}->get_hostname() . '_' . $options{custom}->get_port() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}

View File

@ -41,7 +41,6 @@ sub custom_status_output {
my $msg = sprintf("Current member state is '%s'", $self->{result_values}->{state});
$msg .= sprintf(", syncing to '%s'", $self->{result_values}->{sync_host}) if ($self->{result_values}->{state} ne 'PRIMARY');
return $msg;
}
@ -50,20 +49,18 @@ sub custom_status_calc {
$self->{result_values}->{state} = $mapping_states{$options{new_datas}->{$self->{instance} . '_myState'}};
$self->{result_values}->{sync_host} = $options{new_datas}->{$self->{instance} . '_syncSourceHost'};
return 0;
}
sub custom_member_status_output {
my ($self, %options) = @_;
my $msg = sprintf("state is '%s' and health is '%s' [slave delay: %s] [priority: %s]",
return sprintf("state is '%s' and health is '%s' [slave delay: %s] [priority: %s]",
$self->{result_values}->{state},
$self->{result_values}->{health},
$self->{result_values}->{slave_delay},
$self->{result_values}->{priority});
return $msg;
$self->{result_values}->{priority}
);
}
sub custom_member_status_calc {
@ -131,11 +128,12 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '' },
"warning-member-status:s" => { name => 'warning_member_status', default => '%{state} !~ /PRIMARY|SECONDARY/' },
"critical-member-status:s" => { name => 'critical_member_status', default => '%{health} !~ /up/' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '' },
'warning-member-status:s' => { name => 'warning_member_status', default => '%{state} !~ /PRIMARY|SECONDARY/' },
'critical-member-status:s' => { name => 'critical_member_status', default => '%{health} !~ /up/' },
});
return $self;
}
@ -143,18 +141,18 @@ sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status',
'warning_member_status', 'critical_member_status']);
$self->change_macros(macros => [
'warning_status', 'critical_status',
'warning_member_status', 'critical_member_status'
]);
}
sub manage_selection {
my ($self, %options) = @_;
$self->{custom} = $options{custom};
my $ismaster = $self->{custom}->run_command(
my $ismaster = $options{custom}->run_command(
database => 'admin',
command => $self->{custom}->ordered_hash('ismaster' => 1),
command => $options{custom}->ordered_hash(ismaster => 1),
);
if (!defined($ismaster->{me})) {
@ -164,10 +162,9 @@ sub manage_selection {
$self->{global} = {};
$self->{members} = {};
my $repl_conf = $self->{custom}->run_command(
my $repl_conf = $options{custom}->run_command(
database => 'admin',
command => $self->{custom}->ordered_hash('replSetGetConfig' => 1),
command => $options{custom}->ordered_hash(replSetGetConfig => 1),
);
my %config;
@ -175,9 +172,9 @@ sub manage_selection {
$config{$member->{host}} = { priority => $member->{priority}, slaveDelay => $member->{slaveDelay} }
}
my $repl_status = $self->{custom}->run_command(
my $repl_status = $options{custom}->run_command(
database => 'admin',
command => $self->{custom}->ordered_hash('replSetGetStatus' => 1),
command => $options{custom}->ordered_hash(replSetGetStatus => 1),
);
$self->{global}->{myState} = $repl_status->{myState};
@ -191,7 +188,7 @@ sub manage_selection {
health => $member->{health},
optimeDate => $member->{optime}->{ts}->{seconds},
slaveDelay => $config{$member->{name}}->{slaveDelay},
priority => $config{$member->{name}}->{priority},
priority => $config{$member->{name}}->{priority}
}
}