# This is the monitoring configuration for standalone JVMs.
# Look for JMX_HOST and JMX_PORT to adjust your configuration file.
# Replace JMX_PORT below with the value configured in your JVM deployment.
LoadPlugin java
<Plugin "java">
    JVMARG "-Djava.class.path=/opt/stackdriver/collectd/share/collectd/java/collectd-api.jar:/opt/stackdriver/collectd/share/collectd/java/generic-jmx.jar"
    LoadPlugin "org.collectd.java.GenericJMX"

    <Plugin "GenericJMX">
        <MBean "jvm_localhost_Threading">
            ObjectName "java.lang:type=Threading"
            <Value>
                Type "gauge"
                InstancePrefix "threading-daemon_thread_count"
                Table false
                Attribute "DaemonThreadCount"
            </Value>
            <Value>
                Type "gauge"
                InstancePrefix "threading-thread_count"
                Table false
                Attribute "ThreadCount"
            </Value>
            <Value>
                Type "gauge"
                InstancePrefix "threading-peak_thread_count"
                Table false
                Attribute "PeakThreadCount"
            </Value>
        </MBean>

        <MBean "jvm_localhost_Memory">
            ObjectName "java.lang:type=Memory"
            <Value>
                Type "memory"
                InstancePrefix "memory-heap_usage_committed"
                Table false
                Attribute "HeapMemoryUsage.committed"
            </Value>
            <Value>
                Type "memory"
                InstancePrefix "memory-non_heap_usage_committed"
                Table false
                Attribute "NonHeapMemoryUsage.committed"
            </Value>
            <Value>
                Type "memory"
                InstancePrefix "memory-heap_usage_used"
                Table false
                Attribute "HeapMemoryUsage.used"
            </Value>
            <Value>
                Type "memory"
                InstancePrefix "memory-non_heap_usage_used"
                Table false
                Attribute "NonHeapMemoryUsage.used"
            </Value>
            <Value>
                Type "memory"
                InstancePrefix "memory-heap_usage_max"
                Table false
                Attribute "HeapMemoryUsage.max"
            </Value>
            <Value>
                Type "memory"
                InstancePrefix "memory-non_heap_usage_max"
                Table false
                Attribute "NonHeapMemoryUsage.max"
            </Value>
        </MBean>

        <MBean "jvm_localhost_Runtime">
            ObjectName "java.lang:type=Runtime"
            <Value>
                Type "counter"
                InstancePrefix "runtime-uptime"
                Table false
                Attribute "Uptime"
            </Value>
        </MBean>

        <MBean "jvm_localhost_os">
            ObjectName "java.lang:type=OperatingSystem"
            <Value>
                Type "gauge"
                InstancePrefix "os-open_fd_count"
                Table false
                Attribute "OpenFileDescriptorCount"
            </Value>
            <Value>
                Type "counter"
                InstancePrefix "os-process_cpu_time"
                Table false
                Attribute "ProcessCpuTime"
            </Value>
        </MBean>

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

        <Connection>
            # When using non-standard JVM configurations, replace the below with
            #ServiceURL "service:jmx:rmi:///jndi/rmi://JMX_HOST:JMX_PORT/jmxrmi"
            ServiceURL "service:jmx:rmi:///jndi/rmi://localhost:JMX_PORT/jmxrmi"
            InstancePrefix "jvm"

            Collect "jvm_localhost_Threading"
            Collect "jvm_localhost_Memory"
            Collect "jvm_localhost_Runtime"
            Collect "jvm_localhost_os"
            Collect "jvm_localhost_gc"
        </Connection>
    </Plugin>
</Plugin>

LoadPlugin match_regex
LoadPlugin target_set
LoadPlugin target_replace
<Chain "GenericJMX_jvm">
    <Rule "rewrite_genericjmx_to_jvm">
        <Match regex>
            Plugin "^GenericJMX$"
            PluginInstance "^jvm.*$"
        </Match>
        <Target "replace">
            PluginInstance "jvm" ""
        </Target>
        <Target "set">
            Plugin "jvm"
        </Target>
        Target "return"
    </Rule>
</Chain>

<Chain "PreCache">
    <Rule "jump_to_GenericJMX_jvm">
        <Target "jump">
            Chain "GenericJMX_jvm"
        </Target>
    </Rule>
</Chain>
PreCacheChain "PreCache"