Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vmstat does not return an average for last line #14

Open
babbottscott opened this issue Jul 19, 2017 · 0 comments
Open

vmstat does not return an average for last line #14

babbottscott opened this issue Jul 19, 2017 · 0 comments

Comments

@babbottscott
Copy link

This script purports to check cpu state over a specified interval, but uses vmstat to check state, then assumes the last line gives an average. Suggest changing from vmstat to sar. To overcome the problem of processing float output in bash, can use bc to process.

Linux avg cpu over interval:

  Linux)
    CPU_REPORT=`/usr/bin -u $INTERVAL_SEC $NUM_REPORT | tail -1`
    CPU_USER=`echo $CPU_REPORT | awk '{ print $3 }'`
    CPU_SYSTEM=`echo $CPU_REPORT | awk '{ print $5 }'`
    CPU_IOWAIT=`echo $CPU_REPORT | awk '{ print $6 }'`
    CPU_IDLE=`echo $CPU_REPORT | awk '{ print $8 }'`

Floating point comparison for bash/bc

float_ge() {
  [ $(echo "$1 >= $2" | /usr/bin/bc) -eq 1 ]
}

Floating point comparison in use:

if float_ge "${CPU_IOWAIT}" "${IO_CPU_C}" || float_ge "${CPU_USER}" "${U_CPU_C}" || float_ge "${CPU_SYSTEM}" "${S_CPU_C}";
then
...

Requires packages sysstat and bc to fully implement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant