move aws ec2 to new perfdata
This commit is contained in:
parent
f10d5216d7
commit
3f730bb64c
|
@ -160,7 +160,9 @@ sub manage_selection {
|
|||
|
||||
$self->{metrics}->{$instance}->{display} = $instance;
|
||||
$self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic;
|
||||
$self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0;
|
||||
$self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} =
|
||||
defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ?
|
||||
$metric_results{$instance}->{$metric}->{lc($statistic)} : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
|
|||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
my $msg = "[Health: " . $self->{result_values}->{health} . " - Lifecycle: " . $self->{result_values}->{lifecycle} . "]";
|
||||
my $msg = "[Health: " . $self->{result_values}->{health} .
|
||||
" - Lifecycle: " . $self->{result_values}->{lifecycle} . "]";
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
@ -46,7 +47,10 @@ sub custom_status_calc {
|
|||
sub custom_asg_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = sprintf('Instance number: %s (config: min=%d max=%d)', $self->{result_values}->{count}, $self->{result_values}->{min_size}, $self->{result_values}->{max_size});
|
||||
my $msg = sprintf('Instance current count: %s (config: min=%d max=%d)',
|
||||
$self->{result_values}->{count},
|
||||
$self->{result_values}->{min_size},
|
||||
$self->{result_values}->{max_size});
|
||||
return $msg;
|
||||
}
|
||||
|
||||
|
@ -77,18 +81,21 @@ sub set_counters {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'aws_asg', type => 1, cb_prefix_output => 'prefix_awsasg_output', message_multiple => 'All Auto Scaling Groups are ok' },
|
||||
{ name => 'aws_instances', type => 1, cb_prefix_output => 'prefix_awsinstance_output', message_multiple => 'All instances are ok' },
|
||||
{ name => 'aws_asg', type => 1, cb_prefix_output => 'prefix_awsasg_output',
|
||||
message_multiple => 'All Auto Scaling Groups are ok' },
|
||||
{ name => 'aws_instances', type => 1, cb_prefix_output => 'prefix_awsinstance_output',
|
||||
message_multiple => 'All instances are ok' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{aws_asg} = [
|
||||
{ label => 'count', set => {
|
||||
key_values => [ { name => 'display' }, { name => 'count' }, { name => 'min_size' }, { name => 'max_size' } ],
|
||||
{ label => 'asg-instance-current', nlabel => 'ec2.asg.instance.current.count', set => {
|
||||
key_values => [ { name => 'display' }, { name => 'count' },
|
||||
{ name => 'min_size' }, { name => 'max_size' } ],
|
||||
threshold_use => 'count',
|
||||
closure_custom_calc => $self->can('custom_asg_calc'),
|
||||
closure_custom_output => $self->can('custom_asg_output'),
|
||||
perfdatas => [
|
||||
{ label => 'count', value => 'count', template => '%d',
|
||||
{ value => 'count', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
}
|
||||
|
@ -96,7 +103,8 @@ sub set_counters {
|
|||
];
|
||||
$self->{maps_counters}->{aws_instances} = [
|
||||
{ label => 'instances', set => {
|
||||
key_values => [ { name => 'health' }, { name => 'lifecycle' }, { name => 'asg' }, { name => 'display' } ],
|
||||
key_values => [ { name => 'health' }, { name => 'lifecycle' },
|
||||
{ name => 'asg' }, { name => 'display' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
|
@ -104,21 +112,20 @@ sub set_counters {
|
|||
}
|
||||
},
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"region:s" => { name => 'region' },
|
||||
"filter-asg:s" => { name => 'filter_asg', default => '' },
|
||||
"warning-instances:s" => { name => 'warning_instances', default => '' },
|
||||
"critical-instances:s" => { name => 'critical_instances', default => '%{health} =~ /Healthy/ && %{lifecycle} !~ /InService/' },
|
||||
});
|
||||
$options{options}->add_options(arguments => {
|
||||
"region:s" => { name => 'region' },
|
||||
"filter-asg:s" => { name => 'filter_asg', default => '' },
|
||||
"warning-instances:s" => { name => 'warning_instances', default => '' },
|
||||
"critical-instances:s" => { name => 'critical_instances',
|
||||
default => '%{health} =~ /Healthy/ && %{lifecycle} !~ /InService/' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
@ -152,17 +159,20 @@ sub manage_selection {
|
|||
}
|
||||
|
||||
foreach my $instance (@{$asg->{Instances}}) {
|
||||
$self->{aws_instances}->{$instance->{InstanceId}} = { display => $instance->{InstanceId},
|
||||
asg => $asg->{AutoScalingGroupName},
|
||||
health => $instance->{HealthStatus},
|
||||
lifecycle => $instance->{LifecycleState} };
|
||||
|
||||
$instance_count++;
|
||||
$self->{aws_instances}->{$instance->{InstanceId}} = {
|
||||
display => $instance->{InstanceId},
|
||||
asg => $asg->{AutoScalingGroupName},
|
||||
health => $instance->{HealthStatus},
|
||||
lifecycle => $instance->{LifecycleState}
|
||||
};
|
||||
$instance_count++;
|
||||
}
|
||||
$self->{aws_asg}->{$asg->{AutoScalingGroupName}} = { display => $asg->{AutoScalingGroupName},
|
||||
min_size => $asg->{MinSize},
|
||||
max_size => $asg->{MaxSize},
|
||||
count => $instance_count };
|
||||
$self->{aws_asg}->{$asg->{AutoScalingGroupName}} = {
|
||||
display => $asg->{AutoScalingGroupName},
|
||||
min_size => $asg->{MinSize},
|
||||
max_size => $asg->{MaxSize},
|
||||
count => $instance_count
|
||||
};
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{aws_instances}}) <= 0 && $self->{aws_asg} <= 0) {
|
||||
|
@ -177,7 +187,8 @@ __END__
|
|||
|
||||
=head1 MODE
|
||||
|
||||
Check EC2 Auto Scaling Groups and related instances status (number of instances within, state of each instances)
|
||||
Check EC2 Auto Scaling Groups and related instances status
|
||||
(number of instances within, state of each instances)
|
||||
|
||||
Example:
|
||||
perl centreon_plugins.pl --plugin=cloud::aws::ec2::plugin --custommode=paws --mode=asg-status --region='eu-west-1'
|
||||
|
@ -199,20 +210,23 @@ Filter by autoscaling group name (can be a regexp).
|
|||
=item B<--warning-instances>
|
||||
|
||||
Set warning threshold for status (Default: '').
|
||||
Can used special variables like: %{health}, %{lifecycle}
|
||||
Can use special variables like: %{health}, %{lifecycle}
|
||||
|
||||
=item B<--critical-instances>
|
||||
|
||||
Set critical threshold for instances states (Default: '%{health} =~ /Healthy/ && %{lifecycle} !~ /InService/').
|
||||
Can used special variables like: %{health}, %{lifecycle}
|
||||
Set critical threshold for instances states
|
||||
(Default: '%{health} =~ /Healthy/ && %{lifecycle} !~ /InService/').
|
||||
Can use special variables like: %{health}, %{lifecycle}
|
||||
|
||||
=item B<--warning-count>
|
||||
=item B<--warning-asg-instance-current>
|
||||
|
||||
Threshold warning about number of instances in the autoscaling group
|
||||
Threshold warning about number of
|
||||
instances in the autoscaling group
|
||||
|
||||
=item B<--critical-count>
|
||||
=item B<--critical-asg-instance-current>
|
||||
|
||||
Threshold critical about number of instances in the autoscaling group
|
||||
Threshold critical about number of
|
||||
instances in the autoscaling group
|
||||
|
||||
=back
|
||||
|
||||
|
|
|
@ -25,6 +25,34 @@ use base qw(centreon::plugins::templates::counter);
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
my %metrics_mapping = (
|
||||
'CPUUtilization' => {
|
||||
'output' => 'CPU Utilization',
|
||||
'label' => 'cpu-utilization',
|
||||
'nlabel' => 'ec2.cpu.utilization.percentage',
|
||||
},
|
||||
'CPUCreditBalance' => {
|
||||
'output' => 'CPU Credit Balance',
|
||||
'label' => 'cpu-credit-balance',
|
||||
'nlabel' => 'ec2.cpu.credit.balance.count',
|
||||
},
|
||||
'CPUCreditUsage' => {
|
||||
'output' => 'CPU Credit Usage',
|
||||
'label' => 'cpu-credit-usage',
|
||||
'nlabel' => 'ec2.cpu.credit.usage.count',
|
||||
},
|
||||
'CPUSurplusCreditBalance' => {
|
||||
'output' => 'CPU Surplus Credit Balance',
|
||||
'label' => 'cpu-credit-surplus-balance',
|
||||
'nlabel' => 'ec2.cpu.credit.surplus.balance.count',
|
||||
},
|
||||
'CPUSurplusCreditsCharged' => {
|
||||
'output' => 'CPU Surplus Credit Charged',
|
||||
'label' => 'cpu-credit-surplus-charged',
|
||||
'nlabel' => 'ec2.cpu.credit.surplus.charged.count',
|
||||
},
|
||||
);
|
||||
|
||||
my %map_type = (
|
||||
"instance" => "InstanceId",
|
||||
"asg" => "AutoScalingGroupName",
|
||||
|
@ -33,47 +61,53 @@ my %map_type = (
|
|||
sub prefix_metric_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return ucfirst($options{instance_value}->{type}) . " '" . $options{instance_value}->{display} . "' " . $options{instance_value}->{stat} . " ";
|
||||
return ucfirst($options{instance_value}->{type}) . " '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub prefix_statistics_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Statistic '" . $options{instance_value}->{display} . "' Metrics ";
|
||||
}
|
||||
|
||||
sub long_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Checking " . ucfirst($self->{option_results}->{type}) . " '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', message_multiple => "All CPU metrics are ok", skipped_code => { -10 => 1 } },
|
||||
{ name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output',
|
||||
message_multiple => 'All CPU metrics are ok', indent_long_output => ' ',
|
||||
group => [
|
||||
{ name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output',
|
||||
message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } },
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
foreach my $statistic ('minimum', 'maximum', 'average', 'sum') {
|
||||
foreach my $metric ('CPUCreditBalance', 'CPUCreditUsage', 'CPUSurplusCreditBalance', 'CPUSurplusCreditsCharged') {
|
||||
my $entry = { label => lc($metric) . '-' . lc($statistic), set => {
|
||||
key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'type' }, { name => 'stat' } ],
|
||||
output_template => $metric . ': %.2f',
|
||||
perfdatas => [
|
||||
{ label => lc($metric) . '_' . lc($statistic), value => $metric . '_' . $statistic . '_absolute',
|
||||
template => '%.2f', label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
};
|
||||
push @{$self->{maps_counters}->{metric}}, $entry;
|
||||
}
|
||||
foreach my $metric ('CPUUtilization') {
|
||||
my $entry = { label => lc($metric) . '-' . lc($statistic), set => {
|
||||
key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'type' }, { name => 'stat' } ],
|
||||
output_template => $metric . ': %.2f %%',
|
||||
perfdatas => [
|
||||
{ label => lc($metric) . '_' . lc($statistic), value => $metric . '_' . $statistic . '_absolute',
|
||||
template => '%.2f', unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
};
|
||||
push @{$self->{maps_counters}->{metric}}, $entry;
|
||||
}
|
||||
foreach my $metric (keys %metrics_mapping) {
|
||||
my $entry = {
|
||||
label => $metrics_mapping{$metric}->{label},
|
||||
nlabel => $metrics_mapping{$metric}->{nlabel},
|
||||
set => {
|
||||
key_values => [ { name => $metric }, { name => 'display' } ],
|
||||
output_template => $metrics_mapping{$metric}->{output} . ': %.2f',
|
||||
perfdatas => [
|
||||
{ value => $metric . '_absolute', template => '%.2f', label_extra_instance => 1 }
|
||||
],
|
||||
}
|
||||
};
|
||||
push @{$self->{maps_counters}->{statistics}}, $entry;
|
||||
}
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
|
@ -123,8 +157,7 @@ sub check_options {
|
|||
}
|
||||
}
|
||||
|
||||
foreach my $metric ('CPUCreditBalance', 'CPUCreditUsage', 'CPUSurplusCreditBalance',
|
||||
'CPUSurplusCreditsCharged', 'CPUUtilization') {
|
||||
foreach my $metric (keys %metrics_mapping) {
|
||||
next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
|
||||
&& $metric !~ /$self->{option_results}->{filter_metric}/);
|
||||
|
||||
|
@ -149,17 +182,20 @@ sub manage_selection {
|
|||
|
||||
foreach my $metric (@{$self->{aws_metrics}}) {
|
||||
foreach my $statistic (@{$self->{aws_statistics}}) {
|
||||
next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed}));
|
||||
next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) &&
|
||||
!defined($self->{option_results}->{zeroed}));
|
||||
|
||||
$self->{metric}->{$instance . "_" . lc($statistic)}->{display} = $instance;
|
||||
$self->{metric}->{$instance . "_" . lc($statistic)}->{type} = $self->{option_results}->{type};
|
||||
$self->{metric}->{$instance . "_" . lc($statistic)}->{stat} = lc($statistic);
|
||||
$self->{metric}->{$instance . "_" . lc($statistic)}->{$metric . "_" . lc($statistic)} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0;
|
||||
$self->{metrics}->{$instance}->{display} = $instance;
|
||||
$self->{metrics}->{$instance}->{type} = $self->{option_results}->{type};
|
||||
$self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic;
|
||||
$self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} =
|
||||
defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ?
|
||||
$metric_results{$instance}->{$metric}->{lc($statistic)} : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{metric}}) <= 0) {
|
||||
if (scalar(keys %{$self->{metrics}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values');
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
@ -176,9 +212,9 @@ Check EC2 instances CPU metrics.
|
|||
Example:
|
||||
perl centreon_plugins.pl --plugin=cloud::aws::ec2::plugin --custommode=paws --mode=cpu --region='eu-west-1'
|
||||
--type='asg' --name='centreon-middleware' --filter-metric='Credit' --statistic='average'
|
||||
--critical-cpucreditusage-average='10' --verbose
|
||||
--critical-cpu-credit-usage='10' --verbose
|
||||
|
||||
See 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ec2-metricscollected.html' for more informations.
|
||||
See 'https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/viewing_metrics_with_cloudwatch.html' for more informations.
|
||||
|
||||
Default statistic: 'average' / All satistics are valid.
|
||||
|
||||
|
@ -198,17 +234,10 @@ Filter metrics (Can be: 'CPUCreditBalance', 'CPUCreditUsage',
|
|||
'CPUSurplusCreditBalance', 'CPUSurplusCreditsCharged', 'CPUUtilization')
|
||||
(Can be a regexp).
|
||||
|
||||
=item B<--warning-$metric$-$statistic$>
|
||||
=item B<--warning-*> B<--critical-*>
|
||||
|
||||
Thresholds warning ($metric$ can be: 'cpucreditusage', 'cpucreditbalance',
|
||||
'cpusurpluscreditbalance', 'cpusurpluscreditscharged', 'cpuutilization',
|
||||
$statistic$ can be: 'minimum', 'maximum', 'average', 'sum').
|
||||
|
||||
=item B<--critical-$metric$-$statistic$>
|
||||
|
||||
Thresholds critical ($metric$ can be: 'cpucreditusage', 'cpucreditbalance',
|
||||
'cpusurpluscreditbalance', 'cpusurpluscreditscharged', 'cpuutilization',
|
||||
$statistic$ can be: 'minimum', 'maximum', 'average', 'sum').
|
||||
Thresholds warning (Can be 'cpu-credit-usage', 'cpu-credit-balance',
|
||||
'cpu-credit-surplus-balance', 'cpu-credit-surplus-charged', 'cpu-utilization').
|
||||
|
||||
=back
|
||||
|
||||
|
|
|
@ -25,6 +25,45 @@ use base qw(centreon::plugins::templates::counter);
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
my %metrics_mapping = (
|
||||
'DiskReadBytes' => {
|
||||
'output' => 'Disk Read Bytes',
|
||||
'label' => 'disk-bytes-read',
|
||||
'nlabel' => {
|
||||
'absolute' => 'ec2.disk.bytes.read.bytes',
|
||||
'per_second' => 'ec2.disk.bytes.read.bytespersecond',
|
||||
},
|
||||
'unit' => 'B',
|
||||
},
|
||||
'DiskWriteBytes' => {
|
||||
'output' => 'Disk Write Bytes',
|
||||
'label' => 'disk-bytes-write',
|
||||
'nlabel' => {
|
||||
'absolute' => 'ec2.disk.bytes.write.bytes',
|
||||
'per_second' => 'ec2.disk.bytes.write.bytespersecond',
|
||||
},
|
||||
'unit' => 'B',
|
||||
},
|
||||
'DiskReadOps' => {
|
||||
'output' => 'Disk Read Ops',
|
||||
'label' => 'disk-ops-read',
|
||||
'nlabel' => {
|
||||
'absolute' => 'ec2.disk.ops.read.count',
|
||||
'per_second' => 'ec2.disk.ops.read.persecond',
|
||||
},
|
||||
'unit' => 'ops',
|
||||
},
|
||||
'DiskWriteOps' => {
|
||||
'output' => 'Disk Write Ops',
|
||||
'label' => 'disk-ops-write',
|
||||
'nlabel' => {
|
||||
'absolute' => 'ec2.disk.ops.write.count',
|
||||
'per_second' => 'ec2.disk.ops.write.persecond',
|
||||
},
|
||||
'unit' => 'ops',
|
||||
},
|
||||
);
|
||||
|
||||
my %map_type = (
|
||||
"instance" => "InstanceId",
|
||||
"asg" => "AutoScalingGroupName",
|
||||
|
@ -33,124 +72,111 @@ my %map_type = (
|
|||
sub prefix_metric_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return ucfirst($options{instance_value}->{type}) . " '" . $options{instance_value}->{display} . "' " . $options{instance_value}->{stat} . " ";
|
||||
return ucfirst($self->{option_results}->{type}) . " '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub prefix_statistics_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Statistic '" . $options{instance_value}->{display} . "' Metrics ";
|
||||
}
|
||||
|
||||
sub long_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Checking " . ucfirst($self->{option_results}->{type}) . " '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub custom_metric_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{timeframe} = $options{new_datas}->{$self->{instance} . '_timeframe'};
|
||||
$self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{metric} . '_' . $options{extra_options}->{stat}};
|
||||
$self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{metric}};
|
||||
$self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe};
|
||||
$self->{result_values}->{stat} = $options{extra_options}->{stat};
|
||||
$self->{result_values}->{metric} = $options{extra_options}->{metric};
|
||||
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub custom_metric_threshold {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value},
|
||||
threshold => [ { label => 'critical-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat}), exit_litteral => 'critical' },
|
||||
{ label => 'warning-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat}), exit_litteral => 'warning' } ]);
|
||||
my $exit = $self->{perfdata}->threshold_check(
|
||||
value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value},
|
||||
threshold => [ { label => 'critical-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'critical' },
|
||||
{ label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'warning' } ]);
|
||||
return $exit;
|
||||
}
|
||||
|
||||
sub custom_usage_perfdata {
|
||||
sub custom_metric_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
|
||||
|
||||
$self->{output}->perfdata_add(label => lc($self->{result_values}->{metric}) . "_" . lc($self->{result_values}->{stat}) . $extra_label,
|
||||
unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'B/s' : 'B',
|
||||
value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})),
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
instances => $self->{instance},
|
||||
label => $metrics_mapping{$self->{result_values}->{metric}}->{label},
|
||||
nlabel => defined($self->{instance_mode}->{option_results}->{per_sec}) ?
|
||||
$metrics_mapping{$self->{result_values}->{metric}}->{nlabel}->{per_second} :
|
||||
$metrics_mapping{$self->{result_values}->{metric}}->{nlabel}->{absolute},
|
||||
unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ?
|
||||
$metrics_mapping{$self->{result_values}->{metric}}->{unit} . '/s' :
|
||||
$metrics_mapping{$self->{result_values}->{metric}}->{unit},
|
||||
value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ?
|
||||
$self->{result_values}->{value_per_sec} :
|
||||
$self->{result_values}->{value}),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}),
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_usage_output {
|
||||
sub custom_metric_output {
|
||||
my ($self, %options) = @_;
|
||||
my $msg = "";
|
||||
|
||||
if (defined($self->{instance_mode}->{option_results}->{per_sec})) {
|
||||
my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value_per_sec});
|
||||
$msg = $self->{result_values}->{metric} . ": " . $value . $unit . "/s";
|
||||
my ($value, $unit) = ($metrics_mapping{$self->{result_values}->{metric}}->{unit} eq 'B') ?
|
||||
$self->{perfdata}->change_bytes(value => $self->{result_values}->{value_per_sec}) :
|
||||
($self->{result_values}->{value_per_sec}, $metrics_mapping{$self->{result_values}->{metric}}->{unit});
|
||||
$msg = sprintf("%s: %.2f %s", $metrics_mapping{$self->{result_values}->{metric}}->{output}, $value, $unit . '/s');
|
||||
} else {
|
||||
my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value});
|
||||
$msg = $self->{result_values}->{metric} . ": " . $value . $unit;
|
||||
my ($value, $unit) = ($metrics_mapping{$self->{result_values}->{metric}}->{unit} eq 'B') ?
|
||||
$self->{perfdata}->change_bytes(value => $self->{result_values}->{value}) :
|
||||
($self->{result_values}->{value}, $metrics_mapping{$self->{result_values}->{metric}}->{unit});
|
||||
$msg = sprintf("%s: %.2f %s", $metrics_mapping{$self->{result_values}->{metric}}->{output}, $value, $unit);
|
||||
}
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_ops_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
|
||||
|
||||
$self->{output}->perfdata_add(label => lc($self->{result_values}->{metric}) . "_" . lc($self->{result_values}->{stat}) . $extra_label,
|
||||
unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'ops/s' : 'ops',
|
||||
value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})),
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_ops_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg ="";
|
||||
|
||||
if (defined($self->{instance_mode}->{option_results}->{per_sec})) {
|
||||
$msg = sprintf("%s: %.2f ops/s", $self->{result_values}->{metric}, $self->{result_values}->{value_per_sec});
|
||||
} else {
|
||||
$msg = sprintf("%s: %.2f ops", $self->{result_values}->{metric}, $self->{result_values}->{value});
|
||||
}
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', message_multiple => "All disk metrics are ok", skipped_code => { -10 => 1 } },
|
||||
{ name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output',
|
||||
message_multiple => 'All disks metrics are ok', indent_long_output => ' ',
|
||||
group => [
|
||||
{ name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output',
|
||||
message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } },
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
foreach my $statistic ('minimum', 'maximum', 'average', 'sum') {
|
||||
foreach my $metric ('DiskReadBytes', 'DiskWriteBytes') {
|
||||
my $entry = { label => lc($metric) . '-' . lc($statistic), set => {
|
||||
key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'stat' }, { name => 'timeframe' } ],
|
||||
closure_custom_calc => $self->can('custom_metric_calc'),
|
||||
closure_custom_calc_extra_options => { metric => $metric, stat => $statistic },
|
||||
closure_custom_output => $self->can('custom_usage_output'),
|
||||
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_metric_threshold'),
|
||||
}
|
||||
};
|
||||
push @{$self->{maps_counters}->{metric}}, $entry;
|
||||
}
|
||||
foreach my $metric ('DiskReadOps', 'DiskWriteOps') {
|
||||
my $entry = { label => lc($metric) . '-' . lc($statistic), set => {
|
||||
key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'stat' }, { name => 'timeframe' } ],
|
||||
closure_custom_calc => $self->can('custom_metric_calc'),
|
||||
closure_custom_calc_extra_options => { metric => $metric, stat => $statistic },
|
||||
closure_custom_output => $self->can('custom_ops_output'),
|
||||
closure_custom_perfdata => $self->can('custom_ops_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_metric_threshold'),
|
||||
}
|
||||
};
|
||||
push @{$self->{maps_counters}->{metric}}, $entry;
|
||||
}
|
||||
foreach my $metric (keys %metrics_mapping) {
|
||||
my $entry = {
|
||||
label => $metrics_mapping{$metric}->{label},
|
||||
set => {
|
||||
key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ],
|
||||
closure_custom_calc => $self->can('custom_metric_calc'),
|
||||
closure_custom_calc_extra_options => { metric => $metric },
|
||||
closure_custom_output => $self->can('custom_metric_output'),
|
||||
closure_custom_perfdata => $self->can('custom_metric_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_metric_threshold'),
|
||||
}
|
||||
};
|
||||
push @{$self->{maps_counters}->{statistics}}, $entry;
|
||||
}
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
|
@ -201,7 +227,7 @@ sub check_options {
|
|||
}
|
||||
}
|
||||
|
||||
foreach my $metric ('DiskReadBytes', 'DiskWriteBytes', 'DiskReadOps', 'DiskWriteOps') {
|
||||
foreach my $metric (keys %metrics_mapping) {
|
||||
next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
|
||||
&& $metric !~ /$self->{option_results}->{filter_metric}/);
|
||||
|
||||
|
@ -223,21 +249,23 @@ sub manage_selection {
|
|||
timeframe => $self->{aws_timeframe},
|
||||
period => $self->{aws_period},
|
||||
);
|
||||
|
||||
|
||||
foreach my $metric (@{$self->{aws_metrics}}) {
|
||||
foreach my $statistic (@{$self->{aws_statistics}}) {
|
||||
next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed}));
|
||||
next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) &&
|
||||
!defined($self->{option_results}->{zeroed}));
|
||||
|
||||
$self->{metric}->{$instance . "_" . lc($statistic)}->{display} = $instance;
|
||||
$self->{metric}->{$instance . "_" . lc($statistic)}->{type} = $self->{option_results}->{type};
|
||||
$self->{metric}->{$instance . "_" . lc($statistic)}->{stat} = lc($statistic);
|
||||
$self->{metric}->{$instance . "_" . lc($statistic)}->{timeframe} = $self->{aws_timeframe};
|
||||
$self->{metric}->{$instance . "_" . lc($statistic)}->{$metric . "_" . lc($statistic)} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0;
|
||||
$self->{metrics}->{$instance}->{display} = $instance;
|
||||
$self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic;
|
||||
$self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{timeframe} = $self->{aws_timeframe};
|
||||
$self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} =
|
||||
defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ?
|
||||
$metric_results{$instance}->{$metric}->{lc($statistic)} : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{metric}}) <= 0) {
|
||||
if (scalar(keys %{$self->{metrics}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values');
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
@ -253,7 +281,7 @@ Check EC2 instances disk IO metrics.
|
|||
|
||||
Example:
|
||||
perl centreon_plugins.pl --plugin=cloud::aws::ec2::plugin --custommode=paws --mode=diskio --region='eu-west-1'
|
||||
--type='asg' --name='centreon-middleware' --filter-metric='Read' --statistic='sum' --critical-diskreadops-sum='10'
|
||||
--type='asg' --name='centreon-middleware' --filter-metric='Read' --statistic='sum' --critical-disk-ops-read='10'
|
||||
--verbose
|
||||
|
||||
See 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ec2-metricscollected.html' for more informations.
|
||||
|
@ -276,17 +304,10 @@ Filter metrics (Can be: 'DiskReadBytes', 'DiskWriteBytes',
|
|||
'DiskReadOps', 'DiskWriteOps')
|
||||
(Can be a regexp).
|
||||
|
||||
=item B<--warning-$metric$-$statistic$>
|
||||
=item B<--warning-*> B<--critical-*>
|
||||
|
||||
Thresholds warning ($metric$ can be: 'diskreadbytes', 'diskwritebytes',
|
||||
'diskreadops', 'diskwriteops',
|
||||
$statistic$ can be: 'minimum', 'maximum', 'average', 'sum').
|
||||
|
||||
=item B<--critical-$metric$-$statistic$>
|
||||
|
||||
Thresholds critical ($metric$ can be: 'diskreadbytes', 'diskwritebytes',
|
||||
'diskreadops', 'diskwriteops',
|
||||
$statistic$ can be: 'minimum', 'maximum', 'average', 'sum').
|
||||
Thresholds warning (Can be 'disk-bytes-read', 'disk-bytes-write',
|
||||
'disk-ops-read', 'disk-ops-write').
|
||||
|
||||
=item B<--per-sec>
|
||||
|
||||
|
|
|
@ -47,55 +47,56 @@ sub set_counters {
|
|||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
|
||||
{ name => 'aws_instances', type => 1, cb_prefix_output => 'prefix_awsinstance_output', message_multiple => 'All instances are ok' },
|
||||
{ name => 'aws_instances', type => 1, cb_prefix_output => 'prefix_awsinstance_output',
|
||||
message_multiple => 'All instances are ok' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'total-pending', set => {
|
||||
{ label => 'pending', nlabel => 'ec2.instances.status.pending.count', set => {
|
||||
key_values => [ { name => 'pending' } ],
|
||||
output_template => "pending : %s",
|
||||
output_template => "Pending : %s",
|
||||
perfdatas => [
|
||||
{ label => 'total_pending', value => 'pending_absolute', template => '%d', min => 0 },
|
||||
{ value => 'pending_absolute', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-running', set => {
|
||||
{ label => 'running', nlabel => 'ec2.instances.status.running.count', set => {
|
||||
key_values => [ { name => 'running' } ],
|
||||
output_template => "running : %s",
|
||||
output_template => "Running : %s",
|
||||
perfdatas => [
|
||||
{ label => 'total_running', value => 'running_absolute', template => '%d', min => 0 },
|
||||
{ value => 'running_absolute', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-shutting-down', set => {
|
||||
{ label => 'shuttingdown', nlabel => 'ec2.instances.status.shuttingdown.count', set => {
|
||||
key_values => [ { name => 'shutting-down' } ],
|
||||
output_template => "shutting-down : %s",
|
||||
output_template => "Shutting Down : %s",
|
||||
perfdatas => [
|
||||
{ label => 'total_shutting_down', value => 'shutting-down_absolute', template => '%d', min => 0 },
|
||||
{ value => 'shutting-down_absolute', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-terminated', set => {
|
||||
{ label => 'terminated', nlabel => 'ec2.instances.status.terminated.count', set => {
|
||||
key_values => [ { name => 'terminated' } ],
|
||||
output_template => "terminated : %s",
|
||||
output_template => "Terminated : %s",
|
||||
perfdatas => [
|
||||
{ label => 'total_terminated', value => 'terminated_absolute', template => '%d', min => 0 },
|
||||
{ value => 'terminated_absolute', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-stopping', set => {
|
||||
{ label => 'stopping', nlabel => 'ec2.instances.status.stopping.count', set => {
|
||||
key_values => [ { name => 'stopping' } ],
|
||||
output_template => "stopping : %s",
|
||||
output_template => "Stopping : %s",
|
||||
perfdatas => [
|
||||
{ label => 'total_stopping', value => 'stopping_absolute', template => '%d', min => 0 },
|
||||
{ value => 'stopping_absolute', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'total-stopped', set => {
|
||||
{ label => 'stopped', nlabel => 'ec2.instances.status.stopped.count', set => {
|
||||
key_values => [ { name => 'stopped' } ],
|
||||
output_template => "stopped : %s",
|
||||
output_template => "Stopped : %s",
|
||||
perfdatas => [
|
||||
{ label => 'total_stopped', value => 'stopped_absolute', template => '%d', min => 0 },
|
||||
{ value => 'stopped_absolute', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
|
@ -115,16 +116,15 @@ sub set_counters {
|
|||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"region:s" => { name => 'region' },
|
||||
"filter-instanceid:s" => { name => 'filter_instanceid' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '' },
|
||||
});
|
||||
$options{options}->add_options(arguments => {
|
||||
"region:s" => { name => 'region' },
|
||||
"filter-instanceid:s" => { name => 'filter_instanceid' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ Check EC2 instances status.
|
|||
|
||||
Example:
|
||||
perl centreon_plugins.pl --plugin=cloud::aws::ec2::plugin --custommode=paws --mode=instances-status --region='eu-west-1'
|
||||
--filter-instanceid='.*' --filter-counters='^total-running$' --critical-total-running='10' --verbose
|
||||
--filter-instanceid='.*' --filter-counters='^running$' --critical-running='10' --verbose
|
||||
|
||||
See 'https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstanceStatus.html' for more informations.
|
||||
|
||||
|
@ -201,7 +201,7 @@ See 'https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstance
|
|||
=item B<--filter-counters>
|
||||
|
||||
Only display some counters (regexp can be used).
|
||||
Example: --filter-counters='^total-running$'
|
||||
Example: --filter-counters='^running$'
|
||||
|
||||
=item B<--filter-instanceid>
|
||||
|
||||
|
@ -217,17 +217,11 @@ Can used special variables like: %{state}, %{display}
|
|||
Set critical threshold for status (Default: '').
|
||||
Can used special variables like: %{state}, %{display}
|
||||
|
||||
=item B<--warning-*>
|
||||
=item B<--warning-*> B<--critical-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'total-pending', 'total-running', 'total-shutting-down',
|
||||
'total-terminated', 'total-stopping', 'total-stopped'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'total-pending', 'total-running', 'total-shutting-down',
|
||||
'total-terminated', 'total-stopping', 'total-stopped'.
|
||||
Can be: 'pending', 'running', 'shuttingdown',
|
||||
'terminated', 'stopping', 'stopped'.
|
||||
|
||||
=back
|
||||
|
||||
|
|
|
@ -25,71 +25,121 @@ use base qw(centreon::plugins::templates::counter);
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
my %spot_types = (
|
||||
'general' => ['t2.nano', 't2.micro', 't2.small', 't2.medium', 't2.large', 't2.xlarge', 't2.2xlarge', 'm4.large',
|
||||
'm4.xlarge', 'm4.2xlarge', 'm4.4xlarge', 'm4.10xlarge', 'm4.16xlarge', 'm5.large', 'm5.xlarge',
|
||||
'm5.2xlarge', 'm5.4xlarge', 'm5.12xlarge', 'm5.24xlarge'],
|
||||
'compute' => ['c4.large', 'c4.xlarge', 'c4.2xlarge', 'c4.4xlarge', 'c4.8xlarge', 'c5.large',
|
||||
'c5.xlarge', 'c5.2xlarge', 'c5.4xlarge', 'c5.9xlarge', 'c5.18xlarge'],
|
||||
'memory' => ['r4.large', 'r4.xlarge', 'r4.2xlarge', 'r4.4xlarge', 'r4.8xlarge', 'r4.16xlarge',
|
||||
'x1.16xlarge', 'x1.32xlarge', 'x1e.xlarge', 'x1e.2xlarge', 'x1e.4xlarge', 'x1e.8xlarge', 'x1e.16xlarge',
|
||||
'x1e.32xlarge'],
|
||||
'storage' => ['r4.large', 'r4.xlarge', 'r4.2xlarge', 'r4.4xlarge', 'r4.8xlarge', 'r4.16xlarge',
|
||||
'x1.16xlarge', 'x1.32xlarge', 'x1e.xlarge', 'x1e.2xlarge', 'x1e.4xlarge', 'x1e.8xlarge', 'x1e.16xlarge',
|
||||
'x1e.32xlarge'],
|
||||
'accelerated' => ['f1.2xlarge', 'f1.16xlarge', 'g3.4xlarge', 'g3.8xlarge', 'g3.16xlarge', 'p2.xlarge',
|
||||
'p2.8xlarge', 'p2.16xlarge', 'p3.2xlarge', 'p3.8xlarge', 'p3.16xlarge'],
|
||||
my %family_mapping = (
|
||||
'general' => {
|
||||
'prefix_output' => 'prefix_general_output',
|
||||
'types' => [
|
||||
'a1.medium', 'a1.large', 'a1.xlarge', 'a1.2xlarge', 'a1.4xlarge', 'm4.large',
|
||||
'm4.xlarge', 'm4.2xlarge', 'm4.4xlarge', 'm4.10xlarge', 'm4.16xlarge', 'm5.large',
|
||||
'm5.xlarge', 'm5.2xlarge', 'm5.4xlarge', 'm5.8xlarge', 'm5.12xlarge', 'm5.16xlarge',
|
||||
'm5.24xlarge', 'm5.metal', 'm5a.large', 'm5a.xlarge', 'm5a.2xlarge', 'm5a.4xlarge',
|
||||
'm5a.8xlarge', 'm5a.12xlarge', 'm5a.16xlarge', 'm5a.24xlarge', 'm5ad.large',
|
||||
'm5ad.xlarge', 'm5ad.2xlarge', 'm5ad.4xlarge', 'm5ad.12xlarge', 'm5ad.24xlarge',
|
||||
'm5d.large', 'm5d.xlarge', 'm5d.2xlarge', 'm5d.4xlarge', 'm5d.8xlarge', 'm5d.12xlarge',
|
||||
'm5d.16xlarge', 'm5d.24xlarge', 'm5d.metal', 't2.nano', 't2.micro', 't2.small',
|
||||
't2.medium', 't2.large', 't2.xlarge', 't2.2xlarge', 't3.nano', 't3.micro', 't3.small',
|
||||
't3.medium', 't3.large', 't3.xlarge', 't3.2xlarge', 't3a.nano', 't3a.micro', 't3a.small',
|
||||
't3a.medium', 't3a.large', 't3a.xlarge', 't3a.2xlarge'
|
||||
],
|
||||
},
|
||||
'compute' => {
|
||||
'prefix_output' => 'prefix_compute_output',
|
||||
'types' => [
|
||||
'c4.large', 'c4.xlarge', 'c4.2xlarge', 'c4.4xlarge', 'c4.8xlarge', 'c5.large',
|
||||
'c5.xlarge', 'c5.2xlarge', 'c5.4xlarge', 'c5.9xlarge', 'c5.12xlarge', 'c5.18xlarge',
|
||||
'c5.24xlarge', 'c5.metal', 'c5d.large', 'c5d.xlarge', 'c5d.2xlarge', 'c5d.4xlarge',
|
||||
'c5d.9xlarge', 'c5d.18xlarge', 'c5n.large', 'c5n.xlarge', 'c5n.2xlarge', 'c5n.4xlarge',
|
||||
'c5n.9xlarge', 'c5n.18xlarge'
|
||||
],
|
||||
},
|
||||
'memory' => {
|
||||
'prefix_output' => 'prefix_memory_output',
|
||||
'types' => [
|
||||
'r4.large', 'r4.xlarge', 'r4.2xlarge', 'r4.4xlarge', 'r4.8xlarge', 'r4.16xlarge',
|
||||
'r5.large', 'r5.xlarge', 'r5.2xlarge', 'r5.4xlarge', 'r5.8xlarge', 'r5.12xlarge',
|
||||
'r5.16xlarge', 'r5.24xlarge', 'r5.metal', 'r5a.large', 'r5a.xlarge', 'r5a.2xlarge',
|
||||
'r5a.4xlarge', 'r5a.8xlarge', 'r5a.12xlarge', 'r5a.16xlarge', 'r5a.24xlarge', 'r5ad.large',
|
||||
'r5ad.xlarge', 'r5ad.2xlarge', 'r5ad.4xlarge', 'r5ad.12xlarge', 'r5ad.24xlarge', 'r5d.large',
|
||||
'r5d.xlarge', 'r5d.2xlarge', 'r5d.4xlarge', 'r5d.8xlarge', 'r5d.12xlarge', 'r5d.16xlarge',
|
||||
'r5d.24xlarge', 'r5d.metal', 'u-6tb1.metal', 'u-9tb1.metal', 'u-12tb1.metal', 'x1.16xlarge',
|
||||
'x1.32xlarge', 'x1e.xlarge', 'x1e.2xlarge', 'x1e.4xlarge', 'x1e.8xlarge', 'x1e.16xlarge',
|
||||
'x1e.32xlarge', 'z1d.large', 'z1d.xlarge', 'z1d.2xlarge', 'z1d.3xlarge', 'z1d.6xlarge',
|
||||
'z1d.12xlarge', 'z1d.metal'
|
||||
],
|
||||
},
|
||||
'storage' => {
|
||||
'prefix_output' => 'prefix_storage_output',
|
||||
'types' => [
|
||||
'd2.xlarge', 'd2.2xlarge', 'd2.4xlarge', 'd2.8xlarge', 'h1.2xlarge', 'h1.4xlarge',
|
||||
'h1.8xlarge', 'h1.16xlarge', 'i3.large', 'i3.xlarge', 'i3.2xlarge', 'i3.4xlarge',
|
||||
'i3.8xlarge', 'i3.16xlarge', 'i3.metal', 'i3en.large', 'i3en.xlarge', 'i3en.2xlarge',
|
||||
'i3en.3xlarge', 'i3en.6xlarge', 'i3en.12xlarge', 'i3en.24xlarge'
|
||||
],
|
||||
},
|
||||
'accelerated' => {
|
||||
'prefix_output' => 'prefix_accelerated_output',
|
||||
'types' => [
|
||||
'f1.2xlarge', 'f1.4xlarge', 'f1.16xlarge', 'g3s.xlarge', 'g3.4xlarge', 'g3.8xlarge',
|
||||
'g3.16xlarge', 'p2.xlarge', 'p2.8xlarge', 'p2.16xlarge', 'p3.2xlarge', 'p3.8xlarge',
|
||||
'p3.16xlarge', 'p3dn.24xlarge'
|
||||
],
|
||||
},
|
||||
);
|
||||
|
||||
sub prefix_general_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Spot family 'General purpose' instance types count ";
|
||||
return "Spot family 'General purpose' instances count ";
|
||||
}
|
||||
|
||||
sub prefix_compute_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Spot family 'Compute optimized' instance types count ";
|
||||
return "Spot family 'Compute optimized' instances count ";
|
||||
}
|
||||
|
||||
sub prefix_memory_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Spot family 'Memory optimized' instance types count ";
|
||||
return "Spot family 'Memory optimized' instances count ";
|
||||
}
|
||||
|
||||
sub prefix_storage_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Spot family 'Storage optimized' instance types count ";
|
||||
return "Spot family 'Storage optimized' instances count ";
|
||||
}
|
||||
|
||||
sub prefix_accelerated_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Spot family 'Accelerated computing' instance types count ";
|
||||
return "Spot family 'Accelerated computing' instances count ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach my $family (keys %spot_types) {
|
||||
my $counter = { name => $family, type => 0, cb_prefix_output => 'prefix_' . $family . '_output', skipped_code => { -10 => 1 } };
|
||||
foreach my $family (keys %family_mapping) {
|
||||
my $counter = {
|
||||
name => $family,
|
||||
type => 0,
|
||||
cb_prefix_output => $family_mapping{$family}->{prefix_output},
|
||||
skipped_code => { -10 => 1 } };
|
||||
|
||||
push @{$self->{maps_counters_type}}, $counter;
|
||||
|
||||
$self->{maps_counters}->{$family} = [];
|
||||
|
||||
foreach my $type (@{$spot_types{$family}}) {
|
||||
my $entry = { label => $type, set => {
|
||||
key_values => [ { name => $type } ],
|
||||
output_template => $type . ": %s",
|
||||
perfdatas => [
|
||||
{ label => $type, value => $type . '_absolute', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
};
|
||||
foreach my $type (@{$family_mapping{$family}->{types}}) {
|
||||
my $entry = {
|
||||
label => $type, nlabel => 'ec2.instances.type.' . $family . '.' . $type . '.count', set => {
|
||||
key_values => [ { name => $type } ],
|
||||
output_template => $type . ": %s",
|
||||
perfdatas => [
|
||||
{ value => $type . '_absolute', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
};
|
||||
push @{$self->{maps_counters}->{$family}}, $entry;
|
||||
}
|
||||
}
|
||||
|
@ -97,16 +147,15 @@ sub set_counters {
|
|||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"region:s" => { name => 'region' },
|
||||
"filter-family:s" => { name => 'filter_family' },
|
||||
"filter-type:s" => { name => 'filter_type' },
|
||||
"running" => { name => 'running' },
|
||||
});
|
||||
$options{options}->add_options(arguments => {
|
||||
"region:s" => { name => 'region' },
|
||||
"filter-family:s" => { name => 'filter_family' },
|
||||
"filter-type:s" => { name => 'filter_type' },
|
||||
"running" => { name => 'running' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
@ -124,13 +173,13 @@ sub check_options {
|
|||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
foreach my $family (keys %spot_types) {
|
||||
foreach my $family (keys %family_mapping) {
|
||||
if (defined($self->{option_results}->{filter_family}) && $self->{option_results}->{filter_family} ne '' &&
|
||||
$family !~ /$self->{option_results}->{filter_family}/) {
|
||||
$self->{output}->output_add(long_msg => sprintf("skipping family '%s'", $family), debug => 1);
|
||||
$self->{maps_counters}->{$family} = undef;
|
||||
} else {
|
||||
foreach my $type (@{$spot_types{$family}}) {
|
||||
foreach my $type (@{$family_mapping{$family}->{types}}) {
|
||||
if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
|
||||
$type !~ /$self->{option_results}->{filter_type}/) {
|
||||
next;
|
||||
|
@ -150,8 +199,8 @@ sub manage_selection {
|
|||
next;
|
||||
}
|
||||
|
||||
foreach my $family (keys %spot_types) {
|
||||
$self->{$family}->{$instance->{InstanceType}}++ if (defined($self->{maps_counters}->{$family}) && map(/$instance->{InstanceType}/, @{$spot_types{$family}}));
|
||||
foreach my $family (keys %family_mapping) {
|
||||
$self->{$family}->{$instance->{InstanceType}}++ if (defined($self->{maps_counters}->{$family}) && map(/$instance->{InstanceType}/, @{$family_mapping{$family}->{types}}));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,31 +236,40 @@ Filter by instance family (regexp)
|
|||
|
||||
Filter by instance type (regexp)
|
||||
|
||||
=item B<--warning-*>
|
||||
=item B<--warning-*> B<--critical-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 't2.nano', 't2.micro', 't2.small', 't2.medium', 't2.large', 't2.xlarge', 't2.2xlarge', 'm4.large',
|
||||
'm4.xlarge', 'm4.2xlarge', 'm4.4xlarge', 'm4.10xlarge', 'm4.16xlarge', 'm5.large', 'm5.xlarge', 'm5.2xlarge',
|
||||
'm5.4xlarge', 'm5.12xlarge', 'm5.24xlarge', 'c4.large', 'c4.xlarge', 'c4.2xlarge', 'c4.4xlarge', 'c4.8xlarge',
|
||||
'c5.large', 'c5.xlarge', 'c5.2xlarge', 'c5.4xlarge', 'c5.9xlarge', 'c5.18xlarge', 'r4.large', 'r4.xlarge',
|
||||
'r4.2xlarge', 'r4.4xlarge', 'r4.8xlarge', 'r4.16xlarge', 'x1.16xlarge', 'x1.32xlarge', 'x1e.xlarge', 'x1e.2xlarge',
|
||||
'x1e.4xlarge', 'x1e.8xlarge', 'x1e.16xlarge', 'x1e.32xlarge', 'r4.large', 'r4.xlarge', 'r4.2xlarge', 'r4.4xlarge',
|
||||
'r4.8xlarge', 'r4.16xlarge', 'x1.16xlarge', 'x1.32xlarge', 'x1e.xlarge', 'x1e.2xlarge', 'x1e.4xlarge', 'x1e.8xlarge',
|
||||
'x1e.16xlarge', 'x1e.32xlarge', 'f1.2xlarge', 'f1.16xlarge', 'g3.4xlarge', 'g3.8xlarge', 'g3.16xlarge', 'p2.xlarge',
|
||||
'p2.8xlarge', 'p2.16xlarge', 'p3.2xlarge', 'p3.8xlarge', 'p3.16xlarge'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 't2.nano', 't2.micro', 't2.small', 't2.medium', 't2.large', 't2.xlarge', 't2.2xlarge', 'm4.large',
|
||||
'm4.xlarge', 'm4.2xlarge', 'm4.4xlarge', 'm4.10xlarge', 'm4.16xlarge', 'm5.large', 'm5.xlarge', 'm5.2xlarge',
|
||||
'm5.4xlarge', 'm5.12xlarge', 'm5.24xlarge', 'c4.large', 'c4.xlarge', 'c4.2xlarge', 'c4.4xlarge', 'c4.8xlarge',
|
||||
'c5.large', 'c5.xlarge', 'c5.2xlarge', 'c5.4xlarge', 'c5.9xlarge', 'c5.18xlarge', 'r4.large', 'r4.xlarge',
|
||||
'r4.2xlarge', 'r4.4xlarge', 'r4.8xlarge', 'r4.16xlarge', 'x1.16xlarge', 'x1.32xlarge', 'x1e.xlarge', 'x1e.2xlarge',
|
||||
'x1e.4xlarge', 'x1e.8xlarge', 'x1e.16xlarge', 'x1e.32xlarge', 'r4.large', 'r4.xlarge', 'r4.2xlarge', 'r4.4xlarge',
|
||||
'r4.8xlarge', 'r4.16xlarge', 'x1.16xlarge', 'x1.32xlarge', 'x1e.xlarge', 'x1e.2xlarge', 'x1e.4xlarge', 'x1e.8xlarge',
|
||||
'x1e.16xlarge', 'x1e.32xlarge', 'f1.2xlarge', 'f1.16xlarge', 'g3.4xlarge', 'g3.8xlarge', 'g3.16xlarge', 'p2.xlarge',
|
||||
'p2.8xlarge', 'p2.16xlarge', 'p3.2xlarge', 'p3.8xlarge', 'p3.16xlarge'.
|
||||
Can be: 'a1.medium', 'a1.large', 'a1.xlarge', 'a1.2xlarge', 'a1.4xlarge', 'm4.large',
|
||||
'm4.xlarge', 'm4.2xlarge', 'm4.4xlarge', 'm4.10xlarge', 'm4.16xlarge', 'm5.large',
|
||||
'm5.xlarge', 'm5.2xlarge', 'm5.4xlarge', 'm5.8xlarge', 'm5.12xlarge', 'm5.16xlarge',
|
||||
'm5.24xlarge', 'm5.metal', 'm5a.large', 'm5a.xlarge', 'm5a.2xlarge', 'm5a.4xlarge',
|
||||
'm5a.8xlarge', 'm5a.12xlarge', 'm5a.16xlarge', 'm5a.24xlarge', 'm5ad.large',
|
||||
'm5ad.xlarge', 'm5ad.2xlarge', 'm5ad.4xlarge', 'm5ad.12xlarge', 'm5ad.24xlarge',
|
||||
'm5d.large', 'm5d.xlarge', 'm5d.2xlarge', 'm5d.4xlarge', 'm5d.8xlarge', 'm5d.12xlarge',
|
||||
'm5d.16xlarge', 'm5d.24xlarge', 'm5d.metal', 't2.nano', 't2.micro', 't2.small',
|
||||
't2.medium', 't2.large', 't2.xlarge', 't2.2xlarge', 't3.nano', 't3.micro', 't3.small',
|
||||
't3.medium', 't3.large', 't3.xlarge', 't3.2xlarge', 't3a.nano', 't3a.micro', 't3a.small',
|
||||
't3a.medium', 't3a.large', 't3a.xlarge', 't3a.2xlarge', 'c4.large', 'c4.xlarge',
|
||||
'c4.2xlarge', 'c4.4xlarge', 'c4.8xlarge', 'c5.large',
|
||||
'c5.xlarge', 'c5.2xlarge', 'c5.4xlarge', 'c5.9xlarge', 'c5.12xlarge', 'c5.18xlarge',
|
||||
'c5.24xlarge', 'c5.metal', 'c5d.large', 'c5d.xlarge', 'c5d.2xlarge', 'c5d.4xlarge',
|
||||
'c5d.9xlarge', 'c5d.18xlarge', 'c5n.large', 'c5n.xlarge', 'c5n.2xlarge', 'c5n.4xlarge',
|
||||
'c5n.9xlarge', 'c5n.18xlarge', 'r4.large', 'r4.xlarge', 'r4.2xlarge', 'r4.4xlarge', 'r4.8xlarge', 'r4.16xlarge',
|
||||
'r5.large', 'r5.xlarge', 'r5.2xlarge', 'r5.4xlarge', 'r5.8xlarge', 'r5.12xlarge',
|
||||
'r5.16xlarge', 'r5.24xlarge', 'r5.metal', 'r5a.large', 'r5a.xlarge', 'r5a.2xlarge',
|
||||
'r5a.4xlarge', 'r5a.8xlarge', 'r5a.12xlarge', 'r5a.16xlarge', 'r5a.24xlarge', 'r5ad.large',
|
||||
'r5ad.xlarge', 'r5ad.2xlarge', 'r5ad.4xlarge', 'r5ad.12xlarge', 'r5ad.24xlarge', 'r5d.large',
|
||||
'r5d.xlarge', 'r5d.2xlarge', 'r5d.4xlarge', 'r5d.8xlarge', 'r5d.12xlarge', 'r5d.16xlarge',
|
||||
'r5d.24xlarge', 'r5d.metal', 'u-6tb1.metal', 'u-9tb1.metal', 'u-12tb1.metal', 'x1.16xlarge',
|
||||
'x1.32xlarge', 'x1e.xlarge', 'x1e.2xlarge', 'x1e.4xlarge', 'x1e.8xlarge', 'x1e.16xlarge',
|
||||
'x1e.32xlarge', 'z1d.large', 'z1d.xlarge', 'z1d.2xlarge', 'z1d.3xlarge', 'z1d.6xlarge',
|
||||
'z1d.12xlarge', 'z1d.metal', 'd2.xlarge', 'd2.2xlarge', 'd2.4xlarge', 'd2.8xlarge', 'h1.2xlarge', 'h1.4xlarge',
|
||||
'h1.8xlarge', 'h1.16xlarge', 'i3.large', 'i3.xlarge', 'i3.2xlarge', 'i3.4xlarge',
|
||||
'i3.8xlarge', 'i3.16xlarge', 'i3.metal', 'i3en.large', 'i3en.xlarge', 'i3en.2xlarge',
|
||||
'i3en.3xlarge', 'i3en.6xlarge', 'i3en.12xlarge', 'i3en.24xlarge','f1.2xlarge',
|
||||
'f1.4xlarge', 'f1.16xlarge', 'g3s.xlarge', 'g3.4xlarge', 'g3.8xlarge',
|
||||
'g3.16xlarge', 'p2.xlarge', 'p2.8xlarge', 'p2.16xlarge', 'p3.2xlarge', 'p3.8xlarge',
|
||||
'p3.16xlarge', 'p3dn.24xlarge'.
|
||||
|
||||
=item B<--running>
|
||||
|
||||
|
|
|
@ -30,9 +30,7 @@ sub new {
|
|||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
});
|
||||
$options{options}->add_options(arguments => {});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
|
|
@ -30,8 +30,7 @@ sub new {
|
|||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
});
|
||||
$options{options}->add_options(arguments => {});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
@ -53,7 +52,8 @@ sub run {
|
|||
$self->manage_selection(%options);
|
||||
foreach (@{$self->{instances}}) {
|
||||
next if ($_->{Type} !~ m/instance/);
|
||||
$self->{output}->output_add(long_msg => sprintf("[Id = %s][AvailabilityZone = %s][InstanceType = %s][State = %s][Tags = %s][KeyName = %s]",
|
||||
$self->{output}->output_add(
|
||||
long_msg => sprintf("[Id = %s][AvailabilityZone = %s][InstanceType = %s][State = %s][Tags = %s][KeyName = %s]",
|
||||
$_->{Name}, $_->{AvailabilityZone}, $_->{InstanceType}, $_->{State}, $_->{Tags}, $_->{KeyName}));
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,45 @@ use base qw(centreon::plugins::templates::counter);
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
my %metrics_mapping = (
|
||||
'NetworkIn' => {
|
||||
'output' => 'Network In',
|
||||
'label' => 'network-in',
|
||||
'nlabel' => {
|
||||
'absolute' => 'ec2.network.in.bytes',
|
||||
'per_second' => 'ec2.network.in.bytespersecond',
|
||||
},
|
||||
'unit' => 'B',
|
||||
},
|
||||
'NetworkOut' => {
|
||||
'output' => 'Network Out',
|
||||
'label' => 'network-out',
|
||||
'nlabel' => {
|
||||
'absolute' => 'ec2.network.in.bytes',
|
||||
'per_second' => 'ec2.network.in.bytespersecond',
|
||||
},
|
||||
'unit' => 'B',
|
||||
},
|
||||
'NetworkPacketsIn' => {
|
||||
'output' => 'Network Packets In',
|
||||
'label' => 'network-packets-in',
|
||||
'nlabel' => {
|
||||
'absolute' => 'ec2.network.packets.in.count',
|
||||
'per_second' => 'ec2.network.packets.in.persecond',
|
||||
},
|
||||
'unit' => 'packets',
|
||||
},
|
||||
'NetworkPacketsOut' => {
|
||||
'output' => 'Network Packets Out',
|
||||
'label' => 'network-packets-out',
|
||||
'nlabel' => {
|
||||
'absolute' => 'ec2.network.packets.out.count',
|
||||
'per_second' => 'ec2.network.packets.out.persecond',
|
||||
},
|
||||
'unit' => 'packets',
|
||||
},
|
||||
);
|
||||
|
||||
my %map_type = (
|
||||
"instance" => "InstanceId",
|
||||
"asg" => "AutoScalingGroupName",
|
||||
|
@ -33,124 +72,111 @@ my %map_type = (
|
|||
sub prefix_metric_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return ucfirst($options{instance_value}->{type}) . " '" . $options{instance_value}->{display} . "' " . $options{instance_value}->{stat} . " ";
|
||||
return ucfirst($self->{option_results}->{type}) . " '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub prefix_statistics_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Statistic '" . $options{instance_value}->{display} . "' Metrics ";
|
||||
}
|
||||
|
||||
sub long_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Checking " . ucfirst($self->{option_results}->{type}) . " '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub custom_metric_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{timeframe} = $options{new_datas}->{$self->{instance} . '_timeframe'};
|
||||
$self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{metric} . '_' . $options{extra_options}->{stat}};
|
||||
$self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{metric}};
|
||||
$self->{result_values}->{value_per_sec} = $self->{result_values}->{value} / $self->{result_values}->{timeframe};
|
||||
$self->{result_values}->{stat} = $options{extra_options}->{stat};
|
||||
$self->{result_values}->{metric} = $options{extra_options}->{metric};
|
||||
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub custom_metric_threshold {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value},
|
||||
threshold => [ { label => 'critical-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat}), exit_litteral => 'critical' },
|
||||
{ label => 'warning-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat}), exit_litteral => 'warning' } ]);
|
||||
my $exit = $self->{perfdata}->threshold_check(
|
||||
value => defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value},
|
||||
threshold => [ { label => 'critical-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'critical' },
|
||||
{ label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}, exit_litteral => 'warning' } ]);
|
||||
return $exit;
|
||||
}
|
||||
|
||||
sub custom_traffic_perfdata {
|
||||
sub custom_metric_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
|
||||
|
||||
$self->{output}->perfdata_add(label => lc($self->{result_values}->{metric}) . "_" . lc($self->{result_values}->{stat}) . $extra_label,
|
||||
unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'B/s' : 'B',
|
||||
value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})),
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
instances => $self->{instance},
|
||||
label => $metrics_mapping{$self->{result_values}->{metric}}->{label},
|
||||
nlabel => defined($self->{instance_mode}->{option_results}->{per_sec}) ?
|
||||
$metrics_mapping{$self->{result_values}->{metric}}->{nlabel}->{per_second} :
|
||||
$metrics_mapping{$self->{result_values}->{metric}}->{nlabel}->{absolute},
|
||||
unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ?
|
||||
$metrics_mapping{$self->{result_values}->{metric}}->{unit} . '/s' :
|
||||
$metrics_mapping{$self->{result_values}->{metric}}->{unit},
|
||||
value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ?
|
||||
$self->{result_values}->{value_per_sec} :
|
||||
$self->{result_values}->{value}),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $metrics_mapping{$self->{result_values}->{metric}}->{label}),
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_traffic_output {
|
||||
sub custom_metric_output {
|
||||
my ($self, %options) = @_;
|
||||
my $msg = "";
|
||||
|
||||
if (defined($self->{instance_mode}->{option_results}->{per_sec})) {
|
||||
my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value_per_sec});
|
||||
$msg = $self->{result_values}->{metric} . ": " . $value . $unit . "/s";
|
||||
my ($value, $unit) = ($metrics_mapping{$self->{result_values}->{metric}}->{unit} eq 'B') ?
|
||||
$self->{perfdata}->change_bytes(value => $self->{result_values}->{value_per_sec}) :
|
||||
($self->{result_values}->{value_per_sec}, $metrics_mapping{$self->{result_values}->{metric}}->{unit});
|
||||
$msg = sprintf("%s: %.2f %s", $metrics_mapping{$self->{result_values}->{metric}}->{output}, $value, $unit . '/s');
|
||||
} else {
|
||||
my ($value, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value});
|
||||
$msg = $self->{result_values}->{metric} . ": " . $value . $unit;
|
||||
my ($value, $unit) = ($metrics_mapping{$self->{result_values}->{metric}}->{unit} eq 'B') ?
|
||||
$self->{perfdata}->change_bytes(value => $self->{result_values}->{value}) :
|
||||
($self->{result_values}->{value}, $metrics_mapping{$self->{result_values}->{metric}}->{unit});
|
||||
$msg = sprintf("%s: %.2f %s", $metrics_mapping{$self->{result_values}->{metric}}->{output}, $value, $unit);
|
||||
}
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_packets_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $extra_label = '';
|
||||
$extra_label = '_' . lc($self->{result_values}->{display}) if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
|
||||
|
||||
$self->{output}->perfdata_add(label => lc($self->{result_values}->{metric}) . "_" . lc($self->{result_values}->{stat}) . $extra_label,
|
||||
unit => defined($self->{instance_mode}->{option_results}->{per_sec}) ? 'packets/s' : 'packets',
|
||||
value => sprintf("%.2f", defined($self->{instance_mode}->{option_results}->{per_sec}) ? $self->{result_values}->{value_per_sec} : $self->{result_values}->{value}),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . lc($self->{result_values}->{metric}) . "-" . lc($self->{result_values}->{stat})),
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_packets_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg ="";
|
||||
|
||||
if (defined($self->{instance_mode}->{option_results}->{per_sec})) {
|
||||
$msg = sprintf("%s: %.2f packets/s", $self->{result_values}->{metric}, $self->{result_values}->{value_per_sec});
|
||||
} else {
|
||||
$msg = sprintf("%s: %.2f packets", $self->{result_values}->{metric}, $self->{result_values}->{value});
|
||||
}
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'metric', type => 1, cb_prefix_output => 'prefix_metric_output', message_multiple => "All network metrics are ok", skipped_code => { -10 => 1 } },
|
||||
{ name => 'metrics', type => 3, cb_prefix_output => 'prefix_metric_output', cb_long_output => 'long_output',
|
||||
message_multiple => 'All network metrics are ok', indent_long_output => ' ',
|
||||
group => [
|
||||
{ name => 'statistics', display_long => 1, cb_prefix_output => 'prefix_statistics_output',
|
||||
message_multiple => 'All metrics are ok', type => 1, skipped_code => { -10 => 1 } },
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
foreach my $statistic ('minimum', 'maximum', 'average', 'sum') {
|
||||
foreach my $metric ('NetworkIn', 'NetworkOut') {
|
||||
my $entry = { label => lc($metric) . '-' . lc($statistic), set => {
|
||||
key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'stat' }, { name => 'timeframe' } ],
|
||||
closure_custom_calc => $self->can('custom_metric_calc'),
|
||||
closure_custom_calc_extra_options => { metric => $metric, stat => $statistic },
|
||||
closure_custom_output => $self->can('custom_traffic_output'),
|
||||
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_metric_threshold'),
|
||||
}
|
||||
};
|
||||
push @{$self->{maps_counters}->{metric}}, $entry;
|
||||
}
|
||||
foreach my $metric ('NetworkPacketsIn', 'NetworkPacketsOut') {
|
||||
my $entry = { label => lc($metric) . '-' . lc($statistic), set => {
|
||||
key_values => [ { name => $metric . '_' . $statistic }, { name => 'display' }, { name => 'stat' }, { name => 'timeframe' } ],
|
||||
closure_custom_calc => $self->can('custom_metric_calc'),
|
||||
closure_custom_calc_extra_options => { metric => $metric, stat => $statistic },
|
||||
closure_custom_output => $self->can('custom_packets_output'),
|
||||
closure_custom_perfdata => $self->can('custom_packets_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_metric_threshold'),
|
||||
}
|
||||
};
|
||||
push @{$self->{maps_counters}->{metric}}, $entry;
|
||||
}
|
||||
foreach my $metric (keys %metrics_mapping) {
|
||||
my $entry = {
|
||||
label => $metrics_mapping{$metric}->{label},
|
||||
set => {
|
||||
key_values => [ { name => $metric }, { name => 'timeframe' }, { name => 'display' } ],
|
||||
closure_custom_calc => $self->can('custom_metric_calc'),
|
||||
closure_custom_calc_extra_options => { metric => $metric },
|
||||
closure_custom_output => $self->can('custom_metric_output'),
|
||||
closure_custom_perfdata => $self->can('custom_metric_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_metric_threshold'),
|
||||
}
|
||||
};
|
||||
push @{$self->{maps_counters}->{statistics}}, $entry;
|
||||
}
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
|
@ -201,7 +227,7 @@ sub check_options {
|
|||
}
|
||||
}
|
||||
|
||||
foreach my $metric ('NetworkIn', 'NetworkOut', 'NetworkPacketsIn', 'NetworkPacketsOut') {
|
||||
foreach my $metric (keys %metrics_mapping) {
|
||||
next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne ''
|
||||
&& $metric !~ /$self->{option_results}->{filter_metric}/);
|
||||
|
||||
|
@ -226,18 +252,20 @@ sub manage_selection {
|
|||
|
||||
foreach my $metric (@{$self->{aws_metrics}}) {
|
||||
foreach my $statistic (@{$self->{aws_statistics}}) {
|
||||
next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) && !defined($self->{option_results}->{zeroed}));
|
||||
next if (!defined($metric_results{$instance}->{$metric}->{lc($statistic)}) &&
|
||||
!defined($self->{option_results}->{zeroed}));
|
||||
|
||||
$self->{metric}->{$instance . "_" . lc($statistic)}->{display} = $instance;
|
||||
$self->{metric}->{$instance . "_" . lc($statistic)}->{type} = $self->{option_results}->{type};
|
||||
$self->{metric}->{$instance . "_" . lc($statistic)}->{stat} = lc($statistic);
|
||||
$self->{metric}->{$instance . "_" . lc($statistic)}->{timeframe} = $self->{aws_timeframe};
|
||||
$self->{metric}->{$instance . "_" . lc($statistic)}->{$metric . "_" . lc($statistic)} = defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ? $metric_results{$instance}->{$metric}->{lc($statistic)} : 0;
|
||||
$self->{metrics}->{$instance}->{display} = $instance;
|
||||
$self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{display} = $statistic;
|
||||
$self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{timeframe} = $self->{aws_timeframe};
|
||||
$self->{metrics}->{$instance}->{statistics}->{lc($statistic)}->{$metric} =
|
||||
defined($metric_results{$instance}->{$metric}->{lc($statistic)}) ?
|
||||
$metric_results{$instance}->{$metric}->{lc($statistic)} : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{metric}}) <= 0) {
|
||||
if (scalar(keys %{$self->{metrics}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => 'No metrics. Check your options or use --zeroed option to set 0 on undefined values');
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
@ -254,7 +282,7 @@ Check EC2 instances network metrics.
|
|||
Example:
|
||||
perl centreon_plugins.pl --plugin=cloud::aws::ec2::plugin --custommode=paws --mode=network --region='eu-west-1'
|
||||
--type='asg' --name='centreon-middleware' --filter-metric='Packets' --statistic='sum'
|
||||
--critical-networkpacketsout-sum='10' --verbose
|
||||
--critical-network-packets-out='10' --verbose
|
||||
|
||||
See 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ec2-metricscollected.html' for more informations.
|
||||
|
||||
|
@ -276,17 +304,10 @@ Filter metrics (Can be: 'NetworkIn', 'NetworkOut',
|
|||
'NetworkPacketsIn', 'NetworkPacketsOut')
|
||||
(Can be a regexp).
|
||||
|
||||
=item B<--warning-$metric$-$statistic$>
|
||||
=item B<--warning-*> B<--critical-*>
|
||||
|
||||
Thresholds warning ($metric$ can be: 'networkin', 'networkout',
|
||||
'networkpacketsin', 'networkpacketsout',
|
||||
$statistic$ can be: 'minimum', 'maximum', 'average', 'sum').
|
||||
|
||||
=item B<--critical-$metric$-$statistic$>
|
||||
|
||||
Thresholds critical ($metric$ can be: 'networkin', 'networkout',
|
||||
'networkpacketsin', 'networkpacketsout',
|
||||
$statistic$ can be: 'minimum', 'maximum', 'average', 'sum').
|
||||
Thresholds warning (Can be 'network-in', 'network-out',
|
||||
'network-packets-in', 'network-packets-out'.
|
||||
|
||||
=item B<--per-sec>
|
||||
|
||||
|
|
|
@ -106,13 +106,12 @@ sub new {
|
|||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"type:s" => { name => 'type' },
|
||||
"name:s@" => { name => 'name' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /failed/i' },
|
||||
});
|
||||
$options{options}->add_options(arguments => {
|
||||
"type:s" => { name => 'type' },
|
||||
"name:s@" => { name => 'name' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /failed/i' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue