Skip to content

Commit

Permalink
Remove nested if-blocks at cpu plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
killerbees19 committed May 8, 2020
1 parent 2c20918 commit eadf11e
Showing 1 changed file with 37 additions and 45 deletions.
82 changes: 37 additions & 45 deletions plugins/cpu
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
config_cpu() {
extinfo=""
fields=$(grep '^cpu ' /proc/stat | wc -w)
if [ "$fields" -gt 5 ]; then
extinfo="$extinfo iowait irq softirq"
if [ "$fields" -gt 8 ]; then
extinfo="$extinfo steal"
if [ "$fields" -gt 9 ]; then
extinfo="$extinfo guest"
if [ "$fields" -gt 10 ]; then
extinfo="$extinfo guest_nice"
fi
fi
fi
fi
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))
Expand Down Expand Up @@ -74,30 +66,30 @@ config_cpu() {
echo "softirq.max 5000"
echo "softirq.type DERIVE"
echo "softirq.info CPU time spent handling 'batched' interrupts"
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"
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"
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
fi
fi
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() {
Expand All @@ -111,14 +103,14 @@ fetch_cpu() {
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)"
if [ "$fields" -gt 8 ]; then
echo "steal.value" "$(echo "$CINFO" | cut -d " " -f 8)"
if [ "$fields" -gt 9 ]; then
echo "guest.value" "$(echo "$CINFO" | cut -d " " -f 9)"
if [ "$fields" -gt 10 ]; then
echo "guest_nice.value" "$(echo "$CINFO" | cut -d " " -f 10)"
fi
fi
fi
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
}

0 comments on commit eadf11e

Please sign in to comment.