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

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, February 17, 2012

Follow me on Twitter as @mattiasgeniar

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.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.