Giter VIP home page Giter VIP logo

jps_stat's Introduction

jps_stat

A bash script to moniter current_heap_memory , max_heap_till_now , current_ram , max_ram_used , current_cpu_by_jvm details of all java programs running on current linux system.

How to use

  • Clone this repo and extract and open the folder
  • Right click on jpsstat.sh file and select properties
  • Under Permissions tab, check the Allow executing file as program option.
  • Now open this folder in terminal and enter ./jpsstat.sh
  • This will list the current_heap_memory , max_heap_till_now, current_ram_use, max_ram_used and current_cpu_use of all running java processes on your linux system with live refresh.

Options

This tool expects options in ./jpsstat.sh [option] format.

  • -l : use this option to display the full package name for the application's main class or the full path name to the application's JAR file
  • -h : display the help details. You can also use -help

Example: ./jpsstat.sh -l or ./jpsstat.sh -h

How to stop

  • Press ctrl+c to stop the script and enter reset to clear your screen

Output

Script details

  • This uses jps command to get the list of all processes running java programs (jvm instances)
  • Then for each process_id obtained from jps, it runs jstat -gc <process_id>
  • It calculates Heap memory by adding following fields of jstat -gc output -
    • S0U: Survivor space 0 utilization
    • S1U: Survivor space 1 utilization
    • EU : Eden space utilization
    • OU : Old space utilization
  • It tracks cpu uses using ps -p <process_id> -o %cpu command
  • It uses the rss field of the output of /proc/<pid>/statm command to get the memory(RAM) used by the java process.
  • It uses tput cuu <# of lines> to refresh screen
  • All the decimal values in the output is truncated using %.*

Troubleshooting

  1. Getting error as ./jpsstat.sh: 38: ./jpsstat.sh: Syntax error: "(" unexpected
    • Make sure you run the script as ./jpsstat.sh and not as sh ./jpsstat.sh
    • Use bash --version to make sure your bash version is >= 4.0
  2. Getting error as bash: ./jpsstat.sh: Permission denied
    • Make sure you have given the permission to the "jpsstat.sh" file to execute as program.
    • Either use chmod 777 jpsstat.sh command or follow How to use section to give execute permission to script file.

Requirements

  • Jdk
  • Linux System (Tested on Ubuntu 16.04 LTS)
  • Bash version >= 4.0

License

MIT License

Copyright (c) 2017 Amarjeet Anand

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

jps_stat's People

Contributors

amarjeetanand avatar amarjeetanandsingh avatar cosimo avatar rsvoboda avatar vincentmli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

jps_stat's Issues

Docker sh support

../../jpsstat.sh: line 98: jps: command not found

Running inside a docker container.
Current working directory is jdk/bin, and jps is present.

sh-4.4# ls | grep jps
jps

Syntax error

Hi! First of all, thanks for this tool, it's really helpful!
This issue happens all the time, after running it for a while:

cut: /proc/36627/statm: No such file or directory
./jpsstat.sh: line 93: / 1024 : syntax error: operand expected (error token is "/ 1024 ")

Redhat RHEL 7.

Heap Memory and RAM

I see the RAM memory is lesser than Heap Memory when ran the script in a docker container. Is RAM memory is calculated by excluding heap? .Because heap memory should be a part of RAM right ?

printf error

Hi,
great script. But if I execute the script I get this error:
./jpsstat.sh: line 89: printf: 234.637: invalid number ./jpsstat.sh: line 89: printf: 234.637: invalid number ./jpsstat.sh: line 89: printf: 1.1: invalid number
I found the issue in the printf command where %f has issues to work with decimal numbers. Therefore I modified a few lines:

   MEMORY_T=$(jstat -gc $pid | tail -n 1 | awk '{split($0,a," "); sum=a[3]+a[4]+a[6]+a[8]; mb=sum/1024; print mb}')
        MEMORY=${MEMORY_T%.*}

and
printf "%-6s %-44s %8.2f %8.2f %5.1s\n" $pid ${curr_pid_name["$pid"]} $MEMORY ${curr_pid_max["$pid"]} $cpuuse | sort

It's just a workaround. Hope that helps.

Regards
Marcho

jps log output

hello, when I log into a log file I have a problem with special char at the begining.

How to remove them ?

===== ============================== ======= ======= ====== ====== =====
PID Name CurHeap MaxHeap CurRAM MaxRAM %_CPU
===== ============================== ======= ======= ====== ====== =====
10724 org.eclipse.osgi_3.9.1.v201401 36 36 60 60 0
^[[1A10724 org.eclipse.osgi_3.9.1.v201401 36 36 60 60 0
^[[1A10724 org.eclipse.osgi_3.9.1.v201401 36 36 60 60 0
^[[1A10724 org.eclipse.osgi_3.9.1.v201401 36 36 60 60 0
^[[1A10724 org.eclipse.osgi_3.9.1.v201401 36 36 60 60 0
^[[1A10724 org.eclipse.osgi_3.9.1.v201401 36 36 60 60 0

best
bruno

document options in README.md

We need to document all the supported options in README.md

The readme doc is outdated. In recent development, we have got few more options. All the available options can be seen by running ./jpsstat.sh -h.

New available options are -1 | --once and -H | --no-headers and -l

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.