Compare commits

...

6 Commits

Author SHA1 Message Date
Christian 78df1f77f6
Merge eadf11e04d into 3b6ef20dc1 2024-03-04 20:23:00 +08:00
Steve Schnepp 3b6ef20dc1
Merge pull request #17 from daald/improve-df
Improve df
2023-12-14 14:33:37 +01:00
Daniel Alder c2b8d7315d Fix previous change. The key for config and values was the mountpoint
I accidently changed this to dev. This also works but breaks existing history
2023-12-14 13:26:47 +01:00
Daniel Alder f55b83fdbd Improve df
Before, there were 1+n calls of df where n is the number of output values. I introduced some script magic to use the values from the
first call. Motivation was, there was a very complex sed call which failed to process some of my df output lines. The new code is much
safer.

Actually, the original problem obviously was that the sed regex didn't cover capital letters which I had in my mountpoints.
2023-12-13 14:58:34 +01:00
Christian Schrötter eadf11e04d
Remove nested if-blocks at cpu plugin 2020-05-08 16:33:55 +02:00
Christian Schrötter 2c20918fd4
cpu: Implement steal/guest/guest_nice counters
steal (since Linux 2.6.11)
       (8) Stolen time, which is the time spent in
       other operating systems when running in a virtu‐
       alized environment

guest (since Linux 2.6.24)
       (9) Time spent running a virtual CPU for guest
       operating systems under the control of the Linux
       kernel.

guest_nice (since Linux 2.6.33)
       (10) Time spent running a niced guest (virtual
       CPU for guest operating systems under the con‐
       trol of the Linux kernel).
2020-05-08 16:16:19 +02:00
2 changed files with 48 additions and 18 deletions

View File

@ -1,8 +1,10 @@
config_cpu() {
extinfo=""
if grep -q '^cpu \{1,\}[0-9]\{1,\} \{1,\}[0-9]\{1,\} \{1,\}[0-9]\{1,\} \{1,\}[0-9]\{1,\} \{1,\}[0-9]\{1,\} \{1,\}[0-9]\{1,\} \{1,\}[0-9]\{1,\}' /proc/stat; then
extinfo="iowait irq softirq"
fi
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))
@ -45,7 +47,7 @@ config_cpu() {
echo "idle.max 5000"
echo "idle.type DERIVE"
echo "idle.info Idle CPU time"
if [ -n "$extinfo" ]; then
if [ "$fields" -gt 5 ]; then
echo "iowait.label iowait"
echo "iowait.draw STACK"
echo "iowait.min 0"
@ -65,20 +67,50 @@ config_cpu() {
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() {
extinfo=""
if grep -q '^cpu \{1,\}[0-9]\{1,\} \{1,\}[0-9]\{1,\} \{1,\}[0-9]\{1,\} \{1,\}[0-9]\{1,\} \{1,\}[0-9]\{1,\} \{1,\}[0-9]\{1,\} \{1,\}[0-9]\{1,\}' /proc/stat; then
extinfo="iowait irq softirq"
fi
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 [ -n "$extinfo" ]; then
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
}

View File

@ -4,21 +4,19 @@ graph_args --upper-limit 100 -l 0
graph_vlabel %
graph_category disk
graph_info This graph shows disk usage on the machine."
for PART in $(df -PT | grep '^/' | grep -vwE "$DF_IGNORE_FILESYSTEM_REGEX" | sed '/\/[a-z0-9]*$/!d;s/.* \([a-z0-9\/]\{1,\}\)$/\1/g')
df -PT | grep '^/' | grep -vwE "$DF_IGNORE_FILESYSTEM_REGEX" | while read dev type blocks used avail pct mp
do
PINFO=$(df -P "$PART" | tail -1);
PNAME=$(clean_fieldname "$(echo "$PINFO" | cut -d " " -f 1)")
echo "$PNAME.label $PART"
echo "$PNAME.info $PNAME -> $PART"
PNAME=$(clean_fieldname "$mp")
echo "$PNAME.label $mp"
echo "$PNAME.info $dev -> $mp"
echo "$PNAME.warning 92"
echo "$PNAME.critical 98"
done
}
fetch_df() {
for PART in $(df -PT | grep '^/' | grep -vwE "$DF_IGNORE_FILESYSTEM_REGEX" | sed '/\/[a-z0-9]*$/!d;s/.* \([a-z0-9\/]\{1,\}\)$/\1/g')
df -PT | grep '^/' | grep -vwE "$DF_IGNORE_FILESYSTEM_REGEX" | while read dev type blocks used avail pct mp
do
PINFO=$(df -P "$PART" | tail -1);
PNAME=$(clean_fieldname "$(echo "$PINFO" | cut -d " " -f 1)")
echo "$PNAME.value" "$(echo "$PINFO" | sed -e 's/\%//g' -e 's/ */ /g' | cut -d " " -f 5)"
PNAME=$(clean_fieldname "$mp")
echo "$PNAME.value" "${pct%\%}"
done
}