![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /usr/share/doc/libsys-virt-perl/examples/ |
Upload File : |
#!/usr/bin/perl use strict; use warnings; use Sys::Virt; use Time::HiRes qw(time); my $addr = @ARGV ? shift @ARGV : ""; my $hv = Sys::Virt->new(address => $addr, readonly => 1); my $interval = @ARGV ? shift @ARGV : 1; my $iterations = @ARGV ? shift @ARGV : 1; my $nodeinfo = $hv->get_node_info(); my $ncpus = $nodeinfo->{cpus}; my @cpuTime; my $then; for (my $c = 0 ; $c < $ncpus ; $c++) { printf "CPU %3d ", $c; } print "\n"; for (my $i = 0 ; $i < $iterations ; $i++) { sleep $interval if $i; my $now = time; for (my $c = 0 ; $c < $ncpus ; $c++) { my $info = $hv->get_node_cpu_stats($c); my $used = $info->{kernel} + $info->{user}; if (exists $cpuTime[$c]) { my $cpudelta = $used - $cpuTime[$c]; my $timedelta = ($now - $then) * 1000*1000*1000; my $util = $cpudelta * 100 / $timedelta; printf "%03.02f%% ", $util; } $cpuTime[$c] = $used; } print "\n"; $then = $now; } my ($totcpus, $onlinemask, $nonline) = $hv->get_node_cpu_map(); printf "CPUs total %d, online %d\n", $totcpus, $nonline; my @bits = split(//, unpack("b*", $onlinemask)); for (my $i = 0 ; $i < $totcpus ; $i++) { printf " %d: %d\n", $i, $bits[$i]; }