Skip to content

Instantly share code, notes, and snippets.

@jeremywadsack
Created November 16, 2016 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremywadsack/a95d29ea6911a6112b6b378f68686cf2 to your computer and use it in GitHub Desktop.
Save jeremywadsack/a95d29ea6911a6112b6b378f68686cf2 to your computer and use it in GitHub Desktop.
Get postgres memory usage and send it to graphite
#!/usr/bin/env bash
# Uses du to track the amount of disk space that postgres is using to hold queries that don't fit in memory.
# Uses smem to track USS, PSS, and RSS for the postrgres user for various views of how much memory it is using.
# Add this to crontab to run every minute.
# * * * * * /path/to/pg_graphite.sh
# Configure for your graphite host
PORT=2003
SERVER=carbon.hostedgraphite.com
API_KEY=11111111-2222-3333-4444-5555555555
HOST=db-ga
du -sk /data/pgsql/9.5/data/base/pgsql_tmp/ | awk '{print "'$API_KEY'.postgres.'$HOST'.tmp " $1 " " strftime("%s")}' | nc $SERVER $PORT
/usr/local/bin/smem -u | grep postgres | awk '{print "'$API_KEY'.postgres.'$HOST'.uss " $4 " " strftime("%s")}' | nc $SERVER $PORT
/usr/local/bin/smem -u | grep postgres | awk '{print "'$API_KEY'.postgres.'$HOST'.pss " $5 " " strftime("%s")}' | nc $SERVER $PORT
/usr/local/bin/smem -u | grep postgres | awk '{print "'$API_KEY'.postgres.'$HOST'.rss " $6 " " strftime("%s")}' | nc $SERVER $PORT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment