Created
February 14, 2012 01:23
-
-
Save torao/1822303 to your computer and use it in GitHub Desktop.
Script to dump Java VM stacktrace on all cluster.
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 | |
# -*- encoding: UTF-8 -*- | |
# Script to dump Java VM stacktrace on all cluster. | |
# Please configure your unix account to sudo to each user of jvm processes without | |
# password on each server. | |
import commands | |
import re | |
import time | |
cluster = [ | |
"server1", | |
"server2", | |
# ... | |
] | |
filename = time.strftime("jvmdump_%Y-%m-%d.%H:%M:%S.log") | |
file = open(filename, "w") | |
for server in cluster: | |
file.write("==================== %s ====================\n" % server) | |
upids = commands.getoutput("ssh %s ps -ef | grep java | awk '{print $1, $2}'" % server) | |
for upid in re.split("\n+", upids): | |
file.write("---------- %s ----------\n" % upid) | |
up = re.split(" +", upid) | |
if len(up) == 2: | |
file.write(commands.getoutput("ssh -t -t %s sudo -u %s /usr/java/default/bin/jstack %s" % (server, up[0], up[1]))) | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment