Question about OpenVZ.pm

smilie

New Member
Feb 20, 2009
19
0
1
Hi guys,

I have one question. I am currently 'translating' your GUI to a PHP one. I have made a lot of progress, but I am wondering about this one.

I am 'using' a slightly modified OpenVZ.pm perl code to query a status of single VPS machine. So, I have changed it not to loop through all available VPS's on the machine, but to accept parameter like "101.conf" and do the magic only for that one. This works like a charm.

However, I do have one question regarding following bit of a Perl code:

Code:
if ($diff > 1000) { # don't update too often
    my $useddiff = $used - $last_proc_vestat->{$veid}->{used};
    my $pctcpu = int ($useddiff*100/$diff);
    $last_proc_vestat->{$veid}->{sum} = $sum;
    $last_proc_vestat->{$veid}->{used} = $used;
    $last_proc_vestat->{$veid}->{pctcpu} = $d->{pctcpu} = $pctcpu;

    # fixme: openvz --cpus does not work currently
    my $relcpu = $pctcpu;
    $last_proc_vestat->{$veid}->{relcpu} = $d->{relcpu} = $relcpu;

    } else {
    $d->{pctcpu} = $last_proc_vestat->{$veid}->{pctcpu};
    $d->{relcpu} = $last_proc_vestat->{$veid}->{relcpu};
}

Question is:
What should openvz --cpus do (that it doesn't do?) :-)
And, more important - what does relcpu stand for? I really couldn't make it out from the code itself?
I must admit, my Perl knowledge is next to none :-)

Cheers,
Aleks
 
I found another small thing.
Same file: OpenVZ.pm:

Code:
if (my $ip = $conf->{ip_address}->{value}) {
   $ip =~ s/,;/ /g;
   #$d->{ip} = (split(/\s+/, $ip))[0];
   $d->{ip} = $ip;
   } else {
      $d->{ip} = '-';
}

As you can see, I have replaced line:
$d->{ip} = (split(/\s+/, $ip))[0];
with:
$d->{ip} = $ip;

In first case (original code) it gave back only first occurance of the IP. Once VPS had more then 1 IP, I could not see them. Oddly enough, it works OK in your GUI?

Again, my perl knowledge is too low to judge this one :)

Cheers,
Aleks