]> git.proxmox.com Git - pve-container.git/commitdiff
fix hardcoded CT uptime in vmstatus
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 30 Sep 2015 12:20:16 +0000 (14:20 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 30 Sep 2015 12:58:48 +0000 (14:58 +0200)
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@proxmox.com>
src/PVE/LXC.pm

index 99496f9328fd7e385f1574ab4848ad41de806b20..ccd8c27e593adca0266c2fa19a24f34501c1e0e9 100644 (file)
@@ -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};