From da72ccdd8edea76f11b3f5815e09c92ac7a1d10a Mon Sep 17 00:00:00 2001 From: Colin GAGNAIRE Date: Thu, 28 Dec 2017 16:52:36 +0100 Subject: [PATCH] improve redis restapi --- apps/redis/restapi/custom/api.pm | 19 +++++++++++++++++++ apps/redis/restapi/mode/clusterstats.pm | 9 +-------- apps/redis/restapi/mode/databasesstats.pm | 9 +-------- apps/redis/restapi/mode/nodesstats.pm | 13 +++---------- apps/redis/restapi/mode/shardsstats.pm | 9 +-------- 5 files changed, 25 insertions(+), 34 deletions(-) diff --git a/apps/redis/restapi/custom/api.pm b/apps/redis/restapi/custom/api.pm index 82cb71886..6056977b2 100644 --- a/apps/redis/restapi/custom/api.pm +++ b/apps/redis/restapi/custom/api.pm @@ -42,6 +42,7 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { + "interval:s@" => { name => 'interval' }, "hostname:s@" => { name => 'hostname' }, "port:s@" => { name => 'port' }, "proto:s@" => { name => 'proto' }, @@ -95,6 +96,7 @@ sub check_options { $self->{timeout} = (defined($self->{option_results}->{timeout})) ? shift(@{$self->{option_results}->{timeout}}) : 10; $self->{proxyurl} = (defined($self->{option_results}->{proxyurl})) ? shift(@{$self->{option_results}->{proxyurl}}) : undef; $self->{ssl} = (defined($self->{option_results}->{ssl})) ? shift(@{$self->{option_results}->{ssl}}) : 'tlsv1'; + $self->{interval} = (defined($self->{option_results}->{interval})) ? shift(@{$self->{option_results}->{interval}}) : '15min'; if (!defined($self->{hostname})) { $self->{output}->add_option_msg(short_msg => "Need to specify hostname option."); @@ -105,6 +107,7 @@ sub check_options { scalar(@{$self->{option_results}->{hostname}}) == 0) { return 0; } + return 1; } @@ -137,6 +140,12 @@ sub get_connection_info { return $self->{hostname} . ":" . $self->{port}; } +sub get_interval { + my ($self, %options) = @_; + + return $self->{interval}; +} + sub get { my ($self, %options) = @_; @@ -189,6 +198,12 @@ RedisLabs Enterprise Cluster Rest API custom mode =over 8 +=item B<--interval> + +Time interval from which to retrieve statistics (Default: '15min'). +Can be : '1sec', '10sec', '5min', '15min', +'1hour', '12hour', '1week'. + =item B<--hostname> Cluster hostname. @@ -217,6 +232,10 @@ Proxy URL if any Set HTTP timeout +=item B<--ssl> + +SSL version (Default: tlsv1) + =back =head1 DESCRIPTION diff --git a/apps/redis/restapi/mode/clusterstats.pm b/apps/redis/restapi/mode/clusterstats.pm index 8e2d960a1..e722cb9b6 100644 --- a/apps/redis/restapi/mode/clusterstats.pm +++ b/apps/redis/restapi/mode/clusterstats.pm @@ -226,7 +226,6 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "interval:s" => { name => 'interval', default => '15min' }, "units:s" => { name => 'units', default => '%' }, "free" => { name => 'free' }, }); @@ -244,7 +243,7 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - my $result = $options{custom}->get(path => '/v1/cluster/stats/last?interval='.$instance_mode->{option_results}->{interval}); + my $result = $options{custom}->get(path => '/v1/cluster/stats/last?interval='.$options{custom}->get_interval()); my $result2 = $options{custom}->get(path => '/v1/cluster'); my $result3 = $options{custom}->get(path => '/v1/nodes'); @@ -304,12 +303,6 @@ Check RedisLabs Enterprise Cluster statistics. Only display some counters (regexp can be used). Example: --filter-counters='^cpu' -=item B<--interval> - -Time interval from which to retrieve statistics (Default: '15min'). -Can be : '1sec', '10sec', '5min', '15min', -'1hour', '12hour', '1week' - =item B<--units> Units of thresholds (Default: '%') ('%', 'B'). diff --git a/apps/redis/restapi/mode/databasesstats.pm b/apps/redis/restapi/mode/databasesstats.pm index 810fc7ab4..c271338c3 100644 --- a/apps/redis/restapi/mode/databasesstats.pm +++ b/apps/redis/restapi/mode/databasesstats.pm @@ -441,7 +441,6 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "interval:s" => { name => 'interval', default => '15min' }, "filter-database:s" => { name => 'filter_database' }, "units:s" => { name => 'units', default => '%' }, "free" => { name => 'free' }, @@ -474,7 +473,7 @@ sub change_macros { sub manage_selection { my ($self, %options) = @_; - my $result = $options{custom}->get(path => '/v1/bdbs/stats/last?interval='.$instance_mode->{option_results}->{interval}); + my $result = $options{custom}->get(path => '/v1/bdbs/stats/last?interval='.$options{custom}->get_interval()); my $result2 = $options{custom}->get(path => '/v1/bdbs'); foreach my $database (keys $result) { @@ -556,12 +555,6 @@ Check RedisLabs Enterprise Cluster databases statistics. Only display some counters (regexp can be used). Example: --filter-counters='rate|latency' -=item B<--interval> - -Time interval from which to retrieve statistics (Default: '15min'). -Can be : '1sec', '10sec', '5min', '15min', -'1hour', '12hour', '1week' - =item B<--warning-status> Set warning threshold for status. diff --git a/apps/redis/restapi/mode/nodesstats.pm b/apps/redis/restapi/mode/nodesstats.pm index 2a1c23a87..ebff496a7 100644 --- a/apps/redis/restapi/mode/nodesstats.pm +++ b/apps/redis/restapi/mode/nodesstats.pm @@ -299,12 +299,11 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "interval:s" => { name => 'interval', default => '15min' }, "filter-node:s" => { name => 'filter_node' }, "units:s" => { name => 'units', default => '%' }, "free" => { name => 'free' }, "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /down/i' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /down/i' }, }); return $self; @@ -331,7 +330,7 @@ sub change_macros { sub manage_selection { my ($self, %options) = @_; - my $result = $options{custom}->get(path => '/v1/nodes/stats/last?interval='.$instance_mode->{option_results}->{interval}); + my $result = $options{custom}->get(path => '/v1/nodes/stats/last?interval='.$options{custom}->get_interval()); my $result2 = $options{custom}->get(path => '/v1/nodes'); foreach my $node (keys $result) { @@ -399,12 +398,6 @@ Check RedisLabs Enterprise Cluster nodes statistics. Only display some counters (regexp can be used). Example: --filter-counters='^cpu' -=item B<--interval> - -Time interval from which to retrieve statistics (Default: '15min'). -Can be : '1sec', '10sec', '5min', '15min', -'1hour', '12hour', '1week' - =item B<--units> Units of thresholds (Default: '%') ('%', 'B'). @@ -423,7 +416,7 @@ Can used special variables like: %{status}, %{shard_list}, =item B<--critical-status> -Set critical threshold for status (Default: '%{status} !~ /down/i'). +Set critical threshold for status (Default: '%{status} =~ /down/i'). Can used special variables like: %{status}, %{shard_list}, %{int_addr}, %{ext_addr}. 'status' can be: 'active', 'going_offline', 'offline', diff --git a/apps/redis/restapi/mode/shardsstats.pm b/apps/redis/restapi/mode/shardsstats.pm index 2480bd10c..cff2cb218 100644 --- a/apps/redis/restapi/mode/shardsstats.pm +++ b/apps/redis/restapi/mode/shardsstats.pm @@ -324,7 +324,6 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "interval:s" => { name => 'interval', default => '15min' }, "filter-shard:s" => { name => 'filter_shard' }, "warning-status:s" => { name => 'warning_status', default => '' }, "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /inactive/i | %{backup} =~ /failed/i | @@ -355,7 +354,7 @@ sub change_macros { sub manage_selection { my ($self, %options) = @_; - my $result = $options{custom}->get(path => '/v1/shards/stats/last?interval='.$instance_mode->{option_results}->{interval}); + my $result = $options{custom}->get(path => '/v1/shards/stats/last?interval='.$options{custom}->get_interval()); my $result2 = $options{custom}->get(path => '/v1/shards'); foreach my $shard (keys $result) { @@ -419,12 +418,6 @@ Check RedisLabs Enterprise Cluster shards statistics. Only display some counters (regexp can be used). Example: --filter-counters='clients' -=item B<--interval> - -Time interval from which to retrieve statistics (Default: '15min'). -Can be : '1sec', '10sec', '5min', '15min', -'1hour', '12hour', '1week' - =item B<--warning-status> Set warning threshold for status.