removed uncessesary conversion, and fixed the print statement to output the processes
This commit is contained in:
parent
d329ed2a3a
commit
f60221254f
25
filter.sh
25
filter.sh
@ -16,7 +16,7 @@ if [ -z "$SMB_PIDS" ]; then
|
||||
fi
|
||||
|
||||
# Checking to see if any PIDs exceed CPU or Time thresholds
|
||||
ps -axo pid,comm,pcpu,etime | awk -v cpu="$CPU_THRESHOLD" -v time="$TIME_THRESHOLD" -v smb_pids="$SMB_PIDS" '
|
||||
ps -eo pid,comm,%cpu,etimes --no-headers | awk -v cpu="$CPU_THRESHOLD" -v time="$TIME_THRESHOLD" -v smb_pids="$SMB_PIDS" '
|
||||
BEGIN {
|
||||
split(smb_pids, arr, " ")
|
||||
for (i in arr) {
|
||||
@ -28,30 +28,11 @@ NR > 1 {
|
||||
next
|
||||
}
|
||||
|
||||
# Converting etime into seconds
|
||||
split($4, parts, "-")
|
||||
if (length(parts) == 2) {
|
||||
days=parts[1]
|
||||
hms=parts[2]
|
||||
} else {
|
||||
days=0
|
||||
hms=parts[1]
|
||||
}
|
||||
|
||||
split(hms, t, ";")
|
||||
if (length(t) == 3) {
|
||||
h=t[1]; m=t[2]; s=t[3]
|
||||
} else if (length(t) == 2) {
|
||||
h=t[1]; m=t[2]; s=0
|
||||
} else {
|
||||
h=0; m=0; s=0
|
||||
}
|
||||
|
||||
elapsed = days*86400 + h*3600 + m*60 + s
|
||||
elapsed = $4
|
||||
|
||||
# Comparing elapsed to thresholds
|
||||
if ($3 >= cpu && elapsed >= time) {
|
||||
printf "PID: %s | Command: %s | CPU: %s%% | Runtime: %s (%.2f hours)\n,$1, $2, $3, $4, elapsed/3600"
|
||||
printf "PID: %s | Command: %s | CPU: %s%% | Runtime: %s (%.2f hours)\n",$1, $2, $3, $4, elapsed/3600
|
||||
}
|
||||
}'
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user