From ae8771f414857d92aada464cfb541e83ee6d5729 Mon Sep 17 00:00:00 2001
From: James Gu <jgu@suse.com>
Date: Thu, 25 Jan 2018 17:06:35 -0800
Subject: [PATCH] Add monasca agent plugin to monitor cassandra health
URL: https://review.openstack.org/#/c/538096/

Adds detection plugin to monitor cassandra service, including
the process, and the data directory through the args.

Change-Id: Ic2c20bc878527f607c0eb871e98a79c1521c0507
Story: 2001499
task: 6289
---
 docs/Plugins.md                              | 23 +++++++++++++++
 monasca_setup/detection/plugins/cassandra.py | 42 ++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+)
 create mode 100644 monasca_setup/detection/plugins/cassandra.py

diff --git a/docs/Plugins.md b/docs/Plugins.md
index dc9452262b69..2feb6f6ae644 100644
--- a/docs/Plugins.md
+++ b/docs/Plugins.md
@@ -319,6 +319,7 @@ These are the detection plugins included with the Monasca Agent.  See [Customiza
 | apache | Plugin |
 | barbican | ServicePlugin |
 | bind | Plugin |
+| cassandra | ServicePlugin |
 | ceilometer | ServicePlugin |
 | ceph | Plugin |
 | cert_check | ArgsPlugin |
@@ -608,6 +609,28 @@ The cAdvisor host check returns the following metrics:
 | net.out_packets | hostname, interface, unit | Total network packets sent by all interfaces
 | net.out_packets_sec | hostname, interface, unit | Total number of network packets sent by all interfaces per second
 
+## Cassandra Checks
+This section documents a sampling of the metrics generated by the checks setup
+automatically by the monasca-setup script for the Cassandra service. Please
+note that no directories are monitored per default. `directory_names` argument
+can be passed to monasca-setup to change this behaviour.
+
+The following Cassandra processes are monitored, if they exist when the
+monasca-setup script is run:
+
+##### Cassandra Processes Monitored
+* cassandra
+
+##### Example Cassandra Metrics
+
+| Component | Metric Name | Metric Type | Check Type | Dimensions | Plugin | Description |
+| --------- | ----------- | ----------- | ---------- | ---- | ------ | ----------- | ----- |
+| cassandra | process_pid_count | Gauge | Passive | service=cassandra, component=cassandra, process_user=cassandra | process | cassandra process pid count |
+| cassandra | directory.files_count | Gauge | Active | service=cassandra, component=cassandra, path=/var/cassandra/data | cassandra data directory file count |
+| cassandra | directory.size_bytes | Gauge | Active | service=cassandra, component=cassandra, path=/var/cassandra/data | cassandra data directory size |
+| cassandra | directory.files_count | Gauge | Active | service=cassandra, component=cassandra, path=/var/cassandra/commitlog | cassandra commit log directory file count |
+| cassandra | directory.size_bytes | Gauge | Active | service=cassandra, component=cassandra, path=/var/cassandra/commitlog | cassandra commit log directory size |
+
 ## Check_MK_Local
 The [Check_MK](http://mathias-kettner.com/check_mk.html) [Agent](http://mathias-kettner.com/checkmk_linuxagent.html) can be extended through a series of [local checks](http://mathias-kettner.com/checkmk_localchecks.html).  This plugin parses the `<<<local>>>` output of `check_mk_agent` and converts them into Monasca metrics.  It is installed by `monasca-setup` automatically when the `check_mk_agent` script is found to be installed on the system.
 
diff --git a/monasca_setup/detection/plugins/cassandra.py b/monasca_setup/detection/plugins/cassandra.py
new file mode 100644
index 000000000000..e0c5e73b79d9
--- /dev/null
+++ b/monasca_setup/detection/plugins/cassandra.py
@@ -0,0 +1,42 @@
+
+# Copyright 2018 SUSE LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import monasca_setup.detection
+
+
+class Cassandra(monasca_setup.detection.ServicePlugin):
+
+    """Detect Cassandra daemons and setup configuration to monitor them.
+        Cassandra directories can be checked by passing in a directory_names
+        list. example: 'directory_names': [('/var/cassasndra/data',
+        '/var/cassasndra/commitlog', '/var/log/cassandra')]
+        Cassandra process user name can be overwritten by passing in
+        process_username.
+        See ServicePlugin for details.
+    """
+
+    def __init__(self, template_dir, overwrite=True, args=None):
+        service_params = {
+            'args': args,
+            'template_dir': template_dir,
+            'overwrite': overwrite,
+            'service_name': 'cassandra',
+            'component_name': 'cassandra',
+            'process_username': 'cassandra',
+            'service_api_url': '',
+            'search_pattern': ''
+        }
+
+        super(Cassandra, self).__init__(service_params)
-- 
2.15.1

