wlanboy

tutorials and ruby scripts

Read my tutorials

Read my gists

Gist

Gist: java-info-for-processes

#pid list of java microservices
ps ax | grep java | grep jar | awk '{print $1}'

#Heap space util
jstat -gc 5118 | tail -n 1 | awk '{split($0,a," "); sum=a[3]+a[4]+a[6]+a[8]; print sum}'

#put it together
ps ax | grep java | grep jar | awk '{print $1}' | while read -r line; do jstat -gc "$line" | tail -n 1 | awk '{split($0,a," "); sum=a[3]+a[4]+a[6]+a[8]; print sum}'; done  

#get result list
ps ax | grep java | grep jar | awk '{print $7}' && ps ax | grep java | grep jar | awk '{print $1}' | while read -r line; do jstat -gc "$line" | tail -n 1 | awk '{split($0,a," "); sum=a[3]+a[4]+a[6]+a[8]; print sum " KB"}'; done