add proxmox vm swap usage

This commit is contained in:
fpr 2019-01-31 09:56:22 +01:00 committed by Colin Gagnaire
parent acba6cf2ba
commit 199a421500
1 changed files with 58 additions and 2 deletions

View File

@ -101,6 +101,54 @@ sub custom_memory_calc {
return 0;
}
sub custom_swap_perfdata {
my ($self, %options) = @_;
my $extra_label = '';
if (!defined($options{extra_instance}) || $options{extra_instance} != 0) {
$extra_label .= '_' . $self->{result_values}->{display};
}
$self->{output}->perfdata_add(label => 'swap_used' . $extra_label, unit => 'B',
value => $self->{result_values}->{used},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
min => 0, max => $self->{result_values}->{total});
}
sub custom_swap_threshold {
my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used},
threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
return $exit;
}
sub custom_swap_output {
my ($self, %options) = @_;
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
my $msg = sprintf("Swap Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$total_size_value . " " . $total_size_unit,
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
return $msg;
}
sub custom_swap_calc {
my ($self, %options) = @_;
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_swap_total'};
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_swap_usage'};
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
$self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total};
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
@ -157,6 +205,14 @@ sub set_counters {
],
}
},
{ label => 'swap', set => {
key_values => [ { name => 'swap_usage' }, { name => 'swap_total' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_swap_calc'),
closure_custom_output => $self->can('custom_swap_output'),
closure_custom_perfdata => $self->can('custom_swap_perfdata'),
closure_custom_threshold_check => $self->can('custom_swap_threshold'),
}
},
];
$self->{maps_counters}->{vms_traffic} = [
@ -312,13 +368,13 @@ Example: --filter-counters='^vm-status$'
Threshold warning.
Can be: 'read-iops', 'write-iops', 'traffic-in', 'traffic-out',
'cpu' (%), 'memory' (%).
'cpu' (%), 'memory' (%), 'swap' (%).
=item B<--critical-*>
Threshold critical.
Can be: 'read-iops', 'write-iops', 'traffic-in', 'traffic-out',
'cpu' (%), 'memory' (%).
'cpu' (%), 'memory' (%), 'swap' (%).
=item B<--warning-vm-status>