Created
January 14, 2013 17:43
-
-
Save jwatson/4531825 to your computer and use it in GitHub Desktop.
Automate capturing PgBadger analysis.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import time | |
from fabric.api import get, local, run, sudo | |
def run_pg_badger(): | |
db_name = "mapkin" | |
sudo("perl -pi -e 's/log_min_duration_statement = .*/log_min_duration_statement = 0/' /etc/postgresql/9.*/main/postgresql.conf") | |
sudo("/etc/init.d/postgresql reload") | |
print("Sleeping for 60s") | |
time.sleep(60) | |
sudo("perl -pi -e 's/log_min_duration_statement = .*/log_min_duration_statement = 500/' /etc/postgresql/9.*/main/postgresql.conf") | |
sudo("/etc/init.d/postgresql reload") | |
run("tail -n 100000 /var/log/postgresql/postgresql-9.*-main.log > /tmp/pgbadger.txt") | |
run("gzip -f /tmp/pgbadger.txt") | |
get("/tmp/pgbadger.txt.gz", local_path="/tmp/latest-pgbadger.txt.gz") | |
local("gunzip -f /tmp/latest-pgbadger.txt.gz") | |
now = int(time.time()) | |
local("pgbadger -f stderr -o /tmp/pgbadger-%s-%d.html -q /tmp/latest-pgbadger.txt" % (db_name, now)) | |
local('open /tmp/pgbadger-%s-%d.html' % (db_name, now)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment