Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix cpubyuser plugin #1222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 6 additions & 23 deletions plugins/user/cpubyuser
Original file line number Diff line number Diff line change
Expand Up @@ -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