diff --git a/cpu b/cpu new file mode 100755 index 0000000..9141dac --- /dev/null +++ b/cpu @@ -0,0 +1,79 @@ +#!/bin/sh +# +# Copyright (c) 2017 Babak Farrokhi. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +#%# family=auto +#%# capabilities=autoconf + +if [ "$1" = "autoconf" ]; then + echo yes +fi + +if [ "$1" = "config" ]; then + + echo 'graph_title CPU usage' + echo 'graph_order system interrupt user nice idle' + echo "graph_args --base 1000 -r --lower-limit 0 --upper-limit $PERCENT " + echo 'graph_vlabel %' + echo 'graph_scale no' + echo 'graph_info This graph shows how CPU time is spent.' + echo 'graph_category system' + echo 'graph_period second' + echo 'system.label system' + echo 'system.draw AREA' + echo 'system.max 100' + echo 'system.type DERIVE' + echo 'system.min 0' + echo 'system.info CPU time spent by the kernel in system activities' + echo 'interrupt.label interrupt' + echo 'interrupt.draw STACK' + echo 'interrupt.max 100' + echo 'interrupt.type DERIVE' + echo 'interrupt.min 0' + echo 'interrupt.info CPU time spent by the kernel processing interrupts' + echo 'user.label user' + echo 'user.draw STACK' + echo 'user.max 100' + echo 'user.type DERIVE' + echo 'user.info CPU time spent by normal programs and daemons' + echo 'user.min 0' + echo 'nice.label nice' + echo 'nice.draw STACK' + echo 'nice.max 100' + echo 'nice.type DERIVE' + echo 'nice.info CPU time spent by nice(1)d programs' + echo 'nice.min 0' + echo 'idle.label idle' + echo 'idle.draw STACK' + echo 'idle.max 100' + echo 'idle.type DERIVE' + echo 'idle.info Idle CPU time' + echo 'idle.min 0' + exit 0 +fi + +iostat -c2 -w0.1 -n0 | tail -1 | awk '{ print "user.value " $3 "\nnice.value " $4 "\nsystem.value " $5 "\ninterrupt.value " $6 "\nidle.value " $7 }' +