I know we can use tools like JProfiler etc.
Is there any tutorial on how to configure it to display the memory usage just by remote monitoring?
Any idea?
you have VisualGC, it's not very advanced but you can see the memory usage of your application (garbage,old, perm etc...)
http://java.sun.com/performance/jvmstat/visualgc.html
to resume :
you launch a daemon monitoring on the remote machine (http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jstatd.html, see the security parapraph)
JAVA_HOME/bin/jstatd -J-Djava.security.policy=jstatd.all.policy
with a file here called jstatd.all.policy containing :
grant codebase "file:${java.home}/../lib/tools.jar" {
permission java.security.AllPermission;
};
on the remote machine you got the pid of your application to debug with the jps tool :
http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/jps.html#jps
finally on your local machine you launch the visualgc :
visualgc the_pid#remote_machine_address
I usually use YourKit which is an excellent application (license needed).
In your webservers startup/shutdown script (catalina.sh for tomcat) put in:
JAVA_OPTS="-Djava.awt.headless=true -agentlib:yjpagent -Xrunyjpagent:sessionname=Tomcat"
You'll need YourKit already downloaded and added to your library path (I do this in catalina.sh as well):
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/yourkit/yjp-6.0.16/bin/linux-x86-32
You can then launch the YourKit client on your local desktop and remotely connect.
You can change to VM params of your Java application to allow remote profiling
something like -agentlib:jprofilerti=port=25000
General explanation of JProfiler.
Examples:
NetBeans
Intellij
Profile your application using Jprofiler. Below are the steps to configure your Tomcat with Jprofiler.
In Linux machine open .bash_profile file from /root directory.
Enter jprofiller location (using below command export) in
.bash_profile file
export LD_LIBRARY_PATH=/dsvol/jprofiler6/bin/linux-x86
Go Tomcat installation directory. Open catalena.sh file from bin folder.
Enter the below details in catelana.sh file (only red color information and black color you can find by default in catalena.sh file).
export JPROFILER_HOME
JAVA_OPTS="-Xms768m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=256m -Dfile.encoding=UTF8 -agentpath:/opt/Performance/jprofiler7/bin/linux-x86/libjprofilerti.so=port=8849 $CATALINA_OPTS"
Start the server from bin folder by executing the starup.sh command
I've heard good things of VisualVM and here is an article on how to it up remotely:
Java VisualVM to profile a remote server
EDIT:
I wrote a blog post on how to setup remote profiling through an SSH tunnel here:
http://kamilmroczek.com/2012/11/16/168787859/
Related
I have a custom instance running on Windows Server 2016 where I need to monitor my Java processes.
I setup Stackdriver, installed the monitoring agent and followed this guide for JVM monitoring https://cloud.google.com/monitoring/agent/plugins/jvm
However no matter what I do I can not see any of my processes when setting up an Alerting policy within Stackdriver's console.
There are 2 steps in the guide I am unsure how to follow:
On your VM instance, download jvm-sun-hotspot.conf from the GitHub configuration repository and place it in the directory
/opt/stackdriver/collectd/etc/collectd.d/
Where exactly do I place the .conf file?
Edit the downloaded configuration file and replace JMX_PORT by the port on which your JVM is configured to allow JMX connections.
How do I get the port?
Sorry if this seems obvious but I'm pretty new to this.
Thanks in advance for your help.
All the steps and instructions on the JVM plugin page have instructions relevant for linux, and windows is not even mentioned there. So it could be quite possible that the JVM plugin is supported only on linux.
Since your code is already running on a JVM, you might want to consider if it is possible to move your application from a Windows VM to a linux VM.
Enabling the JVM monitoring plugin
Java Virtual Machines are monitored via JMX.
On your VM instance, download jvm-sun-hotspot.conf from the GitHub
configuration repository and place it in the directory
/opt/stackdriver/collectd/etc/collectd.d/:
(cd /opt/stackdriver/collectd/etc/collectd.d/ && curl -O https://raw.githubusercontent.com/Stackdriver/stackdriver-agent-service-configs/master/etc/collectd.d/jvm-sun-hotspot.conf)
Edit the downloaded configuration file and replace JMX_PORT by the
port on which your JVM is configured to allow JMX connections.
After adding the configuration file, restart the monitoring agent by
running the following command:
sudo service stackdriver-agent restart
Information on other plugin configuration options can be found at
collectd.org.
I have an Azure App Service running Tomcat 8.5 and can't seem to figure out how to do a thread dump. jstack is not recognized in the Console nor the DebugConsole.
On Azure App Service, all popular versions of Java had been installed at the path D:\Program Files (x86)\Java. Take version 1.8.0u73 as example, please see the figure below.
You can command set PATH=D:\Program Files (x86)\Java\jdk1.8.0_73\bin;%PATH% to add Java tools to the environment temporarily via the Kudu console tool. Then, the jstack tool is available in the current Kudu session.
Inspired by the previous answer, I created the following bat script (could be powershell, I suppose) that does the job:
powershell -Command "get-process java |select -expand id" > pid.txt
set /p id= < pid.txt
"%JAVA_HOME%\bin\jstack" -F %id% > out.txt
It uses the java version that you're using in your app (JAVA_HOME) and doesn't require any input from you. It's simple and does the trick. Just create a bat file in your wwwroot, for example, and run it whenever you want.
I know this is an old question but for Windows Apps on Azure App Service, this can be easily done by going to Azure Portal -> Diagnose and Solve problems blade -> Diagnostic Tools and then choosing Collect Java Thread dump from the left menu or the middle pane.
Get the PID of java process from Process Explorer of Kudu (Advanced Tools)
Use this command to collect thread dump:
jcmd Thread.print > D:\home\threaddump.txt
I want to connect to JVM running on remote CentOS 6 server using VisualVM installed on server. I connect to server using ssh with X forwarding:
ssh -X <user#ip>
My ~/.bashrc exports these variables to run VisualVM:
export JAVA_HOME=/usr/local/jdk1.8.0_102/
export PATH="$JAVA_HOME/bin:$PATH"
Then I run VisualVM locating on remote server:
/usr/local/visualvm_138/bin/visualvm
It invokes without errors, but there is no application view appeared (which should appear at application start). Also, there is no Applications sub-item inside Window menu item. I already ran VisualVM successfully using this way about month ago. How to make this window appeared?
Try to delete VisualVM userdir and cache and than restart VisualVM. Userdir is at ~/.visualvm/1.3.8 and cache is at ~/.cache/visualvm/1.3.8
All,
I have a remote server that I recently enabled VNC for using vnc4server and Chicken for mac as the client.
The purpose for doing so was to enable running Java's Jconsole to monitor an executable jar file that is running my server logic.
However, after logging into my server using VNC, I keep getting an error when I try to use Jconsole on vnc.
It states connection failed do you want to try again. Now I am logged in as the same user that started the process.
Is there something I am missing when using jconsole in VNC? Also can I monitor my executable jar file remotely using Jconsole on my local machine?
These are the options I am including to run the jar file: java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9005 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.remote.ssl=false -Djava.rmi.server.hostname=ipaddress -jar path
Thanks
These JVM options fixed things. Fix found here: You need to pass to the VM: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false
https://forums.oracle.com/thread/1177644
This does not seem like an VNC issue- either the ports are not open, they are being blocked b a firewall, or there is some kind of permission/authentication issue with the app itself related to monitoring it.
In order to eliminate VNC as the cause (and use localhost in a local connection on jconsole), do "ssh -X REMOTHOST -n jconsole" and see. This will also eliminate the overhead of running the full X server and VNC.
Also on linux you can find out what process holds a port open by doing:
netstat -ap | grep PORT_NUMBER on the remote host you want to run on.
Colin
I am trying to profile CPU usage using TPTP.
Application to profile run on Linux RH AS5. I installed and configured Agent Controller like described here
I ran the java application using the command
java '-agentlib:JPIBootLoader=JPIAgent:server=standalone,file=log.trcxml;CGProf' MyApp
The monitoring station is All-In-one TPTP version 4.6.2. I followed the stepes described here
on Eclipse - on the "Profile Configuration" I choose a new configuration for "Attach to Agent", set the host to my remote linux machine where MyApp is running, test connection succeed and when I get to the "Agents" tab, I see "Pending...", a background process "Feching children for host" is running and can't find anything which makes it impossible to profile.
Any idea?
You have to run the Agent Controller on the java application in server mode. Currently your command runs it 'headless' and writes it to a log file. The website you linked has a list of the various options for the server parameter.
java '-agentlib:JPIBootLoader=JPIAgent:server=enabled;CGProf' MyApp