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>
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};