Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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