mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 14:16:00 +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' | \
|
top -b -n 1 | sed '1,/^ *PID /d' | \
|
||||||
awk -v USERS="$USERS" '
|
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 {
|
END {
|
||||||
others_sum = 0
|
split(USERS, user_array)
|
||||||
for (user in CPU_USER) {
|
for (user_index in user_array) {
|
||||||
m = match(USERS,user)
|
user = user_array[user_index]
|
||||||
if (m != 0) {
|
# retrieve all process IDs belonging to the user
|
||||||
_user=user
|
"ps -u "user" -o pid --no-headers 2>/dev/null | tr \"\n\" \" \"" | getline pids
|
||||||
gsub(/[-.]/,"_", _user);
|
user_cpu = 0
|
||||||
print _user".value", CPU_USER[user]
|
split(pids, pid_array)
|
||||||
} else
|
# summarize the cpu usage of this usage
|
||||||
others_sum += CPU_USER[user]
|
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