Add Cassandra JMX metrics collection

Change-Id: Iae539abcd76e5a97ef9ac2f9befa23bfd0d78aee
diff --git a/opencontrail/files/collectd_cassandra_jmx.conf b/opencontrail/files/collectd_cassandra_jmx.conf
new file mode 100644
index 0000000..b176754
--- /dev/null
+++ b/opencontrail/files/collectd_cassandra_jmx.conf
@@ -0,0 +1,217 @@
+{%- from "collectd/map.jinja" import client with context %}
+{%- from "linux/map.jinja" import system with context %}
+<LoadPlugin java>
+  Globals false
+</LoadPlugin>
+
+<Plugin "java">
+  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 "cassandra/native_clients">
+      ObjectName "org.apache.cassandra.metrics:type=Client,name=connectedNativeClients"
+      <Value>
+        Attribute "Value"
+        Type "gauge"
+        Table false
+        InstancePrefix "connectedNativeClients"
+      </Value>
+    </MBean>
+    <MBean "cassandra/thrift_clients">
+      ObjectName "org.apache.cassandra.metrics:type=Client,name=connectedThriftClients"
+      <Value>
+        Attribute "Value"
+        Type "gauge"
+        Table false
+        InstancePrefix "connectedThriftClients"
+      </Value>
+    </MBean>
+    <MBean "cassandra/clientrequest_read">
+      ObjectName "org.apache.cassandra.metrics:type=ClientRequest,scope=Read,name=Latency"
+      <Value>
+        Attribute "Mean"
+        Type "gauge"
+        Table false
+        InstancePrefix "clientRequest_Read_Mean"
+      </Value>
+      <Value>
+        Attribute "MeanRate"
+        Type "gauge"
+        Table false
+        InstancePrefix "clientRequest_Read_MeanRate"
+      </Value>
+      <Value>
+        Attribute "50thPercentile"
+        Type "gauge"
+        Table false
+        InstancePrefix "clientRequest_Read_50thPercentile"
+      </Value>
+    </MBean>
+    <MBean "cassandra/clientrequest_write">
+      ObjectName "org.apache.cassandra.metrics:type=ClientRequest,scope=Write,name=Latency"
+      <Value>
+        Attribute "Mean"
+        Type "gauge"
+        Table false
+        InstancePrefix "clientRequest_Write_Mean"
+      </Value>
+      <Value>
+        Attribute "MeanRate"
+        Type "gauge"
+        Table false
+        InstancePrefix "clientRequest_Write_MeanRate"
+      </Value>
+      <Value>
+        Attribute "50thPercentile"
+        Type "gauge"
+        Table false
+        InstancePrefix "clientRequest_Write_50thPercentile"
+      </Value>
+    </MBean>
+    <MBean "cassandra/java_usage">
+      ObjectName "java.lang:type=Memory"
+      <Value>
+        Attribute "NonHeapMemoryUsage"
+        Type "gauge"
+        InstancePrefix "NonHeapMemoryUsage"
+      </Value>
+    </MBean>
+    <MBean "cassandra/endpoints">
+      ObjectName "org.apache.cassandra.net:type=FailureDetector"
+      <Value>
+        Attribute "DownEndpointCount"
+        Type "gauge"
+        Table false
+        InstancePrefix "DownEndpointCount"
+      </Value>
+      <Value>
+        Attribute "UpEndpointCount"
+        Type "gauge"
+        Table false
+        InstancePrefix "UpEndpointCount"
+      </Value>
+    </MBean>
+    <MBean "cassandra/compaction">
+      ObjectName "org.apache.cassandra.metrics:type=Compaction,name=CompletedTasks"
+      <Value>
+        Attribute "Value"
+        Type "gauge"
+        Table false
+        InstancePrefix "CompactionCompletedTasks"
+      </Value>
+    </MBean>
+    <MBean "cassandra/compaction_pending">
+      ObjectName "org.apache.cassandra.metrics:type=Compaction,name=PendingTasks"
+      <Value>
+        Attribute "Value"
+        Type "gauge"
+        Table false
+        InstancePrefix "CompactionPendingTasks"
+      </Value>
+    </MBean>
+    <MBean "cassandra/garbagecollector">
+      ObjectName "java.lang:type=GarbageCollector,name=ConcurrentMarkSweep"
+      <Value>
+        Attribute "CollectionCount"
+        Type "gauge"
+        Table false
+        InstancePrefix "GarbageCollectorCollectionCounta"
+      </Value>
+      <Value>
+        Attribute "CollectionTime"
+        Type "gauge"
+        Table false
+        InstancePrefix "GarbageCollectorCollectionTime"
+      </Value>
+    </MBean>
+    <MBean "cassandra/cmsoldgen">
+      ObjectName "java.lang:type=MemoryPool,name=CMS Old Gen"
+      <Value>
+        Attribute "Usage.used"
+        Type "gauge"
+        Table false
+        InstancePrefix "CMSOldGen"
+      </Value>
+    </MBean>
+    <MBean "cassandra/cmspermgen">
+      ObjectName "java.lang:type=MemoryPool,name=CMS Perm Gen"
+      <Value>
+        Attribute "Usage.used"
+        Type "gauge"
+        Table false
+        InstancePrefix "CMSPermGen"
+      </Value>
+    </MBean>
+    <MBean "cassandra/headmemoryusage">
+      ObjectName "java.lang:type=Memory"
+      <Value>
+        Type "memory"
+        Table false
+        Attribute "HeapMemoryUsage.committed"
+      </Value>
+      <Value>
+        Type "memory"
+        Table false
+        Attribute "HeapMemoryUsage.used"
+      </Value>
+      <Value>
+        Type "memory"
+        Table false
+        Attribute "NonHeapMemoryUsage.max"
+      </Value>
+      <Value>
+        Type "memory"
+        Table false
+        Attribute "NonHeapMemoryUsage.used"
+      </Value>
+      <Value>
+        Type "memory"
+        Table false
+        Attribute "NonHeapMemoryUsage.committed"
+      </Value>
+      <Value>
+        Type "memory"
+        InstancePrefix "memory-heap_usage_max"
+        Table false
+        Attribute "HeapMemoryUsage.max"
+      </Value>
+    </MBean>
+    <MBean "cassandra/storageexceptioncount">
+      ObjectName "org.apache.cassandra.metrics:type=Storage,name=Exceptions"
+      <Value>
+        Attribute "Count"
+        Type "gauge"
+        Table false
+        InstancePrefix "StorageExceptionCount"
+      </Value>
+    </MBean>
+    <MBean "cassandra/storageload">
+      ObjectName "org.apache.cassandra.db:type=StorageService"
+      <Value>
+        Attribute "Load"
+        Type "gauge"
+        Table false
+        InstancePrefix "StorageDBLoad"
+      </Value>
+    </MBean>
+    <Connection>
+      InstancePrefix "cassandra"
+      ServiceURL "service:jmx:rmi:///jndi/rmi://127.0.0.1:7199/jmxrmi"
+      Collect "cassandra/native_clients"
+      Collect "cassandra/thrift_clients"
+      Collect "cassandra/clientrequest_read"
+      Collect "cassandra/clientrequest_write"
+      Collect "cassandra/endpoints"
+      Collect "cassandra/compaction"
+      Collect "cassandra/compaction_pending"
+      Collect "cassandra/garbagecollector"
+      Collect "cassandra/cmsoldgen"
+      Collect "cassandra/cmspermgen"
+      Collect "cassandra/cmspermgen"
+      Collect "cassandra/headmemoryusage"
+      Collect "cassandra/storageexceptioncount"
+      Collect "cassandra/storageload"
+    </Connection>
+  </Plugin>
+</Plugin>
diff --git a/opencontrail/meta/collectd.yml b/opencontrail/meta/collectd.yml
index 02e0428..e849738 100644
--- a/opencontrail/meta/collectd.yml
+++ b/opencontrail/meta/collectd.yml
@@ -1,8 +1,13 @@
 {%- if pillar.opencontrail is defined %}
 {%- if pillar.opencontrail.control is defined %}
-{%- from "opencontrail/map.jinja" import control, collector, config with context %}
+{%- from "opencontrail/map.jinja" import control, collector, config, database with context %}
 local_plugin:
 {%- if control.get('enabled', False) %}
+{%- if database is defined and database.get('cassandra', False) %}
+  collectd_cassandra_jmx:
+    plugin: java
+    template: opencontrail/files/collectd_cassandra_jmx.conf
+{%- endif %}
 {%- set bind_addr=control.bind.address|replace('0.0.0.0', '127.0.0.1') %}
   collectd_contrail_apis:
     plugin: python