title: How to collect JMX metrics from an EC2 instance and populate it in AWS Cloudwatch
body: <p>I have the below setup in place.</p>
  
  <p>EC2 instance, with below packages installed to collect metrics</p>
  
  <ol>
  <li>cloudwatch agent</li>
  <li>cloudwatch plugin</li>
  <li>collectd</li>
  <li>collectd-java</li>
  <li>collectd-generic-jmx</li>
  <li>Elasticsearch</li>
  </ol>
  
  <p>Now, my purpose is to collect Elasticsearch jmx related metrics (Heap Space Used, gc time, etc) and publish them to cloudwatch which I am unable to do.
  I am able to scrape other metrics (mem, df, cpu) to cloudwatch but there are no traces of jmx metrics seen on cloudwatch.</p>
  
  <p>Is it possible to collect elastic search jmx metrics, is my configuration correct, please help
  I am new to jmx configuration.</p>
  
  <p>Please find my collectd-cloudwatch.conf configuration</p>
  
  <pre><code>&lt;Plugin "java"&gt;
  JVMArg "-Djava.class.path=/usr/share/collectd/java/collectd-api.jar:/usr/share/collectd/java/generic-jmx.jar"
  LoadPlugin "org.collectd.java.GenericJMX"
  &lt;Plugin "GenericJMX"&gt;
    &lt;MBean "gc-count"&gt;
      ObjectName "java.lang:type=GarbageCollector,*"
      InstancePrefix "gc-"
      InstanceFrom "name"
      &lt;Value&gt;
        Type "derive"
        Table false
        Attribute "CollectionCount"
        InstancePrefix "count"
      &lt;/Value&gt;
    &lt;/MBean&gt;
     &lt;MBean "gc-time"&gt;
      ObjectName "java.lang:type=GarbageCollector,*"
      InstancePrefix "gc-"
      InstanceFrom "name"
      &lt;Value&gt;
        Type "derive"
        Table false
        Attribute "CollectionTime"
        InstancePrefix "time"
      &lt;/Value&gt;
    &lt;/MBean&gt;
    &lt;MBean "memory_pool"&gt;
      ObjectName "java.lang:type=MemoryPool,*"
      InstancePrefix "memory_pool-"
   InstanceFrom "name"
      &lt;Value&gt;
        Type "memory"
        Table true
        Attribute "Usage"
      &lt;/Value&gt;
    &lt;/MBean&gt;
     &lt;MBean "memory-heap"&gt;
      ObjectName "java.lang:type=Memory"
      InstancePrefix "memory-heap"
      &lt;Value&gt;
        Type "memory"
        Table true
        Attribute "HeapMemoryUsage"
      &lt;/Value&gt;
    &lt;/MBean&gt;
    &lt;MBean "memory-nonheap"&gt;
      ObjectName "java.lang:type=Memory"
      InstancePrefix "memory-nonheap"
      &lt;Value&gt;
        Type "memory"
        Table true
        Attribute "NonHeapMemoryUsage"
      &lt;/Value&gt;
    &lt;/MBean&gt;
     &lt;MBean "thread"&gt;
      ObjectName "java.lang:type=Threading"
      InstancePrefix "threading"
      &lt;Value&gt;
        Type "gauge"
        Table false
        Attribute "ThreadCount"
        InstancePrefix "count"
      &lt;/Value&gt;
    &lt;/MBean&gt;
    &lt;MBean "thread-daemon"&gt;
      ObjectName "java.lang:type=Threading"
      InstancePrefix "threading"
      &lt;Value&gt;
        Type "gauge"
        Table false
        Attribute "DaemonThreadCount"
        InstancePrefix "count-daemon"
      &lt;/Value&gt;
    &lt;/MBean&gt;
    &lt;Connection&gt;
      ServiceURL "service:jmx:rmi:///jndi/rmi://localhost:9200/ ---&gt; elasticsearch running with https
      Collect "memory_pool"
      Collect "memory-heap"
      Collect "memory-nonheap"
      Collect "gc-count"
      Collect "gc-time"
      Collect "thread"
      Collect "thread-daemon"
      User "kibana"
      Password "kibana"
    &lt;/Connection&gt;
  &lt;/Plugin&gt;
  &lt;/Plugin&gt;
  </code></pre>
  
  <p>Here is the error which I am getting in collectd logs</p>
  
  <pre><code>[2020-04-19 10:18:46] [error] GenericJMX plugin: Evaluating `Connection' block failed: java.lang.IllegalArgumentException: No service URL was defined.
  </code></pre>