117 lines
4.0 KiB
Plaintext
117 lines
4.0 KiB
Plaintext
config_cpu() {
|
|
extinfo=""
|
|
fields=$(grep '^cpu ' /proc/stat | wc -w)
|
|
if [ "$fields" -gt 5 ]; then extinfo="$extinfo iowait irq softirq"; fi
|
|
if [ "$fields" -gt 8 ]; then extinfo="$extinfo steal"; fi
|
|
if [ "$fields" -gt 9 ]; then extinfo="$extinfo guest"; fi
|
|
if [ "$fields" -gt 10 ]; then extinfo="$extinfo guest_nice"; fi
|
|
# shellcheck disable=SC2126
|
|
NCPU=$(grep '^cpu[0-9]\+ ' /proc/stat | wc -l)
|
|
PERCENT=$((NCPU * 100))
|
|
graphlimit=$PERCENT
|
|
SYSWARNING=$((PERCENT * 30 / 100))
|
|
SYSCRITICAL=$((PERCENT * 50 / 100))
|
|
USRWARNING=$((PERCENT * 80 / 100))
|
|
echo "graph_title CPU usage"
|
|
echo "graph_order system user nice idle $extinfo" | sed 's/ $//'
|
|
echo "graph_args --base 1000 -r --lower-limit 0 --upper-limit $graphlimit"
|
|
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 5000"
|
|
echo "system.min 0"
|
|
echo "system.type DERIVE"
|
|
echo "system.warning $SYSWARNING"
|
|
echo "system.critical $SYSCRITICAL"
|
|
echo "system.info CPU time spent by the kernel in system activities"
|
|
echo "user.label user"
|
|
echo "user.draw STACK"
|
|
echo "user.min 0"
|
|
echo "user.max 5000"
|
|
echo "user.warning $USRWARNING"
|
|
echo "user.type DERIVE"
|
|
echo "user.info CPU time spent by normal programs and daemons"
|
|
echo "nice.label nice"
|
|
echo "nice.draw STACK"
|
|
echo "nice.min 0"
|
|
echo "nice.max 5000"
|
|
echo "nice.type DERIVE"
|
|
echo "nice.info CPU time spent by nice(1)d programs"
|
|
echo "idle.label idle"
|
|
echo "idle.draw STACK"
|
|
echo "idle.min 0"
|
|
echo "idle.max 5000"
|
|
echo "idle.type DERIVE"
|
|
echo "idle.info Idle CPU time"
|
|
if [ "$fields" -gt 5 ]; then
|
|
echo "iowait.label iowait"
|
|
echo "iowait.draw STACK"
|
|
echo "iowait.min 0"
|
|
echo "iowait.max 5000"
|
|
echo "iowait.type DERIVE"
|
|
echo "iowait.info CPU time spent waiting for I/O operations to finish"
|
|
echo "irq.label irq"
|
|
echo "irq.draw STACK"
|
|
echo "irq.min 0"
|
|
echo "irq.max 5000"
|
|
echo "irq.type DERIVE"
|
|
echo "irq.info CPU time spent handling interrupts"
|
|
echo "softirq.label softirq"
|
|
echo "softirq.draw STACK"
|
|
echo "softirq.min 0"
|
|
echo "softirq.max 5000"
|
|
echo "softirq.type DERIVE"
|
|
echo "softirq.info CPU time spent handling 'batched' interrupts"
|
|
fi
|
|
if [ "$fields" -gt 8 ]; then
|
|
echo "steal.label steal"
|
|
echo "steal.draw STACK"
|
|
echo "steal.min 0"
|
|
echo "steal.max 5000"
|
|
echo "steal.type DERIVE"
|
|
echo "steal.info The time that a virtual CPU had runnable tasks, but the virtual CPU itself was not running"
|
|
fi
|
|
if [ "$fields" -gt 9 ]; then
|
|
echo "guest.label guest"
|
|
echo "guest.draw STACK"
|
|
echo "guest.min 0"
|
|
echo "guest.max 5000"
|
|
echo "guest.type DERIVE"
|
|
echo "guest.info The time spent running a virtual CPU for guest operating systems"
|
|
fi
|
|
if [ "$fields" -gt 10 ]; then
|
|
echo "guest_nice.label guest_nice"
|
|
echo "guest_nice.draw STACK"
|
|
echo "guest_nice.min 0"
|
|
echo "guest_nice.max 5000"
|
|
echo "guest_nice.type DERIVE"
|
|
echo "guest_nice.info The time spent running a virtual CPU for a niced guest operating system"
|
|
fi
|
|
}
|
|
fetch_cpu() {
|
|
fields=$(grep '^cpu ' /proc/stat | wc -w)
|
|
CINFO=$(grep '^cpu ' /proc/stat | cut -c6-)
|
|
echo "user.value" "$(echo "$CINFO" | cut -d " " -f 1)"
|
|
echo "nice.value" "$(echo "$CINFO" | cut -d " " -f 2)"
|
|
echo "system.value" "$(echo "$CINFO" | cut -d " " -f 3)"
|
|
echo "idle.value" "$(echo "$CINFO" | cut -d " " -f 4)"
|
|
if [ "$fields" -gt 5 ]; then
|
|
echo "iowait.value" "$(echo "$CINFO" | cut -d " " -f 5)"
|
|
echo "irq.value" "$(echo "$CINFO" | cut -d " " -f 6)"
|
|
echo "softirq.value" "$(echo "$CINFO" | cut -d " " -f 7)"
|
|
fi
|
|
if [ "$fields" -gt 8 ]; then
|
|
echo "steal.value" "$(echo "$CINFO" | cut -d " " -f 8)"
|
|
fi
|
|
if [ "$fields" -gt 9 ]; then
|
|
echo "guest.value" "$(echo "$CINFO" | cut -d " " -f 9)"
|
|
fi
|
|
if [ "$fields" -gt 10 ]; then
|
|
echo "guest_nice.value" "$(echo "$CINFO" | cut -d " " -f 10)"
|
|
fi
|
|
}
|