Last active
September 14, 2017 08:35
-
-
Save dovy/22951154c1021abb9bff7110a616dac5 to your computer and use it in GitHub Desktop.
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/python | |
import logging | |
logging.basicConfig(level=logging.INFO) | |
logger = logging.get_logger(__name__) | |
import time | |
from subprocess import Popen, PIPE, STDOUT | |
import xmlrpclib | |
import sys | |
class Supervisor_Health: | |
def __init__(self): | |
self.server = xmlrpclib.Server('http://USER:[email protected]:1337/RPC2') | |
def check(self, process): | |
logger.info('--> Checking %s [%d]' % (process['name'], process['pid'])) | |
cmd = "strace -s 99 -ffp %d" % process['pid'] | |
FNULL = open(os.devnull, 'w') | |
p = Popen(cmd, stdin=PIPE, stdout=FNULL, stderr=STDOUT, shell=True) | |
time.sleep(1) | |
p.kill() | |
def launch(self): | |
logger.info('\n\nChecking Supervisor Health %d' % time.time()) | |
processes = self.server.supervisor.getAllProcessInfo() | |
count = 0 | |
for p in processes: | |
if p['statename'] == "RUNNING": | |
self.check(p) | |
count += 1 | |
logger.info('\nChecked health for %d running processes. Sleeping for 10 mins.' % count) | |
time.sleep(600) | |
self.launch() | |
def main(): | |
client = Supervisor_Health() | |
logger.info('~~ Supervisor_Health') | |
client.launch() | |
if __name__ == "__main__": | |
try: | |
main() | |
except Exception, e: | |
logs.traceback(exception=e, system=sys) | |
exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment