Last active
August 29, 2015 14:12
-
-
Save davidszotten/a2c362ce85c233571106 to your computer and use it in GitHub Desktop.
uwsgi dumper
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
#!/usr/bin/env python | |
import datetime | |
import os | |
import socket | |
import subprocess | |
import sys | |
ERROR = ' HTTP/1.1" 499' | |
def follow(filename): | |
proc = subprocess.Popen( | |
['tail', '-n', '0', '-F', filename], | |
stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE, | |
) | |
while True: | |
line = proc.stdout.readline() | |
if ERROR in line: | |
yield line | |
def list_sockets(path): | |
return os.listdir(path) | |
def print_tbs(path): | |
for socket_name in list_sockets(path): | |
abs_name = os.path.join(path, socket_name) | |
print_tb(abs_name) | |
def print_tb(socket_name): | |
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
try: | |
sock.connect(socket_name) | |
msg = '{}:\n'.format(socket_name) | |
while msg: | |
print msg, | |
msg = sock.recv(4096) | |
sock.close() | |
except socket.error: | |
pass | |
def main(): | |
filename = sys.argv[1] | |
socket_path = sys.argv[2] | |
if not os.path.exists(filename): | |
print "unknown file {}".format(filename) | |
sys.exit(1) | |
if not os.path.exists(socket_path): | |
print "unknown path {}".format(socket_path) | |
sys.exit(1) | |
for line in follow(filename): | |
print datetime.datetime.now() | |
print line | |
print_tbs(socket_path) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment