1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

bugfix cpubyuser plugin

Prior plugin version returns wrong results. I'm not sure why.
This commit fix the bug however it reduce functionality since
there is no way now to include/exclude certain users.
This commit is contained in:
Michał Kadlof 2021-06-12 21:34:09 +02:00
parent 0860ec94cb
commit 6ce54ca9d6

View file

@ -92,26 +92,9 @@ OTHER_PRINT=""
[ -z "$OTHER_FIELD" ] || OTHER_PRINT="print \"$(clean_fieldname "$OTHER_FIELD")\", others_sum;"
ps ax --format "%cpu user" | tail +2 | \
awk -v USERS="$USERS" '
# Store the CPU usage of each process - the mapping to the
# user happens later. We cannot use the second column
# (username) directly, since it may be abbreviated (ending
# with "+").
{ CPU_USER[$2]=$1 }
END {
others_sum = 0
split(USERS, user_array)
for (user in CPU_USER) {
m = match(USERS,user)
if (m != 0) {
_user=user
gsub(/[-.]/,"_",_user);
print _user, (CPU_USER[user])
} else
others_sum += CPU_USER[user]
}
'"$OTHER_PRINT"'
}' | while read -r user count; do
# apply fieldname cleanup
echo "$(clean_fieldname "$user").value $count"
done
awk '{
arr[$2]+=$1
}
END {
for (key in arr) printf("%s.value %s\n", key, arr[key])
}' | sort -k1,1