The bugged sysinfo() call in OpenVZ hosts running Kernel 2.6.32+

There is a rather annoying bug in the sysinfo C library if you’re running the OpenVZ kernel version 2.6.32 or higher. The problem is that the library used to return correct values for the uptime report, but since a few months appears to be broken and always returns 0. If you’re using monitoring agents (ie: zabbix) that rely on that sysinfo() call to determine the uptime, you’ll get funky reports about servers keeping their uptime of 0 minutes.

Here’s a way to verify the problem. Create a small C-program like this, called stats.c.

#include <sys/sysinfo.h>
#include <stdio.h>

int main() {
        struct sysinfo sys;

        /* Get the sysinfo */
        sysinfo(&sys);

        /* Output */
        printf("Uptime in seconds: %d\n", sys.uptime);
        return 0;
}

Compile it and run it.

~# gcc stats.c -o stats
~# chmod +x stats
~# ./stats
Uptime in seconds: 0
~# uptime
 16:44:27 up 27 min,  0 users,  load average: 0.00, 0.00, 0.00
~# cat /proc/uptime 
1685.92 151770.28

And it will always output “Uptime in seconds: 0”, regardless of your actual uptime reported in /proc/uptime or via the uptime command.

If you’re having this problem with Zabbix Agents, there’s a bugreport filed as ZBX-4230 but since it’s an actual problem only on OpenVZ, I think we can only hope to see it fixed in Bug 2051 at OpenVZ.org.