How to monitor JVM with JRE only - java

I have a Centos7 server and I want to monitor the JVM in order to identify performance issue but I have only JRE installed on the prod environment as follows:
Based on the research I saw there were some tool available such as Java Mission Control but it is only available with JDK but I have JRE installed. Any idea what open source tool I can use to monitor the jvm on centos with only JRE installed?

jattach gives you access to a few powerful tools, namely jcmd which you can then use to run various diagnostics commands against the java app.
Works with plain JRE - check https://github.com/apangin/jattach
See also https://docs.oracle.com/en/java/javase/17/docs/specs/man/jcmd.html

Related

What causes VisualVM to report "CPU usage: unknown"?

I am running a Java application on Java 17.0.0 from Azul - Zulu17.28+13-CA, with bundled JavaFX. Everything is working fine, except that the CPU usage simply says "unknown". I've seen messages before about "unavailable with this JVM" or something similar to that, when I ran VisualVM on older JDKs, but this is different.
VisualVM itself is running on JDK 19.0.1.
About box reports: Azul 19.0.1; OpenJDK 64-Bit Server VM (19.0.1+10, mixed mode, sharing)
The same version of VisualVM running on JDK 19.0.1 on a different system is able to get CPU usage for an application running on Oracle JDK 8u60 (ancient, I know).
Does the Azul JVM that I am trying to monitor not support something to do with CPU monitoring that Oracle Java does?
As it turns out, the JRE that the application was running on was an image made with jlink that lacked the jdk.management module. When that module was added to the JRE, the CPU usage was reported properly.
More details at GH-479.

pyCharm debugging: JRE without jstack?

I need to debug pyCharm community version on Windows 7 and try to follow what their manual says:
JStack
This command line utility is provided with the JDK installation and
can be found in JAVA_HOME\bin directory. Make sure to use the same or
close JDK version to the one the IDE runs under (see Help | About). It
will not work if IDE runs under 32-bit JDK and you run jstack from the
64-bit JDK distribution and vice versa.
To use jstack you need the IDE process identifier (PID). PID can be
obtained using jps utility that is located in the same directory as
jstack.
jps -mv
My pyCharm: help/about reads: JRE 1.7.0_40 b43 x86
How ever, in C:\Program Files (x86)\Java\jre7\bin there is no jps and no jstack. I'm not used to the command line in Windows - perhaps I'm doing something wrong here? Am I supposed to look in a different directory? I could not find any system wide environmental variable JAVA_HOME what could give any clues here.
Well, you need a Java Development Kit (JDK) instead of a Java Runtime Environment (JRE).
It is a bit larger but has many other dev tools (like jstack, jps, jvisualvm, etc., even the source code of Java). Download and install one to see the differences.

Can VisualVM monitoring apps running on JRE

as the headline mentioned: is it possible to connect VisualVM to an remote application running on JRE instead of JDK ?
And yes, the VisualVM itself runs on JDK !
Kind regards
Dominik
VisualVM connects to a running Java Virtual Machine (JVM).
And this JVM is contained both in the JDK and the JRE.
In fact, the JDK is a JRE with additional tools and items to allow creating Java programs. If you only want to run them, you only need a JDK.
So yes, you can connect to a JRE-only install.

Install JRE if not installed

I've been looking, on the web and this forum, for the correct way to include the Java Runtime Environment with my Java application.
I know that the JRE is machine-dependant and thus, the JRE to provide with my application will change if I want to deploy for MAC or Linux for example.
What I really want to know (assuming what I said before is correct), is :
"Is there a way to check whether a JRE is installed on the client machine, and if not install it before trying to run my application ?"
Because I do not think it is possible :
Do you think I should deploy my application with the JRE folder adapted to the client system, and launch my application with a script using the java.exe contained in the JRE folder ?
This avoids installing any Java stuff, but it doesn't look like a good practice to me...
If your application is client-side, I would offer both options: installation with and w/o JRE. Many java applications offers both installations. For example, SmartGit application allows you to download installation with bundled JRE or one that uses existing JRE (where its users responsibility to have the compatible version of java). Many application servers comes with their own JDK already included with the installation.
So, bundling deployment with your JRE is fine if you don't want any trouble with your customers; however, I would allow non-JRE installation as well (to satisfy picky ones :).
If your application is server-side, usually it doesn't come with JRE, but again, this is not a rule.
Moreover, your running/installation script may check if correct JRE or JDK is installed (by checking if the JAVA_HOME is set etc) and then exit if JRE is missing. Even more, the script can even download java and install it locally - although it would be more practical to just use bundled JRE that you have prepared with the application. Or, if JRE is detected, you may ask user if they want to use existing java or bundled.
Bundling JRE is not a big deal. Even I sometimes install java application with bundled JRE, because I switched on my system to e.g. new version or 64-bit version of java that is not supported by application and so on...
Hope this helps ;)
java -version command on CMD of windows tells JVM version; so you can decide if you need to install or not based on the output of this command.
C:\Users\501200I958>java -version
java version "1.7.0_17"
Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

Java server jvm installation on windows 32 bit systems

I am trying to bundle java as a part of a java product that should be installed silently with a single click and are having some issues:
My installation has the following requirements:
Has no be silent and require no user input or action excpect a doubleclick on the installation file (no configuration and post install steps)
Has to setup java so that JAVA_HOME points to a Java SE installation with a server jvm
Is this at all possible to do this on a win32 system with sun java installers? I know that by default the jre does not contian a server jvm. But even when installing the jdk the public jre which is installed (and mapped to JAVA_HOME) does not contain a server jvm. In sun own README file (Sun README) they suggest copying the files:
jre\bin\server\
On Microsoft Windows platforms, the JDK includes both
the Java HotSpot(TM) Server VM and Java HotSpot Client VM.
However, the Java SE Runtime Environment for Microsoft Windows
platforms includes only the Java HotSpot Client VM. Those wishing
to use the Java HotSpot Server VM with the Java SE Runtime
Environment may copy the JDK's jre\bin\server folder to a
bin\server directory in the Java SE Runtime Environment.
But this solution is difficult to automate gracefully in a silent install. There has to be a better way to do this without repackaging the entire java distrubution. Has anyone encountered the same problem and come up with a more elegant solution?
For the past years, I manage Java like this: I download the installer, install it somewhere, package all files into a ZIP and then use that ZIP file to deploy Java anywhere. The installer will leave a lot of stuff in the registry and %WinDir%, etc. which you don't really need. This also allows me to move some files around (like the bin\server\jvm.dll or security related settings).
That way, I can even embed Java inside the application directory, independent of any already installed version of Java.
Just set JAVA_HOME in a small batch script before starting your application and you're good. You can use %~dp0 to make it completely position independent (%~dp0 expands to the path leading to the batch file).
Make your own installer.
I use inno setup compiler, works well for my purpose.
If you need the registry entries, you can export them, include them in the installer, include the files, and a little change here and there and you're done. Silent installer that configures things to the exact specifications you need.
It comes with an easy to use script wizard.
I mention a specific one because it's free. Ultimately, making your own installer is the solutions.

Categories