fix prom kube allocated pods calc
This commit is contained in:
parent
6db0612269
commit
83ac39651d
|
@ -53,15 +53,17 @@ sub custom_usage_perfdata {
|
||||||
$extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
|
$extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
|
||||||
my %total_options = ();
|
my %total_options = ();
|
||||||
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
|
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
|
||||||
$total_options{total} = $self->{result_values}->{capacity};
|
$total_options{total} = $self->{result_values}->{allocatable};
|
||||||
$total_options{cast_int} = 1;
|
$total_options{cast_int} = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{output}->perfdata_add(label => $label . $extra_label,
|
$self->{output}->perfdata_add(
|
||||||
value => $value_perf,
|
label => $label . $extra_label,
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
|
value => $value_perf,
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
|
||||||
min => 0, max => $self->{result_values}->{capacity});
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
|
||||||
|
min => 0, max => $self->{result_values}->{allocatable}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub custom_usage_threshold {
|
sub custom_usage_threshold {
|
||||||
|
@ -72,16 +74,36 @@ sub custom_usage_threshold {
|
||||||
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
|
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
|
||||||
$threshold_value = $self->{result_values}->{prct_allocated};
|
$threshold_value = $self->{result_values}->{prct_allocated};
|
||||||
}
|
}
|
||||||
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' },
|
$exit = $self->{perfdata}->threshold_check(
|
||||||
{ label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
|
value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' },
|
||||||
|
{ label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]
|
||||||
|
);
|
||||||
|
return $exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub custom_usage_threshold {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my ($exit, $threshold_value);
|
||||||
|
$threshold_value = $self->{result_values}->{allocated};
|
||||||
|
if ($self->{instance_mode}->{option_results}->{units} eq '%') {
|
||||||
|
$threshold_value = $self->{result_values}->{prct_allocated};
|
||||||
|
}
|
||||||
|
$exit = $self->{perfdata}->threshold_check(
|
||||||
|
value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' },
|
||||||
|
{ label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]
|
||||||
|
);
|
||||||
return $exit;
|
return $exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub custom_usage_output {
|
sub custom_usage_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $msg = sprintf("Pods Allocation Capacity : %s, Allocated : %s (%.2f%%)",
|
my $msg = sprintf("Pods Capacity: %s, Allocatable: %s, Allocated: %s (%.2f%%)",
|
||||||
$self->{result_values}->{capacity}, $self->{result_values}->{allocated}, $self->{result_values}->{prct_allocated});
|
$self->{result_values}->{capacity},
|
||||||
|
$self->{result_values}->{allocatable},
|
||||||
|
$self->{result_values}->{allocated},
|
||||||
|
$self->{result_values}->{prct_allocated});
|
||||||
return $msg;
|
return $msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,19 +113,18 @@ sub custom_usage_calc {
|
||||||
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
|
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
|
||||||
$self->{result_values}->{capacity} = $options{new_datas}->{$self->{instance} . '_capacity'};
|
$self->{result_values}->{capacity} = $options{new_datas}->{$self->{instance} . '_capacity'};
|
||||||
$self->{result_values}->{allocatable} = $options{new_datas}->{$self->{instance} . '_allocatable'};
|
$self->{result_values}->{allocatable} = $options{new_datas}->{$self->{instance} . '_allocatable'};
|
||||||
$self->{result_values}->{allocated} = $self->{result_values}->{capacity} - $self->{result_values}->{allocatable};
|
$self->{result_values}->{allocated} = $options{new_datas}->{$self->{instance} . '_allocated'};
|
||||||
$self->{result_values}->{prct_allocated} = ($self->{result_values}->{capacity} > 0) ? $self->{result_values}->{allocated} * 100 / $self->{result_values}->{capacity} : 0;
|
$self->{result_values}->{prct_allocated} = ($self->{result_values}->{allocatable} > 0) ? $self->{result_values}->{allocated} * 100 / $self->{result_values}->{allocatable} : 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub set_counters {
|
sub set_counters {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{maps_counters_type} = [
|
$self->{maps_counters_type} = [
|
||||||
{ name => 'nodes', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All nodes status are ok',
|
{ name => 'nodes', type => 1, cb_prefix_output => 'prefix_node_output',
|
||||||
message_separator => ' - ', skipped_code => { -11 => 1 } },
|
message_multiple => 'All nodes status are ok', message_separator => ' - ', skipped_code => { -11 => 1 } },
|
||||||
];
|
];
|
||||||
|
|
||||||
$self->{maps_counters}->{nodes} = [
|
$self->{maps_counters}->{nodes} = [
|
||||||
|
@ -116,7 +137,8 @@ sub set_counters {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ label => 'allocated-pods', set => {
|
{ label => 'allocated-pods', set => {
|
||||||
key_values => [ { name => 'capacity' }, { name => 'allocatable' }, { name => 'display' } ],
|
key_values => [ { name => 'capacity' }, { name => 'allocatable' }, { name => 'allocated' },
|
||||||
|
{ name => 'display' } ],
|
||||||
closure_custom_calc => $self->can('custom_usage_calc'),
|
closure_custom_calc => $self->can('custom_usage_calc'),
|
||||||
closure_custom_output => $self->can('custom_usage_output'),
|
closure_custom_output => $self->can('custom_usage_output'),
|
||||||
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
|
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
|
||||||
|
@ -160,6 +182,7 @@ sub check_options {
|
||||||
'unschedulable' => '^kube_node_spec_unschedulable$',
|
'unschedulable' => '^kube_node_spec_unschedulable$',
|
||||||
'capacity' => '^kube_node_status_capacity_pods$',
|
'capacity' => '^kube_node_status_capacity_pods$',
|
||||||
'allocatable' => '^kube_node_status_allocatable_pods$',
|
'allocatable' => '^kube_node_status_allocatable_pods$',
|
||||||
|
'allocated' => '^kubelet_running_pod_count$',
|
||||||
};
|
};
|
||||||
foreach my $metric (@{$self->{option_results}->{metric_overload}}) {
|
foreach my $metric (@{$self->{option_results}->{metric_overload}}) {
|
||||||
next if ($metric !~ /(.*),(.*)/);
|
next if ($metric !~ /(.*),(.*)/);
|
||||||
|
@ -200,7 +223,10 @@ sub manage_selection {
|
||||||
$self->{extra_filter} . '}, "__name__", "capacity", "", "")',
|
$self->{extra_filter} . '}, "__name__", "capacity", "", "")',
|
||||||
'label_replace({__name__=~"' . $self->{metrics}->{allocatable} . '",' .
|
'label_replace({__name__=~"' . $self->{metrics}->{allocatable} . '",' .
|
||||||
$self->{option_results}->{node} .
|
$self->{option_results}->{node} .
|
||||||
$self->{extra_filter} . '}, "__name__", "allocatable", "", "")' ]);
|
$self->{extra_filter} . '}, "__name__", "allocatable", "", "")',
|
||||||
|
'label_replace({__name__=~"' . $self->{metrics}->{allocated} . '",' .
|
||||||
|
$self->{option_results}->{node} .
|
||||||
|
$self->{extra_filter} . '}, "__name__", "allocated", "", "")' ]);
|
||||||
|
|
||||||
foreach my $result (@{$results}) {
|
foreach my $result (@{$results}) {
|
||||||
$self->{nodes}->{$result->{metric}->{$self->{labels}->{node}}}->{display} = $result->{metric}->{$self->{labels}->{node}};
|
$self->{nodes}->{$result->{metric}->{$self->{labels}->{node}}}->{display} = $result->{metric}->{$self->{labels}->{node}};
|
||||||
|
@ -268,6 +294,7 @@ Default :
|
||||||
- unschedulable: ^kube_node_spec_unschedulable$
|
- unschedulable: ^kube_node_spec_unschedulable$
|
||||||
- capacity: ^kube_node_status_capacity_pods$
|
- capacity: ^kube_node_status_capacity_pods$
|
||||||
- allocatable: ^kube_node_status_allocatable_pods$
|
- allocatable: ^kube_node_status_allocatable_pods$
|
||||||
|
- allocated: ^kubelet_running_pod_count$
|
||||||
|
|
||||||
=item B<--filter-counters>
|
=item B<--filter-counters>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue