patric-r/jvmtop

Additional command line switches to support scripting

mskadu opened this issue · 6 comments

I am using your excellent script to do some diagnostics on a java-based legacy system. It would be dead useful to be able to provide additional switches that can provide the ability to

a) write/ append output from every cycle to file (--write ??)
b) Produce only specific output
c) Hide the first two line (--hide-header ??)

This will make the tool scripting-friendly. Thanks!

a) jvmtop follows the common unix tradition to only write to stdout/stderr.
If you need its output in a file, you're a free to redirect it.
In order to output only once and exit which you most probably need for scripting,
use the --once switch, e.g. ./jvmtop.sh --once > myfile

b) Can you clarify what kind of specific output you need by showing an example?

c) I'll think about it. Maybe a parser-friendly output like CSV (different mode) would help you even more?

Hello there.

Thanks for taking the time to respond. Writing to a file is exactly that I am doing at the moment. However, the technique I am forced to use is akin to screen scraping and has a few challenges.

For instance --once > myfile produces only the header and not the top 10 list. When I manually run the command it takes a few seconds for the top 10 to show up (RHEL 6.x/ Sun JDK 1.6.x). I am in the process of figuring out how to deal with this.

As an afterthought, how about a flag switch to convert the output in machine readable format (--machine-readable or better) so that the output can be parsed with CLI tools like awk, grep or similar.

Using the typical output of ./jvmtop.sh 24227 as reference

  1. JvmTop 0.8.0 alpha - 13:20:26, amd64, 4 cpus, Linux 2.6.32-57, load avg 0.00
  2. http://code.google.com/p/jvmtop
  3. PID 24227: org.apache.catalina.startup.Bootstrap
  4. ARGS: start
  5. VMARGS: -Dcatalina.base=/usr/share/tomcat -Dcatalina.home=/usr/share/tomc[...]
  6. VM: Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 1.8.0_60
  7. UP: 3:36m #THR: 17 #THRPEAK: 21 #THRCREATED: 48 USER: tomcat
  8. GC-Time: 0: 0m #GC-Runs: 45 #TotalLoadedClasses: 2466
  9. CPU: 0.48% GC: 0.00% HEAP: 8m / 418m NONHEAP: 22m / n/a
  10. TID NAME STATE CPU TOTALCPU BLOCKEDBY
  11.  54 RMI TCP Connection(26)-127.0.0       RUNNABLE  1.64%     0.19%
    
  12.  55 JMX server connection timeout        RUNNABLE  0.12%     0.06%
    
  13.  17 ajp-bio-8009-AsyncTimeout       TIMED_WAITING  0.02%     3.55%
    
  14.  15 http-bio-8080-AsyncTimeout      TIMED_WAITING  0.01%     4.20%
    
  15.  53 JMX server connection timeout   TIMED_WAITING  0.00%     0.04%
    
  16.  52 JMX server connection timeout   TIMED_WAITING  0.00%     0.01%
    
  17.  22 RMI Scheduler(0)                TIMED_WAITING  0.00%     0.08%
    
  18.  20 RMI TCP Accept-0                     RUNNABLE  0.00%     0.01%
    
  19.  19 Attach Listener                      RUNNABLE  0.00%     0.09%
    
  20.  16 ajp-bio-8009-Acceptor-0              RUNNABLE  0.00%     0.00%
    
  21. Note: Only top 10 threads (according cpu load) are shown!

Possible "hide info" switches

  • --hide-info could hide lines 01-3 and 23
  • --hide-vminfo could hide lines 04-07
  • --hide-stats could hide lines 08-10
  • --hide-topthreads could hide lines 12-22

That way, someone looking to use command line on jvmtop could pick and chose what info gets generated and how. And then easily use awk/grep/ etc to parse the output.

Just some thoughts. I am improving as I have more chance to think them through a bit better. Please do ask more questions :)

Hi,
the absence of the top 10 threads information when using --once is a known limitation which will be addressed in a future release. Please use issue #58 for tracking that one.

Your suggestion for a machine readable format corresponds somehow to the "c)" section in my previous comment. I am asking myself which format (CSV?) should be used for such a mode - what do you think?

I'll think about the additional --hide-xyz switches - thanks for clarifying this.
This should be quite easy to implement.

BTW, just to gain some insights into the real-life usage scenarios of jvmtop ;)
How do you actually use jvmtop's output after you parsed its output? Do you use any further tool chains like nagios?

Re. which format - I would go with CSV for now. It's the simplest and can easily be converted to others downstream by command line utilities. Vagrant also appears to be doing a wait-and-watch, until which they've gone with CSV (see: https://docs.vagrantup.com/v2/cli/machine-readable.html)

Re. --hide-xyz - thanks, that would be very handy.

Re. usage scenario - in my case I am using jmvtop as a light-weight profiler of heap/non-heap and some CPU stats of processes within a JVM. My company has a Java based product that consumes considerable memory and CPU. I was looking for a simple profiler that does not require me to change any JAVA_OPT variables or make changes to my PROD code.

My script is basically a simple UNIX script running in cron and captures the relevant figures and writes them to a file. The data in this "capture" file can then be used for whatever purposes. This is just the first usage - the more info JVMtop can produce, the more useful my script can make of it.

On that topic, how possible is it to add memory related columns to the top-10 field list?

Hello again - any luck with this?

Closing this as I have not had a response to this in nearly a year now.