Skip to content

Instantly share code, notes, and snippets.

@torao
Created February 14, 2012 01:23
Show Gist options
  • Save torao/1822303 to your computer and use it in GitHub Desktop.
Save torao/1822303 to your computer and use it in GitHub Desktop.
Script to dump Java VM stacktrace on all cluster.
#!/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