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.lampre...@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};
-- 
2.1.4


_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to