Created
October 7, 2024 17:39
-
-
Save qrkourier/9d508a32b43f5206d922c1f6feae09a8 to your computer and use it in GitHub Desktop.
Count open files for commands: ziti-edge-tunnel run, ziti controller run, and ziti router run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
printf 'Open\tSock\tUnix\tFile\tCommand\n' | |
for CMD in 'ziti router run' 'ziti controller run' 'ziti-edge-tunnel run' | |
do | |
for PID in $(pgrep -f "$CMD") | |
do | |
# Capture lsof output for the process | |
lsof_output=$(sudo lsof -Pnp "$PID" 2>/dev/null) | |
# Total open files | |
total_open=$(echo "$lsof_output" | wc -l) | |
# Count by file types using awk to specifically match the 5th column | |
sock_count=$(echo "$lsof_output" | awk '$5 ~ /IPv[46]/ {count++} END {print count+0}') | |
unix_count=$(echo "$lsof_output" | awk '$5 == "unix" {count++} END {print count+0}') | |
file_count=$(echo "$lsof_output" | awk '$5 ~ /REG|DIR|LINK/ {count++} END {print count+0}') | |
# Print the totals in the desired format | |
printf '%d\t%d\t%d\t%d\t%s\n' "$total_open" "$sock_count" "$unix_count" "$file_count" "$(ps -o args= -p "$PID")" | |
done | |
done \ | |
| sort -nr | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment