Last active
August 29, 2015 14:17
-
-
Save steinnes/ead90afa9882e89b995f to your computer and use it in GitHub Desktop.
redis workload recorder
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 time | |
import signal | |
import sys | |
import redis | |
import socket | |
def stop(sig, frame): | |
sys.stdout.flush() # flush whatever is there! | |
sys.stderr.write("Stopping due to {}\n".format(sig)) | |
sys.exit(1) | |
def monitor(host, port): | |
sock = socket.create_connection((host, port)) | |
sock.send('monitor\r\n') | |
while True: | |
sys.stdout.write(sock.recv(256)) | |
def start(seconds, host, port=6379): | |
signal.signal(signal.SIGALRM, stop) | |
signal.alarm(seconds) | |
monitor(host, port) | |
def main(): | |
if len(sys.argv) < 3: | |
print "Usage: {} <seconds> <host> [<port>]".format(sys.argv[0]) | |
sys.exit(1) | |
seconds = int(sys.argv[1]) | |
host = str(sys.argv[2]) | |
kwargs = {} | |
try: | |
kwargs['port'] = int(sys.argv[3]) | |
except ValueError: | |
print "Invalid port!" | |
sys.exit(1) | |
except IndexError: | |
pass | |
start(seconds, host, **kwargs) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: