This question already has answers here:
Can jconsole data be retrieved from the command line?
(9 answers)
Closed 7 years ago.
I want to write a JUnit testcase that will also be able to monitor and collect the parameters of a JVM, like the memory usage, heap size and other custom JMX managed beans etc. I will be having the JMX address of the JVM. More clearly, I would like to know if I could gather the information that jconsole provides but programatically without a UI. And then I would want to check if the JVM performance has degraded or not by integrating it with Jenkins. Are there any already available tools that do this?
You might consider using Virtual Machine Agent, here is a good educational article
Also you can use Profiler tools in eclipse to monitor your program performance
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am currently working on an event driven System with multiple components running. Recently , I have received an urgent requirement to identify the memory consumption of java components running , so that we can give a brief idea of memory requirements before it is getting deployed on UAT/customer production environments.
Do we have any API using which Deep retained size can be calculated or a formula can be provided using which memory requirements can be computed.
Any ideas on this will surely help.
I have seen some API's ( java instrumentation Api) using which Shallow size can be calculated , but this will not suffice my need.
I also found java Assist using which java byte code can be modified at runtime.
To identify the memory consumption of a java aplication, you can use a profiler.
In jdk 6 or greater you can find jvisualvm (https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jvisualvm.html).
With jvisualvm, you can attach to a java process and, in sampler tab, you can see the memory consumed grouped by class type.
There are even other powerful profilers (JProfiler is one of them)
Enable garbage collection logging and analyze the log. As a bonus you will also be able to identify (and fix) aberrant behaviour.
To turn on gc logging, use the following flags:
-verbose:gc
-XX:+PrintGCDetails
-XX:+PrintGCDateStamps
-XX:+PrintTenuringDistribution
-XX:+PrintGCCause
-Xloggc:/gc-%t.log
This log file can then be handled in a number of tools like Censum from JClarity or uploaded to https://gceasy.io/ for easy analysis. Note that you will see the memory consumption as a whole for the app, not a breakdown. For that you will have to use something like VisualVM mentioned above.
This question already has answers here:
Global keylogger in Java
(3 answers)
Closed 6 years ago.
I have been searching for a while now for a library that allows me to know which Key-Event was pressed. But not in a focused program/text-field or anything else but as a process that runs in the background.
I'm not trying to write a keylogger but I want to create a program that lets me create shortcuts for key-combinations.
I don't think Java has native support for something like this. Java is really a language of abstraction, it gets you further away from the OS to make developing easier - but also for security purposes.
Key events are core to the OS so you will (likely) need a language or a library has that capability. Check out JNativeHook.
You can achieve this using JNI and Global System hook. Global System hook applies a Key Logger to the whole computer and not the JVM therefore allowing you to capture key presses outside of the JVM.
An example implementation of it can be seen here
This question already has answers here:
How to find how much disk space is left using Java?
(4 answers)
Closed 8 years ago.
I am looking for simple solution for finding total disk space and available space of a remove machine using java program.
Please help
Update
There are questions already similar to this with primarily focus on local machine. I was looking solution for remote machine.
The easiest way to get the remote machine information and also safe way to do
is to SSH to the server from Java and get the necessary information from.
use JSch Library for SSH connection to server.
for an example look here
This question already has answers here:
How Do I Eject a Volume in Java?
(2 answers)
Closed 3 years ago.
I know that questions like this have been asked before, but I couldn't find any more recent ones and I have a twist to my question.
I've developed an application in Java that is designed to run on removable media, and work on both Windows and Mac. I would like to add a button to safely remove/eject the device, if it is supported (i.e a USB drive). Is there a command line for each operating system that would allow me to do this?
I know that it can be done by an application running on the device to be ejected, because I've seen one that does it, but obviously I understand there are certain limitations to Java.
Thanks in advance
This is something that you will have to do by invoking an auxiliary application. These applications are not platform independent as you wish. So, to do that, find out which OS you are on by using System.getProperty("os.name") and invoke the appropriate command for the detected OS. Invoking applications is done with Runtime.getRuntime().exec(). Search for the commands you need for each OS.
This question already has answers here:
How do I monitor the computer's CPU, memory, and disk usage in Java?
(12 answers)
Closed 9 years ago.
I have searched all over the internet for about two days now. I have found a lot about how to find the CPU usage using VB and anything in the .NET framework. I am not using the .NET framework so these are irrelevant, I feel.
What I really need is results similar to the ones shown in the "CPU Usage" section in a Windows Task Manager under the "Performance" tab. If I could find a way to mimic that calculation, then that is exactly what I am looking for. I need the percentage of CPU Usage.
Obviously, Java is not the ideal language for finding the CPU usage of a computer, but that is the language I am using and I have been able to get everything else I need about the computer except this.
I am using Windows 7 with Java version 7 update 21. Eclipse is my IDE.
This is my first time posting a question on here, so if I have left anything out or something is not clear, please ask and I will do my best to explain more of what I mean.
There are a couple of ways to do this; one is to run a command-line tool and parse the output. On Windows 7, you can run
c:\Windows\system32\typeperf "\processor(_total)\% processor time"
Try it -- it prints a few lines of sampled CPU load data.
Another way is to use OperatingSystemMXBean .