python telnet / monitoring redis or beanstalk

i wrote this python to monitor my redis or beanstalk process, cannot give you full of my scripts this is only basic scripts. in case me in the future forget how to write and send command to server via telnet and failed because of hung in the middle of process (got into limbo) this will get the value and send that value over to monitoring server thru REST API or CLI

Monitoring current connected client in redis

#!/usr/bin/env python
# Very simple python monitoring redis connected clients.

import sys
import telnetlib
import time

def run_telnet_session():
 #host = raw_input("Enter remote hostname e.g. localhost:")
 #port = raw_input("Enter remote hostname e.g. 6379:")
 host = "127.0.0.1"
 port = 6379
 session = telnetlib.Telnet(host,port)

 session.write("info \r\n")
 time.sleep(1)
 session.write("quit \r\n")
 data=session.read_very_eager()
 #print data
 for item in data.split("\n"):
  if "connected_clients" in item:
    print item.strip()
    print item.strip().split(':')[1]

if __name__ == '__main__':
 run_telnet_session()

Monitoring Current Job ready beanstalkd

#!/usr/bin/env python
# Very simple python monitoring redis connected clients.

import sys
import telnetlib
import time

def run_telnet_session():
 host = "127.0.0.1"
 port = 11300
 session = telnetlib.Telnet(host,port)

 session.write("stats\r\n")
 time.sleep(2)
 session.write("quit\r\n")
 data=session.read_very_eager()

 for item in data.split("\n"):
   if "current-jobs-ready" in item:
    print item.strip()
    print item.strip().split(':')[1]

if __name__ == '__main__':
 run_telnet_session()


mon_py_scripts