2013-02-07 19:32:06 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
2013-02-08 23:47:59 +08:00
|
|
|
envnik=$(basename "${TILER_ENVIRONMENT}" .js)
|
|
|
|
|
2013-02-08 23:08:24 +08:00
|
|
|
if test "$1" = "config"; then
|
2013-02-09 00:05:43 +08:00
|
|
|
echo "graph_title fd usage (${envnik})"
|
2013-02-08 23:47:59 +08:00
|
|
|
cat <<"EOM"
|
2013-02-09 00:05:43 +08:00
|
|
|
graph_vlabel number of file descriptors
|
|
|
|
graph_category windshaft
|
2013-02-09 00:48:54 +08:00
|
|
|
graph_scale no
|
2013-02-08 23:08:24 +08:00
|
|
|
procs.label Number of tiler processes
|
|
|
|
pgsql.label PostgreSQL connections (max)
|
|
|
|
redis.label Redis connections (max)
|
|
|
|
http.label Incoming http requests (max)
|
2013-02-12 00:35:17 +08:00
|
|
|
caches.label Number of renderer caches (max)
|
2013-02-09 00:05:43 +08:00
|
|
|
nfd.label Total file descriptors (max)
|
2013-02-08 23:08:24 +08:00
|
|
|
EOM
|
|
|
|
exit 0
|
2013-02-08 23:44:34 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
if test x"$1" != x; then
|
2013-02-12 01:23:35 +08:00
|
|
|
TILER_ENVIRONMENT=$(cd $(dirname $0); pwd)/../../config/environments/${1}.js
|
2013-02-08 23:44:34 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
if test -z "$TILER_ENVIRONMENT"; then
|
|
|
|
echo "Usage: $0 [<environment>]" >&2
|
|
|
|
echo " or: [TILER_ENVIRONMENT=<environment>] $0" >&2
|
|
|
|
exit 1
|
2013-02-08 23:08:24 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
http_port=$(echo "console.log(require('${TILER_ENVIRONMENT}').port)" | node) || exit 1
|
|
|
|
pgsql_port=$(echo "console.log(require('${TILER_ENVIRONMENT}').postgres.port)" | node) || exit 1
|
|
|
|
redis_port=$(echo "console.log(require('${TILER_ENVIRONMENT}').redis.port)" | node) || exit 1
|
2013-02-07 19:32:06 +08:00
|
|
|
|
2013-02-08 22:24:25 +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
|
|
|
|
2013-02-08 23:08:24 +08:00
|
|
|
if test -z "${pids}"; then
|
|
|
|
echo "No processes found listening on tcp port '${http_port}'" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2013-02-08 22:24:25 +08:00
|
|
|
tmpreport="/tmp/checkfd.$$.txt"
|
2013-02-07 19:32:06 +08:00
|
|
|
|
2013-02-20 19:12:35 +08:00
|
|
|
lsof -Pp $(echo "${pids}" | tr ' ' ',') > "${tmpreport}"
|
2013-02-07 19:32:06 +08:00
|
|
|
|
2013-02-08 22:24:25 +08:00
|
|
|
maxdb=0
|
|
|
|
maxredis=0
|
|
|
|
maxhttp=0
|
|
|
|
maxtot=0
|
2013-02-12 00:35:17 +08:00
|
|
|
maxcache=0
|
2013-02-07 19:32:06 +08:00
|
|
|
|
2013-02-08 22:24:25 +08:00
|
|
|
for pid in ${pids}; do
|
2013-02-07 20:26:11 +08:00
|
|
|
|
2013-02-08 23:08:24 +08:00
|
|
|
cnt=$(grep "${pid}" "${tmpreport}" | grep ":${pgsql_port} " | wc -l);
|
2013-02-08 22:24:25 +08:00
|
|
|
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
|
2013-02-07 20:26:11 +08:00
|
|
|
|
2013-02-09 01:17:15 +08:00
|
|
|
cnt=$(grep "${pid}" "${tmpreport}" | grep ":${http_port}-" | grep -v "LISTEN" | wc -l);
|
2013-02-08 22:24:25 +08:00
|
|
|
if test $cnt -gt $maxhttp; then maxhttp=$cnt; fi
|
2013-02-07 20:26:11 +08:00
|
|
|
|
2013-02-08 22:24:25 +08:00
|
|
|
cnt=$(grep "${pid}" "${tmpreport}" | wc -l);
|
|
|
|
if test $cnt -gt $maxtot; then maxtot=$cnt; fi
|
2013-02-07 20:26:11 +08:00
|
|
|
|
2013-02-12 00:35:17 +08:00
|
|
|
log=$(grep "${pid}" "${tmpreport}" | grep -w 1w | awk '{print $9}')
|
|
|
|
if test -e "${log}"; then
|
2013-03-18 23:37:31 +08:00
|
|
|
kill -USR2 "${pid}"
|
2014-02-19 22:38:14 +08:00
|
|
|
cnt=$(tac ${log} | sed -n -e '/ItemKey/p;/ RenderCache /q' | wc -l)
|
2013-02-12 00:35:17 +08:00
|
|
|
if test $cnt -gt $maxcache; then maxcache=$cnt; fi
|
|
|
|
else
|
|
|
|
# report the error...
|
|
|
|
maxcache=-1
|
|
|
|
fi
|
|
|
|
|
2013-02-07 19:32:06 +08:00
|
|
|
done
|
|
|
|
|
2013-02-08 22:24:25 +08:00
|
|
|
echo "procs.value ${nworkers}"
|
|
|
|
echo "pgsql.value ${maxdb}"
|
|
|
|
echo "redis.value ${maxredis}"
|
|
|
|
echo "http.value ${maxhttp}"
|
2013-02-12 00:35:17 +08:00
|
|
|
echo "caches.value ${maxcache}"
|
2013-02-08 22:24:25 +08:00
|
|
|
echo "nfd.value ${maxtot}"
|
2013-02-07 19:32:06 +08:00
|
|
|
|
2013-02-08 22:24:25 +08:00
|
|
|
rm -f "${tmpreport}"
|