Skip to content

Instantly share code, notes, and snippets.

@hanshasselberg
Created December 19, 2012 03:16
Show Gist options
  • Save hanshasselberg/4334087 to your computer and use it in GitHub Desktop.
Save hanshasselberg/4334087 to your computer and use it in GitHub Desktop.
# number postgres connections
sudo ps -ef | grep postgres | wc -l
# disk usage
iostat 5
# memory
mpstat 5
# slow req per second
tail -f /var/log/postgresql/postgresql-9.1-main.log | perl -e 'while (<>) {$l++;if (time > $e) {$e=time;print "$l\n";$l=0}}'
# slow query duration
tail -f /var/log/postgresql/postgresql-9.1-main.log | cut -d ' ' -f 7
# req per second
def curr
`psql -c 'SELECT SUM(xact_commit) FROM pg_stat_database;' 2> /dev/null`.split("\n"
)[2].strip.to_i
end
while true
start = curr
sleep(1)
p curr - start
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment