[pve-devel] [PATCH pve-container] fix hardcoded CT uptime in vmstatus

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Sep 30 14:24:20 CEST 2015


This differs from the way it's done for qemu, but we could it implement 
it for LXC the same way. IMO the proposed way with ctime is a bit nicer, 
as it mirros the lxcfs behaviour and needs less calls to proc.

FYI, when we would do it like in QemuServer.pm it would look like this:

> diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
> index 99496f9..3fdce0f 100644
> --- a/src/PVE/LXC.pm
> +++ b/src/PVE/LXC.pm
> @@ -23,6 +23,8 @@ use Data::Dumper;
>
>  my $nodename = PVE::INotify::nodename();
>
> +my $cpuinfo = PVE::ProcFSTools::read_cpuinfo();
> +
>  cfs_register_file('/lxc/', \&parse_pct_config, \&write_pct_config);
>
>  my $rootfs_desc = {
> @@ -801,11 +803,15 @@ sub vmstatus {
>         $d->{template} = is_template($conf);
>      }
>
> +    my ($uptime) = PVE::ProcFSTools::read_proc_uptime(1);
> +
>      foreach my $vmid (keys %$list) {
>         my $d = $list->{$vmid};
>         next if $d->{status} ne 'running';
>
> -       $d->{uptime} = 100; # fixme:
> +       my $pid = find_lxc_pid($vmid);
> +       my $pstat = PVE::ProcFSTools::read_proc_pid_stat($pid);
> +       $d->{uptime} = int(($uptime - 
> $pstat->{starttime})/$cpuinfo->{user_hz});
>
>         $d->{mem} = read_cgroup_value('memory', $vmid, 
> 'memory.usage_in_bytes');
>         $d->{swap} = read_cgroup_value('memory', $vmid, 
> 'memory.memsw.usage_in_bytes') - $d->{mem};

regards


On 09/30/2015 02:20 PM, Thomas Lamprecht wrote:
> Implement the container uptime by susbtracting the ctime from the
> container pid file from the actual time.
> This mirrors the behaviour of lxcfs, see get_pid1_time() in lxcfs.c.
> This hass some limitations, like frozen or live migrated containers
> falsify the real uptime. But as it shows everytime the uptime like
> a uptime command in the container would this is forgivable, for now.
>
> Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
> ---
>   src/PVE/LXC.pm | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
> index 99496f9..ccd8c27 100644
> --- a/src/PVE/LXC.pm
> +++ b/src/PVE/LXC.pm
> @@ -805,7 +805,9 @@ sub vmstatus {
>   	my $d = $list->{$vmid};
>   	next if $d->{status} ne 'running';
>   
> -	$d->{uptime} = 100; # fixme:
> +	my $pid = find_lxc_pid($vmid);
> +	my $ctime = (stat("/proc/$pid"))[10]; # 10 = ctime
> +	$d->{uptime} = time - $ctime; # the method lxcfs uses
>   
>   	$d->{mem} = read_cgroup_value('memory', $vmid, 'memory.usage_in_bytes');
>   	$d->{swap} = read_cgroup_value('memory', $vmid, 'memory.memsw.usage_in_bytes') - $d->{mem};





More information about the pve-devel mailing list