Code Monkey home page Code Monkey logo

sensu-plugins-java's Introduction

Sensu-Plugins-java

Build Status Gem Version Code Climate Test Coverage Dependency Status

Functionality

Files

  • bin/check-java-permgen.rb
  • bin/java-heap-pcnt.sh - deprecated, use check-java-heap-pcnt
  • bin/check-java-heap-pcnt.sh
  • bin/check-java-heap-pcnt-java8.sh - supports java 8 and multiple java processes
  • bin/check-java-heap-pcnt.rb - ruby wrapper for check-java-heap-pcnt.sh
  • bin/metrics-java-heap-graphite.sh
  • bin/metrics-java-heap-graphite-java8.sh - supports java 8 and multiple java processes
  • metrics-java-heap-graphite.rb - ruby wrapper for metrics-java-heap-graphite.sh
  • bin/metrics-jstat.py
  • bin/metrics-jstat-java8.py - supports java 8
  • bin/metrics-jstat.rb - ruby wrapper script for metrics-jstat.py

Usage

Installation

Installation and Setup

Notes

sensu-plugins-java's People

Contributors

bootswithdefer avatar dependabot-preview[bot] avatar dependabot-support avatar eheydrick avatar jspaleta avatar juan-moreno avatar kidinicol avatar majormoses avatar rooprob avatar santhosh-tekuri avatar sensu-plugin avatar sovaa avatar sstarcher avatar tas50 avatar zandabanda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sensu-plugins-java's Issues

Usage of sudo in check-java-heap-pcnt.rb

Is there any particular reason for using sudo while running the jps and jstat commands?
The "user" under which the script runs should have the correct permissions to check for status of process and calculate the heap usage.

I see this error while running the check.
output: sudo: sorry, you must have a tty to run sudo

Syntax Error in java-heap-pcnt.sh

I'm getting the following error when running java-heap-pcnt.sh:

./java-heap-pcnt.sh:23:in `load': /usr/local/share/ruby/gems/2.0/gems/sensu-plugins-java-0.0.2/bin/java-heap-pcnt.sh:15: syntax error, unexpected tCONSTANT, expecting keyword_do_cond or ';' or '\n' (SyntaxError)
while getopts "w:c:n:hp" OPT; do
                            ^
/usr/local/share/ruby/gems/2.0/gems/sensu-plugins-java-0.0.2/bin/java-heap-pcnt.sh:15: syntax error, unexpected keyword_do_cond, expecting end-of-input
    from ./java-heap-pcnt.sh:23:in `<main>'

This is running on an Amazon AMI with Ruby 2.0 and I assume there's an conflict with Ruby loading the gem that runs the Bash script.

Enabling separate metrics pull

To get separate metrics per JAVA process, following modifications have to be done:
in metrics-java-heap-graphite-java8.sh
Lines 40 & 65 instead:
PID=$(sudo jps | grep " $NAME$" | awk '{ print $1}')
&
projectName=$(sudo jps | grep $PID | awk '{ print $2}' | cut -d. -f1)

It would be nice to have:

PID=$(sudo jps -l | grep " $NAME$" | awk '{ print $1}')
&
projectName=$(sudo jps -l | grep $PID | awk '{ print $2}' | cut -d. -f1)

And

in metrics-java-heap-graphite.sh

Line 50
project=$(sudo jps | grep $PID | awk '{ print $2 }' | cut -d. -f1)
to
project=$(sudo jps -l | grep $PID | awk '{ print $2 }' | cut -d. -f1)

-l is added after jps command

Best Regards

Syntax error

Hi! I have some troubles.
Its very easy to reproduce.

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04 LTS
Release:    14.04
Codename:   trusty
bash --version
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)

ruby --version
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]

gem install sensu-plugins-java

gem list | grep java
sensu-plugins-java (0.0.3)
metrics-java-heap-graphite.sh
/usr/local/bin/metrics-java-heap-graphite.sh:23:in `load': /var/lib/gems/1.9.1/gems/sensu-plugins-java-0.0.3/bin/metrics-java-heap-graphite.sh:13: syntax error, unexpected tCONSTANT, expecting keyword_do_cond or ';' or '\n' (SyntaxError)
while getopts 's:n:h' OPT; do
                         ^
/var/lib/gems/1.9.1/gems/sensu-plugins-java-0.0.3/bin/metrics-java-heap-graphite.sh:13: syntax error, unexpected keyword_do_cond, expecting $end
    from /usr/local/bin/metrics-java-heap-graphite.sh:23:in `<main>'
java-heap-pcnt.sh
/usr/local/bin/java-heap-pcnt.sh:23:in `load': /var/lib/gems/1.9.1/gems/sensu-plugins-java-0.0.3/bin/java-heap-pcnt.sh:15: syntax error, unexpected tCONSTANT, expecting keyword_do_cond or ';' or '\n' (SyntaxError)
while getopts 'w:c:n:hp' OPT; do
                            ^
/var/lib/gems/1.9.1/gems/sensu-plugins-java-0.0.3/bin/java-heap-pcnt.sh:15: syntax error, unexpected keyword_do_cond, expecting $end
    from /usr/local/bin/java-heap-pcnt.sh:23:in `<main>'

If anyone have the same problem and successfully resolved it - please, provide solution!
Thanks a lot.

Feature Request: supporting other jdks and pid sourcing

I can't seem to use this as is to profile the heap on a Puppet Enterprise (2016.1.x) for two reasons.

  1. I need opendjk installed, and it could work if you configured an optional secondary jps command.
  • ex -j /opt/puppetlabs/server/apps/java/lib/jvm/java/bin/jps
  • or -j could be the java bin path.
  1. jps doesn't actually return something usable. There isn't a single process. For some reason they're all named "main" mostly, as you see below:
/opt/puppetlabs/server/apps/java/lib/jvm/java/bin/jps
11472 main
5584 main
4128 main
3539 activemq.jar
13525 Jps
27461 main

I could get the pid from a pid file optionally as well:

[root@devcorepptl918 ~]# cat /var/run/puppetlabs/puppetserver/puppetserver
27461

But this seems like a lot of conditionals just for the puppet master.

My question is - would you be open to some changes here? I'm new to using jps and jstat, so maybe you have an easier fix. My suggestions would complicate this file quite a bit - maybe beyond where I'd even want to take it.

It'd be easier for me to use your script and hack up a one-off, but thought I'd raise the question of a PR. :)

Script metrics-jstat.rb return "IndexError: list index out of range"

Hello

I am just trying to get jstat metrics in Sensu with sensu-plugins-java
I launched "metrics-jstat.rb -D -H localhost -j Server" and got error message "IndexError: list index out of range"
It use jstat from java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64 on CentOS Linux release 7.4.1708
Else version of others packages are: sensu-1.1.1-1.el7.x86_64

Best regards.
rsf

$ metrics-jstat.rb -D -H localhost -j Server
Traceback (most recent call last):
File "/opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugins-java-1.3.0/bin/metrics-jstat.py", line 315, in
JstatMetricsToGraphiteFormat().main()
File "/opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugins-java-1.3.0/bin/metrics-jstat.py", line 268, in main
gc_stats = get_jstat_metrics("-gc", lvmid, metric_maps_gc)
File "/opt/sensu/embedded/lib/ruby/gems/2.4.0/gems/sensu-plugins-java-1.3.0/bin/metrics-jstat.py", line 243, in get_jstat_metrics
return dict([(metric_maps[title], values[position]) for position, title in enumerate(titles) if title in metric_maps])
IndexError: list index out of range

Multiple JPS processes causes command to hang

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

Dependabot can't resolve your Ruby dependency files

Dependabot can't resolve your Ruby dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Bundler::VersionConflict with message: Bundler could not find compatible versions for gem "english":
  In Gemfile:
    sensu-plugins-java was resolved to 0.0.1, which depends on
      english (= 0.6.3)

Could not find gem 'english (= 0.6.3)', which is required by gem 'sensu-plugins-java', in any of the sources.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Make it possible to use sudo for check-java-permgen.rb

The jstat and jps commands may require root access; let check-java-permgen.rb use sudo if told to. Requires the following in /etc/sudoers:

sensu ALL=(ALL) NOPASSWD: /path/to/java/jdk1.8.0_92/bin/jps
sensu ALL=(ALL) NOPASSWD: /path/to/java/jdk1.8.0_92/bin/jstat

JVM Used Heap Calculation

The current total heap calculation is
TotalHeap=jstat -gccapacity $PID | tail -n 1 | awk '{ print ($4 + $5 + $6 + $10) / 1024 }'
This includes: S0C, S1C, EC & OC (survivor, eden and Old space)

MC is not part of calculation above which seems to be correct.
However current heap calculation includes Metaspace utilization(MU)
UsedHeap=jstat -gc $PID | tail -n 1 | awk '{ print ($3 + $4 + $6 + $8 + $10) / 1024 }'
This includes: S0U, S1U, EU, OU and MU

Since MU is outside of JVM Heap, IMO, that shouldn't be part of the calculation.
The calculation should be
UsedHeap=$(sudo ${JAVA_BIN}jstat -gc $PID | tail -n 1 | awk '{ print ($3 + $4 + $6 + $8) / 1024 }')

metrics-java-heap-graphite.rb requires sensu to have sudo access, I can't figure out how to restrict.

So I'm not sure if it should require sudo access, I note on the README page/an example or 2 would be nice. Anyways I've been able to get metrics-java-heap-graphite.rb to run on sensu but only by setting up:

Defaults:sensu !requiretty

sensu ALL = NOPASSWD:ALL

I've tried all sorts of combinations of files to allow like

sensu ALL = NOPASSWD: /opt/sensu/embedded/bin/metrics-java-heap-graphite.rb, /opt/sensu/embedded/bin/metrics-java-heap-graphite.sh

but I just can't seem to figure it out. Some help would be much appreciated

Sensu check for jvm heap not working

I am facing issues with sensu-plugins-java. I have installed plugin in our server and I need to use check-java-heap-pcnt.rb to monitor the heap size in our server, but it is not showing proper output when I try to run the check locally. Here's how I tried to run the check locally:

# ./check-java-heap-pcnt.rb -n java -w 70 -c 85 -j /usr/java/defaults/bin/ -p
Here's the output it generated:

    invalid argument count
Usage: jstat -help|-options
       jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]

Definitions:
  <option>      An option reported by the -options option
  <vmid>        Virtual Machine Identifier. A vmid takes the following form:
                     <lvmid>[@<hostname>[:<port>]]
                Where <lvmid> is the local vm identifier for the target
                Java virtual machine, typically a process id; <hostname>is
                the name of the host running the target Java virtual machine;
                and <port> is the port number for the rmiregistry on the
                target host. See the jvmstat documentation for a more complete
                description of the Virtual Machine Identifier.
  <lines>       Number of samples between header lines.
  <interval>    Sampling interval. The following forms are allowed:
                    <n>["ms"|"s"]
                Where <n> is an integer and the suffix specifies the units as 
                milliseconds("ms") or seconds("s"). The default units are "ms".
  <count>       Number of samples to take before terminating.
  -J<flag>      Pass <flag> directly to the runtime system. 
(standard_in) 1: syntax error 
MEM UNKNOWN -

Maybe I am not using the correct syntax pattern. Please guide me as i need to monitor the jvm heap size for my production server.

BUG in check agnostic JAVA Version

When you use checks bin / check-java-heap-pcnt.sh and bin / metrics-java-heap-graphite.sh, instead of the actual Java version you are using, it is always calculated as JAVA 7, the variable used is a string and in the comparation statement is treating as an array this causes to return as a number of fields 1, calculating the memory as Java7 instead to be agnostic.

Checks are using Current HEAP instead of Max HEAP

When java is started with different values -Xms (initial memory allocation) and -Xmx (maximum memory allocation), the checks triggers an alarm when reach the treshold, but the percentage is calculated using the current size, later the JVM expand the memory because the HEAP is reaching the current memory and change the size, this trigger a resolved status.

We can not know with what percentage of memory the JVM will expand / decrease the current HEAP, it is necessary that the check calculate the used percentage with the Max memory that the HEAP could allocate.

Can't get metrics-jstat.rb to work because of the elevated privileges required by jstat

metrics-jstat.rb works fine from my local command line metrics-jstat.rb -j :::app_name::: -H :::name::: of course on the command line I have to actually type the app name. But it doesn't seem to work when running from sensu. It simple exits 1 with no output, and I don't see any details in sensu logs.

I've even tried giving sensu user full sudo access.

Feature request: check Java threads

Would be really helpful to have a check against the number of Java threads, as some of our Java applications are subject to thread explosions which signal imminent failure.

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.