[Bug 214297] [patch] net-mgmt/nagios-check_cpu_usage: Sometimes fails to parse vmstat output

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Mon Nov 7 18:59:49 UTC 2016


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=214297

            Bug ID: 214297
           Summary: [patch] net-mgmt/nagios-check_cpu_usage: Sometimes
                    fails to parse vmstat output
           Product: Ports & Packages
           Version: Latest
          Hardware: Any
                OS: Any
            Status: New
          Keywords: patch
          Severity: Affects Some People
          Priority: ---
         Component: Individual Port(s)
          Assignee: freebsd-ports-bugs at FreeBSD.org
          Reporter: vidar at karlsen.tech
          Keywords: patch

Created attachment 176748
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=176748&action=edit
Change vmstat to iostat

nagios-check_cpu_usage reads output from vmstat in order to report CPU usage.
vmstat will output straight numbers (not "easily human readable form") when the
output is not a terminal.
On a busy host, this may cause the fre and flt columns to be jammed together
with no separating whitespace, which in turn will cause nagios-check_cpu_usage
to return bogus values due to a sort of off-by-one error:

Not busy:
r b w     avm     fre  flt  re  pi  po    fr   sr   in    sy    cs us sy id
0 0 3  762140  490772  693   0   0   0   863    4   70   833   366  1  0 99
               ^^^^^^  ^^^
Busy (just testing running make in security/openssl):
r b w     avm     fre  flt  re  pi  po    fr   sr   in    sy    cs us sy id
1 0 3  865856  48101239575   0 121   0 43154    8   72 40026  1357 21  5 74
               ^^^^^^^^^^^
nagios-check_cpu_usage reads the 15th, 16th and 17th column, so in the latter
case it will report us="5", sy="74", id="".

I propose changing the following line:
cpu_all=$( vmstat -c 2 -n 0 | tail -n 1 | awk '{print $15 " " $16 " " $17}' )
to:
cpu_all=$( iostat -c 2 -t proc | tail -n 1 | awk '{print $3 " " $5 " " $7}' )
or to:
cpu_all=$( vmstat -h -c 2 -n 0 | tail -n 1 | awk '{print $15 " " $16 " " $17}'
)

iostat doesn't appear to have this problem because it outputs much fewer
columns, while the second alternative solution bypasses the problem by forcing
vmstat to print the memory values as 1M instead of 1048576.

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-ports-bugs mailing list