Improvements to the fd checker

1. Finds listening processes automatically
2. Reports highest value among processes for each connection type
3. Reduces lsof calls
4. Uses munin-like output
This commit is contained in:
Sandro Santilli 2013-02-08 15:24:25 +01:00
parent 6b71cde56e
commit 56319a5ac0

View File

@ -1,42 +1,42 @@
#!/bin/sh #!/bin/sh
# Sorry, you must currently manually edit the regexp to make this work http_port=8181
# on your machine. db_port=6432
redis_port=6379
master_pid=$(ps xa | grep windshaft | grep -v local | grep -v grep | awk '{print $1}') pids=$(lsof -i :${http_port} | grep LISTEN | awk '{print $2}')
nworkers=$(echo "${pids}" | wc -l)
pids=$(echo "${pids}" | paste -sd ' ')
# TODO: use pid files tmpreport="/tmp/checkfd.$$.txt"
worker_pids=$(ps xa | grep windshaft | grep local | awk '{print $1}' |
python -c "import sys; print ','.join((x.strip() for x in sys.stdin.readlines()))")
if test -z "${worker_pids}"; then lsof -p $(echo "${pids}" | tr ' ' ',') > "${tmpreport}"
echo "No workers found"
exit 1
fi
echo "Master: $master_pid" maxdb=0
echo "Workers: $worker_pids" maxredis=0
maxhttp=0
maxtot=0
for pid in $(echo $worker_pids | tr ',' ' '); do for pid in ${pids}; do
pidrep="/tmp/checkfd.$pid.txt" cnt=$(grep "${pid}" "${tmpreport}" | grep ":${db_port} " | wc -l);
if test $cnt -gt $maxdb; then maxdb=$cnt; fi
cnt=$(grep "${pid}" "${tmpreport}" | grep ":${redis_port} " | wc -l);
if test $cnt -gt $maxredis; then maxredis=$cnt; fi
lsof -p $pid > "${pidrep}" cnt=$(grep "${pid}" "${tmpreport}" | grep ":${http_port} " | grep -v "LISTEN" | wc -l);
if test $cnt -gt $maxhttp; then maxhttp=$cnt; fi
echo -n "worker $pid postgres: " cnt=$(grep "${pid}" "${tmpreport}" | wc -l);
cat "${pidrep}" | grep ':6432 .EST' | wc -l; if test $cnt -gt $maxtot; then maxtot=$cnt; fi
echo -n "worker $pid redis: "
cat "${pidrep}" | grep ':6379 .EST' | wc -l;
echo -n "worker $pid incoming http: "
cat "${pidrep}" | grep ':8181' | wc -l;
echo -n "worker $pid total: "
cat "${pidrep}" | wc -l;
done done
echo "procs.value ${nworkers}"
echo "pgsql.value ${maxdb}"
echo "redis.value ${maxredis}"
echo "http.value ${maxhttp}"
echo "nfd.value ${maxtot}"
echo -n "master $master_pid total: " rm -f "${tmpreport}"
lsof -p $master_pid | grep node | wc -l;