diff --git a/src/cloud/azure/compute/aks/mode/memory.pm b/src/cloud/azure/compute/aks/mode/memory.pm new file mode 100644 index 000000000..f9619df0c --- /dev/null +++ b/src/cloud/azure/compute/aks/mode/memory.pm @@ -0,0 +1,179 @@ +# +# Copyright 2022 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::compute::aks::mode::memory; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'node_memory_rss_bytes' => { + 'output' => 'memory RSS Usage', + 'label' => 'memory-rss-usage', + 'nlabel' => 'aks.node.memory.rss.bytes', + 'unit' => 'B', + 'min' => '0' + }, + 'node_memory_rss_percentage' => { + 'output' => 'Memory RSS Percent', + 'label' => 'memory-rss-percent', + 'nlabel' => 'aks.node.memory.rss.percentage', + 'unit' => '%', + 'min' => '0', + 'max' => '100' + }, + 'node_memory_working_set_bytes' => { + 'output' => 'memory Usage', + 'label' => 'memory-usage', + 'nlabel' => 'aks.node.memory.working.set.bytes', + 'unit' => 'B', + 'min' => '0' + }, + 'node_memory_working_set_percentage' => { + 'output' => 'Memory Percent', + 'label' => 'memory-percent', + 'nlabel' => 'aks.node.memory.working.set.percentage', + 'unit' => '%', + 'min' => '0', + 'max' => '100' + } + + }; + + return $metrics_mapping; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-metric:s' => { name => 'filter_metric' }, + 'resource:s' => { name => 'resource' }, + 'resource-group:s' => { name => 'resource_group' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') { + $self->{output}->add_option_msg(short_msg => 'Need to specify either --resource with --resource-group option or --resource .'); + $self->{output}->option_exit(); + } + + my $resource = $self->{option_results}->{resource}; + my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : ''; + my $resource_type = $self->{option_results}->{resource_type}; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.ContainerService\/managedClusters\/(.*)$/) { + $resource_group = $1; + $resource = $2; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'managedClusters'; + $self->{az_resource_namespace} = 'Microsoft.ContainerService'; + $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; + $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M'; + $self->{az_aggregations} = ['Average']; + + foreach my $metric (keys %{$self->{metrics_mapping}}) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + push @{$self->{az_metrics}}, $metric; + } +} + +1; + +__END__ + +=head1 MODE + +Check Memory usage on Azure Kubernetes Cluster. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=memory --custommode=api +--resource= --resource-group= --warning-memory-percent='90' --critical-memory-percent='95' + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=storage --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.ContainerService/managedClusters/' +--warning-memory-percent='90' --critical-memory-percent='95' + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<--warning-memory-usage> + +Warning threshold in Bytes. + +=item B<--critical-memory-usage> + +Critical threshold in Bytes. + +=item B<--warning-memory-percent> + +Warning threshold in percent. + +=item B<--critical-memory-percent> + +Critical threshold in percent. + +=item B<--warning-rss-memory-usage> + +Warning threshold in Bytes. + +=item B<--critical-rss-memory-usage> + +Critical threshold in Bytes. + +=item B<--warning-rss-memory-percent> + +Warning threshold in percent. + +=item B<--critical-rss-memory-percent> + +Critical threshold in percent. + +=back + +=cut diff --git a/src/cloud/azure/compute/aks/mode/nodestate.pm b/src/cloud/azure/compute/aks/mode/nodestate.pm new file mode 100644 index 000000000..cdd372891 --- /dev/null +++ b/src/cloud/azure/compute/aks/mode/nodestate.pm @@ -0,0 +1,131 @@ +# +# Copyright 2022 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::compute::aks::mode::nodestate; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'kube_node_status_condition' => { + 'output' => 'Kube Node State Condition', + 'label' => 'node-state-condition', + 'nlabel' => 'aks.kube.node.status.condition.count', + 'unit' => '', + 'min' => '0' + } + }; + + return $metrics_mapping; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-metric:s' => { name => 'filter_metric' }, + 'resource:s' => { name => 'resource' }, + 'resource-group:s' => { name => 'resource_group' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') { + $self->{output}->add_option_msg(short_msg => 'Need to specify either --resource with --resource-group option or --resource .'); + $self->{output}->option_exit(); + } + + my $resource = $self->{option_results}->{resource}; + my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : ''; + my $resource_type = $self->{option_results}->{resource_type}; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.ContainerService\/managedClusters\/(.*)$/) { + $resource_group = $1; + $resource = $2; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'managedClusters'; + $self->{az_resource_namespace} = 'Microsoft.ContainerService'; + $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; + $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M'; + $self->{az_aggregations} = ['Average']; + + foreach my $metric (keys %{$self->{metrics_mapping}}) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + push @{$self->{az_metrics}}, $metric; + } +} + +1; + +__END__ + +=head1 MODE + +Check Azure Kubernetes number of nodes by state. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=nodestate --custommode=api +--resource= --resource-group= --zeroed --warning-node-state-condition=5 --critical-node-state-condition=10 + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=nodestate --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.ContainerService/managedClusters/' +--zeroed --warning-node-state-condition=5 --critical-node-state-condition=10 + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<--warning-node-state-condition> + +Set warning threshold for number of condition nodes. + +=item B<--critical-node-state-condition> + +Set critical threshold for number of condition nodes. + +=back + +=cut diff --git a/src/cloud/azure/compute/aks/mode/podstate.pm b/src/cloud/azure/compute/aks/mode/podstate.pm new file mode 100644 index 000000000..f6ff369a5 --- /dev/null +++ b/src/cloud/azure/compute/aks/mode/podstate.pm @@ -0,0 +1,148 @@ +# +# Copyright 2022 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::compute::aks::mode::podstate; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'kube_pod_status_ready' => { + 'output' => 'Kube Pods State Ready', + 'label' => 'pod-state-ready', + 'nlabel' => 'aks.kube.pod.status.ready.count', + 'unit' => '', + 'min' => '0' + }, + 'kube_pod_status_phase' => { + 'output' => 'Kube Pods State Phase', + 'label' => 'pod-state-phase', + 'nlabel' => 'aks.kube.pod.status.phase.count', + 'unit' => '', + 'min' => '0' + } + + }; + + return $metrics_mapping; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-metric:s' => { name => 'filter_metric' }, + 'resource:s' => { name => 'resource' }, + 'resource-group:s' => { name => 'resource_group' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') { + $self->{output}->add_option_msg(short_msg => 'Need to specify either --resource with --resource-group option or --resource .'); + $self->{output}->option_exit(); + } + + my $resource = $self->{option_results}->{resource}; + my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : ''; + my $resource_type = $self->{option_results}->{resource_type}; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.ContainerService\/managedClusters\/(.*)$/) { + $resource_group = $1; + $resource = $2; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'managedClusters'; + $self->{az_resource_namespace} = 'Microsoft.ContainerService'; + $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; + $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M'; + $self->{az_aggregations} = ['Average']; + + foreach my $metric (keys %{$self->{metrics_mapping}}) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + push @{$self->{az_metrics}}, $metric; + } +} + +1; + +__END__ + +=head1 MODE + +Check Azure Kubernetes number of pods by state. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=pod-state --custommode=api +--resource= --resource-group= --zeroed --warning-pod-state-phase=5 --critical-pod-state-phase=10 + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=pod-state --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.ContainerService/managedClusters/' +--zeroed --warning-pod-state-phase=5 --critical-pod-state-phase=10 + + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<--warning-pod-state-ready> + +Set warning threshold for number of Pods State Ready. + +=item B<--critical-pod-state-ready> + +Set critical threshold for number of Pods State Ready. + +=item B<--warning-pod-state-phase> + +Set warning threshold for number of Pods State Phase. + +=item B<--critical-pod-state-phase> + +Set critical threshold for number of Pods State Phase. + +=back + +=cut diff --git a/src/cloud/azure/compute/aks/mode/unschedulablepods.pm b/src/cloud/azure/compute/aks/mode/unschedulablepods.pm new file mode 100644 index 000000000..396d5a9e6 --- /dev/null +++ b/src/cloud/azure/compute/aks/mode/unschedulablepods.pm @@ -0,0 +1,131 @@ +# +# Copyright 2022 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package cloud::azure::compute::aks::mode::unschedulablepods; + +use base qw(cloud::azure::custom::mode); + +use strict; +use warnings; + +sub get_metrics_mapping { + my ($self, %options) = @_; + + my $metrics_mapping = { + 'cluster_autoscaler_unschedulable_pods_count' => { + 'output' => 'Cluster Autoscaler Unschedulable Pods', + 'label' => 'unschedulable-pods', + 'nlabel' => 'aks.cluster.autoscaler.unschedulable.pods.count', + 'unit' => '', + 'min' => '0' + } + }; + + return $metrics_mapping; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-metric:s' => { name => 'filter_metric' }, + 'resource:s' => { name => 'resource' }, + 'resource-group:s' => { name => 'resource_group' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') { + $self->{output}->add_option_msg(short_msg => 'Need to specify either --resource with --resource-group option or --resource .'); + $self->{output}->option_exit(); + } + + my $resource = $self->{option_results}->{resource}; + my $resource_group = defined($self->{option_results}->{resource_group}) ? $self->{option_results}->{resource_group} : ''; + my $resource_type = $self->{option_results}->{resource_type}; + if ($resource =~ /^\/subscriptions\/.*\/resourceGroups\/(.*)\/providers\/Microsoft\.ContainerService\/managedClusters\/(.*)$/) { + $resource_group = $1; + $resource = $2; + } + + $self->{az_resource} = $resource; + $self->{az_resource_group} = $resource_group; + $self->{az_resource_type} = 'managedClusters'; + $self->{az_resource_namespace} = 'Microsoft.ContainerService'; + $self->{az_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 900; + $self->{az_interval} = defined($self->{option_results}->{interval}) ? $self->{option_results}->{interval} : 'PT5M'; + $self->{az_aggregations} = ['Average']; + + foreach my $metric (keys %{$self->{metrics_mapping}}) { + next if (defined($self->{option_results}->{filter_metric}) && $self->{option_results}->{filter_metric} ne '' + && $metric !~ /$self->{option_results}->{filter_metric}/); + push @{$self->{az_metrics}}, $metric; + } +} + +1; + +__END__ + +=head1 MODE + +Check Azure Kubernetes Cluster Autoscaler unschedulable pods. + +Example: + +Using resource name : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=unschedulable-pods --custommode=api +--resource= --resource-group= --zeroed --warning-unschedulable-pods=5 --critical-unschedulable-pods=10 + +Using resource id : + +perl centreon_plugins.pl --plugin=cloud::azure::compute::aks::plugin --mode=unschedulable-pods --custommode=api +--resource='/subscriptions//resourceGroups//providers/Microsoft.ContainerService/managedClusters/' +--zeroed --warning-unschedulable-pods=5 --critical-unschedulable-pods=10 + +=over 8 + +=item B<--resource> + +Set resource name or id (Required). + +=item B<--resource-group> + +Set resource group (Required if resource's name is used). + +=item B<--warning-unschedulable-pods> + +Set warning threshold for number of unschedulable pods. + +=item B<--critical-unschedulable-pods> + +Set critical threshold for number of unschedulable pods. + +=back + +=cut diff --git a/src/cloud/azure/compute/aks/plugin.pm b/src/cloud/azure/compute/aks/plugin.pm index f933eb947..27da9b73b 100644 --- a/src/cloud/azure/compute/aks/plugin.pm +++ b/src/cloud/azure/compute/aks/plugin.pm @@ -29,15 +29,18 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '0.1'; $self->{modes} = { 'allocatable-resources' => 'cloud::azure::compute::aks::mode::allocatableresources', 'cpu' => 'cloud::azure::compute::aks::mode::cpu', 'discovery' => 'cloud::azure::compute::aks::mode::discovery', - 'health' => 'cloud::azure::compute::aks::mode::health', + 'health' => 'cloud::azure::compute::aks::mode::health', + 'memory' => 'cloud::azure::compute::aks::mode::memory', + 'node-state' => 'cloud::azure::compute::aks::mode::nodestate', + 'pod-state' => 'cloud::azure::compute::aks::mode::podstate', 'storage' => 'cloud::azure::compute::aks::mode::storage', 'traffic' => 'cloud::azure::compute::aks::mode::traffic', - 'unneeded-nodes' => 'cloud::azure::compute::aks::mode::unneedednodes' + 'unneeded-nodes' => 'cloud::azure::compute::aks::mode::unneedednodes', + 'unschedulable-pods' => 'cloud::azure::compute::aks::mode::unschedulablepods' }; $self->{custom_modes}->{azcli} = 'cloud::azure::custom::azcli'; @@ -49,7 +52,7 @@ sub init { my ($self, %options) = @_; $self->{options}->add_options(arguments => { - 'api-version:s' => { name => 'api_version', default => '2018-01-01' }, + 'api-version:s' => { name => 'api_version', default => '2018-01-01' } }); $self->SUPER::init(%options);