Skip to content

Instantly share code, notes, and snippets.

@thomasv314
Created January 16, 2025 19:28
Show Gist options
  • Save thomasv314/ff5d92d9b7429f5830bfc154752b2094 to your computer and use it in GitHub Desktop.
Save thomasv314/ff5d92d9b7429f5830bfc154752b2094 to your computer and use it in GitHub Desktop.
inspect number of processes/cores
#!/usr/bin/env bash
# set -ex
deployments=$(kubectl get pods -o jsonpath='{.items[?(@.status.phase=="Running")].metadata.name}')
for deployment in $deployments; do
# echo "$deployment"
kubectl exec -it $deployment -- /bin/sh -c '
num_processors=$(cat /proc/cpuinfo | grep processor | wc -l)
total_processes=0
for pid in /proc/[0-9]*; do
pid=$(basename $pid)
cmdline=$(cat /proc/$pid/cmdline 2>/dev/null | tr "\0" " ")
# Uncomment following line to see proc info
# echo "$pid - $cmdline"
total_processes=$(expr "$total_processes" + 1)
done;
hostname=$(cat /etc/hostname)
extra=" has $total_processes procs running on node w/ $num_processors cores"
if [ "$total_processes" -gt 10 ]; then
printf "\033[31m%s\033[0m %s\n" "$hostname" "$extra"
else
printf "%s %s\n" "$hostname" "$extra"
fi
'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment