Generate heap dump without JDK - SIGQUIT to application? - java

any idea how do generate a java heapdump without JDK?
I'm able to obtain the processid but I don't have access to the machine directly and there's no JDK installed.
You can alternatively use the JVM parameter -XX:+HeapDumpOnCtrlBreak
and send a SIGQUIT signal (-3 kill for Unix and Ctrl-Break for
Windows) to the running Java process – the signal will also create a
heapdump without aborting the JVM
Is there an easier way? and how can I send a SIGQUIT to the process?
Thank you for your help

If you still have access via SSH/telnet you could use:
kill -QUIT <pid>
as you described in you quotation.
Other option in to access the application via JMX, i.e. jconsole or jvisialvm
To use JMX you need enabled JMX via the command line of the application

Related

jvm monitoring - from command line

I am looking for commands to run in a Linux VM, to continuously monitoring the following metrics for my client:
jvm.cpu_load.process
jvm.thread_count
jvm.non_heap_memory
jvm.heap_memory_max
Could you help me to find the exact command to get these metrics?
You can get some this information by running jcmd repeatedly against your process. Run jcmd <pid> help to find out what your JVM supports. For example, you can get information about the process' use of memory by running jcmd <pid> GC.heap_info.
However, if you want to get this information regularly, you should look at writing a program to query either JMX (https://docs.oracle.com/en/java/javase/15/management/monitoring-and-management-using-jmx-technology.html) or by using JFR to gain this data. If you're Java 14 o above, then you can use JFR Streaming to process the data as it comes off (added in JEP 394).
JFR is an always-on profiling mechanism which periodically dumps data that you can process, but in non-streaming mode, it will dump contents after a particular amount of data is collected.
If you're looking to just monitor metrics remotely, writing a JMX tool is probably the recommended way of doing it, or using an existing tool like NewRelic's agent or Netflix's Servo library to acquire this data via JMX if you don't want to write it yourself.

How do jps, jinfo, jstat, jmap and jstack get information about local Java processes?

How does jps get information about all the local java processes?
Does it connect to some local server process to fetch the information?
How do jinfo, jstat, jmap, and jstack get information about a local java process? Do they connect to some local server process(es) to fetch the information?
Is jstatd only used for providing remote access to local java processes, but not for providing local access to local java processes?
I am running Ubuntu. My question comes from https://stackoverflow.com/a/55669949/156458.
jps finds running Java processes by scanning through /tmp/hsperfdata_<username> directory. Each HotSpot-based Java process creates a file in this directory with the name equal to the process ID.
The file /tmp/hsperfdata_<username>/<pid> contains various counters exported by the JVM. These counters can be read by an external process. This is exactly how jstat works. I described jvmstat performance counters in the JavaMagazine article.
So, jstat can always read counters of a local Java process, but in order to be able to monitor a remote machine, jstatd needs to be running.
jmap, jstack and jinfo use Dynamic Attach mechanism. These utilities connect to the target JVM via UNIX-domain socket and send the corresponding command to the JVM. The command is executed by the remote JVM itself. Find more about Dynamic Attach in this answer and in this presentation.

Install4j: Is is possible to configure an install4j launcher to respond to kill -3 and generate a thread dump?

I would like to automatically create a thread dump as part of a log collection script I have written.
I know that it is possible to generate a thread dump using jstack or kill -3 . The customer running the log collection script will only have a JRE installed so jstack is not an option.
If I use jstack and the pid of the JVM that the install4j launcher creates I get the thread dump...however invoking kill -3 with the same pid generates no output. I am currently directing both stderror and stdout to files using the install4j launcher configuration.
This is a linux launcher that is configured with the service option.
FWIW...I have tried not directing the output and also running my application as a console program instead of a service and none of these allow 'kill -3' to work.
I'm using install4j 6.0
Lastly, I do not want to use -XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:LogFile=dump.log because of the unknown overhead it might create.
Any help would be appreciated!
I would suggest to use the ThreadMXBean to get this information programmatically in the same process rather than use signal handlers from another process. The API documentation is at
http://docs.oracle.com/javase/8/docs/api/java/lang/management/ThreadMXBean.html
Here's a full example of how to use this MBean.
In that way you can write the information explicitly to wherever you want it to go.

Not enough Storage is available to process this command when running java utilities from command line

I'm on Windows Vista 64 bit, with a 64 bit jvm installed. I'm trying to use jstack and jmap -- two utilities that come with the JDK -- to peek into an application server's guts. This works fine on a windows xp machine, 32 bit.
However, when I run these commands against the processid for a ColdFusion application server on this vista64 machine, I get the error message in the title of this post.
All I'm doing is running jstack , where pid is the processid of my CF server, and I'm getting this
this machine has plenty of available memory, but I highly doubt it's a memory problem. The reason I say that is that if I start JBoss, which is taking up just as much memory as CF, I can run jstack against that process.
Thanks for advice
Figured it out. The problem was that ColdFusion was running as a windows service. By stopping the service and running from the command line (jrun start cfusion) , I was able to successfully use the JDK tools
this posting provides details on how to execute jstack when the process is running as a windows service. basically, use the psexec command.
Jstack and Not enough storage is available to process this command

JVM thread dump location

When I issue a kill -3 <pid> command to my Java program, it generates the thread dump on the console. How do I redirect this to a file?
Two options:
Run your Java application with stdout redirected
java com.example.MyApp > out.txt
Use jstack instead.
The jstack utility allows you to get a thread dump and send the output to the current console instead of the stdout of the Java application, allowing you to redirect it.
For example, if the PID of your Java application is 12345 (use the jps utility to find it quickly):
jstack 12345 > threads.txt
I usually use the NetBeans profiler, but jvisualvm is available from the command line.
If you want details of all threads and other JVM details, try jconsole.
Please append following JVM arguments to your application. Thread dump should be captured at dump.log.
-XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:LogFile=dump.log
Please note it does not redirect, but enables JVM diagnostic logging. So, there could be possible over head as well.
However, if you can have JDK in the environment, using jstack or jcmd (jcmd is preferred with JDK 1.8), you can capture thread dump and redirect to a file.
you can generate java thread dumps using 4 ways excluding the kill -QUIT way.

Categories

Resources