Skip to content

Instantly share code, notes, and snippets.

@defanator
Last active November 9, 2016 19:31
Show Gist options
  • Save defanator/529c764738dafdb26153c4f4a9b8899b to your computer and use it in GitHub Desktop.
Save defanator/529c764738dafdb26153c4f4a9b8899b to your computer and use it in GitHub Desktop.
nginx memory leaks monitoring
#!/bin/sh
nginxpidfile=/var/run/nginx.pid
if [ ! -e ${nginxpidfile} ]; then
echo "nginx pid file (${nginxpidfile}) not found" >&2
exit 1
fi
ppid=`cat ${nginxpidfile}`
kill -0 ${ppid} >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "nginx is not running or stale pid file?" >&2
exit 1
fi
echo "Watching for nginx (master pid=${ppid})"
i=0
while [ :: ]; do
echo -n "`date` [$i]: "
mstat=`ps -p ${ppid} -ho pid,vsz,rss 2>&1 | awk '{print "master " $2 "/" $3}'`
wstat=`ps --ppid ${ppid} -ho pid,vsz,rss 2>&1 | awk '{vsz=vsz+$2; rss=rss+$3; n=n+1} END {print "workers(" n ") " vsz "/" rss;}'`
echo "${mstat} ${wstat}"
# service nginx reload >/dev/null 2>&1
sleep 1
i=$((i+1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment