Subject: | Divide by zero in CpuStats.pm in OpenVZ containers |
Running CpuStats on an Ubuntu server running as an OpenVZ container
under Proxmox occasionally results in the following error:
Illegal division by zero at
/usr/local/share/perl/5.10.1/Sys/Statistics/Linux/CpuStats.pm line 209.
It seems that the following work-around would at least ignore the error:
202 $dcpu->{$k} -= $icpu->{$k};
203 $icpu->{$k} = $v;
204 $uptime += $dcpu->{$k};
205 }
206
+++ $uptime = 1 unless $uptime;
+++
207 foreach my $k (keys %{$dcpu}) {
208 if ($dcpu->{$k} > 0) {
209 $dcpu->{$k} = sprintf('%.2f', 100 * $dcpu->{$k}
/ $uptime);
210 } elsif ($dcpu->{$k} < 0) {
--------------
System details follow:
it@milpat:~$ uname -a
Linux milpat 2.6.32-4-pve #1 SMP Thu Oct 21 09:35:29 CEST 2010 x86_64
GNU/Linux
it@milpat:~$ perl -v
This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi
Ubuntu 10.04 minimal server install - a contributed download found on
the OpenVZ wiki.