Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jstack command #391

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 59 additions & 2 deletions src/omero/plugins/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,24 @@ def __init__(this, name, help, wait=False):
action="append",
exclusive=False)

jstack = Action(
"jstack",
"""Print active threads from the OMERO backend.

If installed, the `jstack` tool will be invoked on
the OMERO Java processes.

Examples:

# By default, print the threads from the main Java process (Blitz-0)
omero admin jstack

""").parser
jstack.add_argument(
"--service",
default="Blitz-0",
help="Service name. '*' designates all services)")

Action(
"rewrite",
"""Regenerate the IceGrid configuration files
Expand Down Expand Up @@ -1663,6 +1681,38 @@ def email(self, args):
finally:
cb.close(True)


@with_config
def jstack(self, args, config):
"""
"""
if args.service == "*":
# TODO: get a list of services
services = ("Blitz-0", "Indexer-0", "PixelData-0")
else:
services = (args.service,)

unknown_services = 0
for service in services:
pid = self.check_service(service, return_pid=True)
if pid is None:
unknown_services += 1
self.ctx.err(f"service not running: {service}")
else:
self.ctx.err(f"Loading jstack for {service} ({pid})")
popen = self.ctx.popen(["jstack", str(pid)])
popen.wait()
jstack = popen.communicate()
jstack = [x.decode("utf-8") for x in jstack]
# TODO: offer to write to file
self.ctx.out("stdout:")
self.ctx.out(jstack[0])
self.ctx.err("stderr:")
self.ctx.err(jstack[1])

if unknown_services:
self.ctx.die(14, f"{unknown_services} unknown service(s)")

def getdirsize(self, directory, strict=True):
"""
Uses os.walk to calculate the deep size of the given
Expand Down Expand Up @@ -2009,12 +2059,19 @@ def sessionlist(self, args):
self.ctx.controls["hql"].display(
mapped, ("node", "session", "started", "owner", "agent", "notes"))

def check_service(self, name):
def check_service(self, name, return_pid=False):
command = self._cmd()
command.extend(["-e", "server pid %s" % name])
p = self.ctx.popen(command) # popen
rc = p.wait()
return rc == 0
rv = rc == 0
if return_pid:
if rv:
return p.communicate()[0].decode("utf-8").strip()
else:
return None
else:
return rv

def start_service(self, name):
command = self._cmd()
Expand Down
Loading