Windshaft-cartodb/tools/checkfds.sh

43 lines
1005 B
Bash
Raw Normal View History

2013-02-07 19:32:06 +08:00
#!/bin/sh
http_port=8181
db_port=6432
redis_port=6379
2013-02-07 19:32:06 +08:00
pids=$(lsof -i :${http_port} | grep LISTEN | awk '{print $2}')
nworkers=$(echo "${pids}" | wc -l)
pids=$(echo "${pids}" | paste -sd ' ')
2013-02-07 19:32:06 +08:00
tmpreport="/tmp/checkfd.$$.txt"
2013-02-07 19:32:06 +08:00
lsof -p $(echo "${pids}" | tr ' ' ',') > "${tmpreport}"
2013-02-07 19:32:06 +08:00
maxdb=0
maxredis=0
maxhttp=0
maxtot=0
2013-02-07 19:32:06 +08:00
for pid in ${pids}; do
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
cnt=$(grep "${pid}" "${tmpreport}" | grep ":${http_port} " | grep -v "LISTEN" | wc -l);
if test $cnt -gt $maxhttp; then maxhttp=$cnt; fi
cnt=$(grep "${pid}" "${tmpreport}" | wc -l);
if test $cnt -gt $maxtot; then maxtot=$cnt; fi
2013-02-07 19:32:06 +08:00
done
echo "procs.value ${nworkers}"
echo "pgsql.value ${maxdb}"
echo "redis.value ${maxredis}"
echo "http.value ${maxhttp}"
echo "nfd.value ${maxtot}"
2013-02-07 19:32:06 +08:00
rm -f "${tmpreport}"