mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 02:51:03 +00:00
[cpubyuser] improve parsing for long usernames (Closes: #757)
"ps" abbreviates long username - thus we prepare a separate mapping
This commit is contained in:
parent
5bec8ec6b5
commit
8280dbb0f5
1 changed files with 27 additions and 12 deletions
|
@ -74,17 +74,32 @@ fi
|
|||
|
||||
top -b -n 1 | sed '1,/^ *PID /d' | \
|
||||
awk -v USERS="$USERS" '
|
||||
{ CPU_USER[$2]+=$9 }
|
||||
# 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_PER_PID[$1]=$9 }
|
||||
END {
|
||||
others_sum = 0
|
||||
for (user in CPU_USER) {
|
||||
m = match(USERS,user)
|
||||
if (m != 0) {
|
||||
_user=user
|
||||
gsub(/[-.]/,"_", _user);
|
||||
print _user".value", CPU_USER[user]
|
||||
} else
|
||||
others_sum += CPU_USER[user]
|
||||
split(USERS, user_array)
|
||||
for (user_index in user_array) {
|
||||
user = user_array[user_index]
|
||||
# retrieve all process IDs belonging to the user
|
||||
"ps -u "user" -o pid --no-headers 2>/dev/null | tr \"\n\" \" \"" | getline pids
|
||||
user_cpu = 0
|
||||
split(pids, pid_array)
|
||||
# summarize the cpu usage of this usage
|
||||
for (pid_index in pid_array) {
|
||||
pid = pid_array[pid_index]
|
||||
user_cpu += CPU_PER_PID[pid]
|
||||
delete CPU_PER_PID[pid]
|
||||
}
|
||||
print "others.value", others_sum;
|
||||
}'
|
||||
print user, user_cpu
|
||||
}
|
||||
# add all remaining cpu usages into "others"
|
||||
others_sum = 0
|
||||
for (other_usage in CPU_PER_PID) others_sum+=CPU_PER_PID[other_usage]
|
||||
print "'"$OTHER_FIELD"'", others_sum;
|
||||
}' | while read -r user count; do
|
||||
# apply fieldname cleanup
|
||||
echo "$(clean_fieldname "$user").value $count"
|
||||
done
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue