Fix #5649
This commit is contained in:
parent
ff1f7d1bcb
commit
c2ff932705
|
@ -123,6 +123,7 @@ sub run {
|
||||||
my $save_datas = {};
|
my $save_datas = {};
|
||||||
my $new_datas = {};
|
my $new_datas = {};
|
||||||
my $old_datas = {};
|
my $old_datas = {};
|
||||||
|
my ($total_datas, $total_cpu_num) = ({}, 0);
|
||||||
|
|
||||||
foreach my $line (split(/\n/, $stdout)) {
|
foreach my $line (split(/\n/, $stdout)) {
|
||||||
next if ($line !~ /cpu(\d+)\s+/);
|
next if ($line !~ /cpu(\d+)\s+/);
|
||||||
|
@ -177,6 +178,7 @@ sub run {
|
||||||
$self->{output}->display();
|
$self->{output}->display();
|
||||||
$self->{output}->exit();
|
$self->{output}->exit();
|
||||||
}
|
}
|
||||||
|
$total_cpu_num++;
|
||||||
|
|
||||||
my @exits;
|
my @exits;
|
||||||
foreach (@{$maps}) {
|
foreach (@{$maps}) {
|
||||||
|
@ -194,6 +196,8 @@ sub run {
|
||||||
|
|
||||||
my $value = (($new_datas->{$cpu_number}->{$_->{counter}} - $old_datas->{$cpu_number}->{$_->{counter}}) * 100) /
|
my $value = (($new_datas->{$cpu_number}->{$_->{counter}} - $old_datas->{$cpu_number}->{$_->{counter}}) * 100) /
|
||||||
($new_datas->{$cpu_number}->{total} - $old_datas->{$cpu_number}->{total});
|
($new_datas->{$cpu_number}->{total} - $old_datas->{$cpu_number}->{total});
|
||||||
|
$total_datas->{$_->{counter}} = 0 if (!defined($total_datas->{$_->{counter}}));
|
||||||
|
$total_datas->{$_->{counter}} += $value;
|
||||||
$str_output .= $str_append . sprintf($_->{output}, $value);
|
$str_output .= $str_append . sprintf($_->{output}, $value);
|
||||||
$str_append = ', ';
|
$str_append = ', ';
|
||||||
my $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $_->{counter});
|
my $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $_->{counter});
|
||||||
|
@ -212,6 +216,15 @@ sub run {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# We can display a total (some buffer creation and counters have moved)
|
||||||
|
if ($total_cpu_num != 0) {
|
||||||
|
foreach my $counter (sort keys %{$total_datas}) {
|
||||||
|
$self->{output}->perfdata_add(label => 'total_cpu_' . $counter . '_avg', unit => '%',
|
||||||
|
value => sprintf("%.2f", $total_datas->{$counter} / $total_cpu_num),
|
||||||
|
min => 0, max => 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$self->{output}->display();
|
$self->{output}->display();
|
||||||
$self->{output}->exit();
|
$self->{output}->exit();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue