sensu-plugins / sensu-plugins-java

Sensu Java Plugins
http://sensu-plugins.io
MIT License
5 stars 25 forks source link

Multiple JPS processes causes command to hang #12

Closed rahulsh1 closed 7 years ago

rahulsh1 commented 7 years ago

If multiple processes have the same "jps" name, this causes command (jstat) to hang. $ check-java-heap-pcnt.rb -n jar -w 60 -c 80 <-- does not return

I have multiple java processes which runs using a jar name. jps shows both as jar.

$ jps
29475 jar
2519 Jps
18875 jar

$ PID=$(sudo jps | grep $NAME | awk '{ print $1}')
# echo $PID
29475 18875

$ sudo jstat -gccapacity $PID  | tail -n 1 | awk '{ print ($4 + $5 + $6 + $10) / 1024 }'  <-- Does not return

However with the full package name listing, this can be easily fixed

$ jps -l
29475 myapp-1.0-SNAPSHOT.jar
2777 sun.tools.jps.Jps
18875 slave.jar

Adding -l to PID=$(sudo jps -l | grep $NAME | awk '{ print $1}') fixes this issue. I can then run

$ check-java-heap-pcnt.rb -n myapp
MEM OK - jvm heap usage: 6% | 73.1454 MB out of 1159 MB
majormoses commented 7 years ago

closed per: https://github.com/sensu-plugins/sensu-plugins-java/issues/17