[Xymon] xymon freebsd memory calculations

Brian Scott Brian.Scott at tafensw.edu.au
Fri Apr 27 04:13:38 CEST 2012


Hi people,

I was just trying to track down why the memory used was showing 0% on my
FreeBSD systems and have found an interesting bug.

The logic in xymond/client/freebsd.c is a little funny with fall back
positions depending on what is supplied from the client, but essentially
if there is no vmtotal section in the client data (old client) then the
figure is used from meminfo which has been pretty good (but perhaps not
perfect). If there is a section “Free Memory Pages” in the vmtoal section
then that number is used in preference.

Problems:

• The number is in K bytes so must be adjusted for use.

• The offset to the end of the searched for string is 19 not 18 (must
count the leading newline).

• We aren’t calculating memphyused if we use the vmtotal method.

• The string “Free Memory Pages:” changes to “Free Memory:” with revision
234134 by eadler, Wed Apr 11 14:18:18 2012 UTC to
/head/sbin/sysctl/sysctl.c
(http://svnweb.freebsd.org/base/head/sbin/sysctl/sysctl.c?r1=234133&r2=234134&).

My suggested fix is to change the logic at line 82 onwards in
xymond/client/freebsd.c to read as follows:

if (vmtotalstr) {
    p = strstr(vmtotalstr, "\nFree Memory Pages:");
    if (p) {
        memphysfree = atol(p + 19)/1024;
        memphysused = memphystotal - memphysfree;
        found++;
    } else {
        p = strstr(vmtotalstr, "\nFree Memory:");
        if (p) {
            memphysfree = atol(p + 13)/1024;
            memphysused = memphystotal - memphysfree;
            found++;
        }
    }
}

Regards,

Brian Scott

P.S. I have CC’d the FreeBSD port maintainer for xymon but offcourse this
fix is needed on any server if any monitored client is running FreeBSD.





More information about the Xymon mailing list