CPU monitor per VMs

I’m used to always seeing the CPU utilization monitor. It’s easy to see who’s doing illegal activities :sunglasses:
Not finding a standard Qubes solution, I wrote a little script for xfce panel item “Generic Monitor”. Maybe someone will find it useful or say that I invented a crooked bicycle and there is a much better one.

It looks like this in a dark theme:

Screenshot_1

Screenshot_2

The script to be copied to the Dom0:

#!/usr/bin/perl

# indicator length
my $il = 25;

my $name_max = '';
my $cpu_max = -1;

open(my $top, '-|', 'xentop -bi2 -d1') || die $!;

while (<$top>) {
        next if /^\s*NAME/ ... /^\s*NAME/;
        s/^\s+//;
        my @s = split /\s+/;
        my $cpu = eval{$s[3]/$s[8]} || 0;
        if ($cpu > $cpu_max) {
                $name_max = $s[0];
                $cpu_max = $cpu;
        }
}

my $v = 1 + int($cpu_max * $il / 100); 

print '|' x $v, '.' x ($il-$v), "\n", $name_max, ' ', int $cpu_max;

for example, in ~/bin/cpu_monitor_dot.pl
Make it executable and write the path to it in Command “Generic Monitor”.
Period (s) for me 4.5
And the VM generating the highest load will always be in front of your eyes :sunglasses:

7 Likes

Period must be greater than 1 sec because of the 1 sec delay in xentop