Created
October 18, 2018 01:44
-
-
Save openfly/aaf211d0c23777424921bc438c0abaaf to your computer and use it in GitHub Desktop.
coring stuff module
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
import socket | |
import subprocess | |
class Coring(object): | |
def __init__(self, *args, **kwargs): | |
super(Coring, self).__init__(*args, **kwargs) | |
def gcore(self, pid): | |
''' grab core dump of process by pid ''' | |
core_path = '/data/tomcat/temp/tomcat.core' | |
try: | |
cmd = 'gcore -o \'%s\' %d' % (core_path, pid) | |
self.runc(cmd) | |
return core_path + '.' + str(pid) | |
except subprocess.CalledProcessError as grepexc: | |
print grepexc | |
return None | |
def get_threaddump(self, core_path, issue): | |
''' take threaddump from core file and toss it ''' | |
hostname = socket.gethostname() | |
jstackbin = '/usr/java/latest/bin/jstack' | |
javabin = '/usr/java/latest/bin/java' | |
try: | |
cmd = '%s -J-d64 %s %s > /data/tomcat/temp/%s-%s-threaddump.txt' % (jstackbin, javabin, core_path, hostname, issue) | |
output = self.runc(cmd) | |
cmd = 'toss /data/tomcat/temp/%s-%s-threaddump.txt' % (hostname, issue) | |
output = self.runc(cmd) | |
return output.strip() | |
except subprocess.CalledProcessError as threadexc: | |
print threadexc | |
return None | |
def get_heapdump(self, core_path, issue): | |
''' take heapdump from core file and toss it ''' | |
hostname = socket.gethostname() | |
jmapbin = '/usr/java/latest/bin/jmap' | |
javabin = '/usr/java/latest/bin/java' | |
try: | |
cmd = '%s -dump:format=b,file=/data/tomcat/temp/%s-%s-heapdump.hprof %s %s' % (jmapbin, hostname, issue, javabin, core_path) | |
output = self.runc(cmd) | |
# print output | |
cmd = 'toss /data/tomcat/temp/%s-%s-heapdump.hprof' % (hostname, issue) | |
output = self.runc(cmd) | |
# print output | |
return output.strip() | |
except subprocess.CalledProcessError as threadexc: | |
print threadexc | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment