# Install:
#   This plugin is sometimes bundled with collectd, if not
#   you can install with:
#
#     apt-get install collectd-java collectd-generic-jmx
#
#   If your collectd log shows an error loading java.so, see
#   http://www.willdurness.com/collectinggraphing-information-on-neo4j-via-collectd-and-graphite/
#   and how they setup LD_LIBRARY_PATH.  The basic problem is
#   collectd wants open JDK 6.  You can fix this by adding
#
#   export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/lib/jvm/java-7-oracle/jre/lib/amd64/server
#
#   to your collectd init file, but pointing to the correct
#   library path for your java install.
#
#   You need to install the signalfx_types_db on your system and reference it
#   from this config file:
#     cp signalfx_types_db /etc/collectd.d/signalfx_types_db
#
#   If you get the error "Blah blah" it could be because you're version of java is different
#   than the version of java that collectd was compiled with.  This is especially true for people
#   running java 6.  To resolve this, you need to compile collectd from source on a machine using
#   the same setup of java you want, and copy over the .jar files it generates to the jars inside
#   Djava.class.path.
#
#   If the plugin appears to load but you don't see any metrics, you may need to specify
#   a InstancePrefix parameter to give your metrics readable names.

# Documentation:
#   https://collectd.org/wiki/index.php/Plugin:Java
#   https://collectd.org/wiki/index.php/Plugin:GenericJMX
#   https://collectd.org/wiki/index.php/Plugin:GenericJMX/Config

# System modifications:
#   Make sure the JVMArg path points to valid jar files.  If you do not find
#   the generic-jmx jar in the JVMArg path you may need to install the collectd-generic-jmx plugin

# Config file modifications:
#   Do not modify the config file, but you **WILL** need another config file that
#   points to your java application.  See 20-javageneric.conf if you want a
#   catch-all config for any java app.

TypesDB "/etc/collectd.d/signalfx_types_db"
LoadPlugin java
<Plugin java>
    JVMArg "-verbose:jni"
    JVMArg "-Djava.class.path=/usr/share/collectd/java/collectd-api.jar:/usr/share/collectd/java/generic-jmx.jar"

    LoadPlugin "org.collectd.java.GenericJMX"
    <Plugin "GenericJMX">
        <MBean "classes">
            ObjectName "java.lang:type=ClassLoading"
            <Value>
                Type "gauge"
                InstancePrefix "loaded_classes"
                Table false
                Attribute "LoadedClassCount"
            </Value>
        </MBean>

        <MBean "garbage_collector">
            ObjectName "java.lang:type=GarbageCollector,*"
            InstancePrefix "gc-"
            InstanceFrom "name"
            <Value>
                Type "invocations"
                Table false
                Attribute "CollectionCount"
            </Value>
            <Value>
                Type "total_time_in_ms"
                InstancePrefix "collection_time"
                Table false
                Attribute "CollectionTime"
            </Value>
        </MBean>

        <MBean "memory-heap">
            ObjectName "java.lang:type=Memory"
            InstancePrefix "memory-heap"
            <Value>
                Type "jmx_memory"
                Table true
                Attribute "HeapMemoryUsage"
            </Value>
        </MBean>

        <MBean "memory-nonheap">
            ObjectName "java.lang:type=Memory"
            InstancePrefix "memory-nonheap"
            <Value>
                Type "jmx_memory"
                Table true
                Attribute "NonHeapMemoryUsage"
            </Value>
        </MBean>

        <MBean "memory_pool">
            ObjectName "java.lang:type=MemoryPool,*"
            InstancePrefix "memory_pool-"
            InstanceFrom "name"
            <Value>
                Type "jmx_memory"
                Table true
                Attribute "Usage"
            </Value>
        </MBean>
    </Plugin>
</Plugin>
