From 816095158bb83e8b0ecac86399420af96a888a6b Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 15 Apr 2015 12:45:55 +0200 Subject: [PATCH] add couchbase support this is a squash commit of all couchbase commits from minodes/newrelic-plugin-agent: - 33c9162f920cd821c6d051302b73ebb2ab27419d fix JSON access - 4e0695788575805e351863384eacf4ab1af1e708 read basicStats from all couchbase buckets - eb58aa6391e747903f9c76fdbb622a64d75dc8c3 basicStats now per bucket sent to newrelic - ede17dcb152838a300f127e5acdd95269482d1ad add couchbase support the original branch used in pull request #404 had a bunch of garbage commits related to other plugins (nagiorelic). i cleaned the unrelated stuff and squashed everything to a single commit --- README.rst | 7 +++ docker/base/newrelic-plugin-agent.cfg | 6 +++ etc/newrelic/newrelic-plugin-agent.cfg | 6 +++ newrelic_plugin_agent/plugins/__init__.py | 1 + newrelic_plugin_agent/plugins/couchbase.py | 60 ++++++++++++++++++++++ 5 files changed, 80 insertions(+) create mode 100644 newrelic_plugin_agent/plugins/couchbase.py diff --git a/README.rst b/README.rst index 917bf8f..3877aaa 100644 --- a/README.rst +++ b/README.rst @@ -7,6 +7,7 @@ NewRelic platform. Currently supported backend systems are: - Alternative PHP Cache - Apache HTTP Server - CouchDB +- Couchbase - Elasticsearch - HAProxy - Memcached @@ -298,6 +299,12 @@ Configuration Example #username: foo #password: bar + couchbase: + name: localhost + host: localhost + port: 8091 + path: pools/default/buckets + elasticsearch: name: clustername host: localhost diff --git a/docker/base/newrelic-plugin-agent.cfg b/docker/base/newrelic-plugin-agent.cfg index f957d04..3b7a316 100644 --- a/docker/base/newrelic-plugin-agent.cfg +++ b/docker/base/newrelic-plugin-agent.cfg @@ -22,6 +22,12 @@ Application: # username: foo # password: bar + #couchbase: + # name: localhost + # host: localhost + # port: 8091 + # path: pools/default/buckets + #elasticsearch: # name: Clustername # host: localhost diff --git a/etc/newrelic/newrelic-plugin-agent.cfg b/etc/newrelic/newrelic-plugin-agent.cfg index f957d04..3b7a316 100644 --- a/etc/newrelic/newrelic-plugin-agent.cfg +++ b/etc/newrelic/newrelic-plugin-agent.cfg @@ -22,6 +22,12 @@ Application: # username: foo # password: bar + #couchbase: + # name: localhost + # host: localhost + # port: 8091 + # path: pools/default/buckets + #elasticsearch: # name: Clustername # host: localhost diff --git a/newrelic_plugin_agent/plugins/__init__.py b/newrelic_plugin_agent/plugins/__init__.py index 98c5cb9..1a87a63 100644 --- a/newrelic_plugin_agent/plugins/__init__.py +++ b/newrelic_plugin_agent/plugins/__init__.py @@ -6,6 +6,7 @@ available = { 'apache_httpd': 'newrelic_plugin_agent.plugins.apache_httpd.ApacheHTTPD', 'couchdb': 'newrelic_plugin_agent.plugins.couchdb.CouchDB', + 'couchbase': 'newrelic_plugin_agent.plugins.couchbase.Couchbase', 'edgecast': 'newrelic_plugin_agent.plugins.edgecast.Edgecast', 'elasticsearch': 'newrelic_plugin_agent.plugins.elasticsearch.ElasticSearch', diff --git a/newrelic_plugin_agent/plugins/couchbase.py b/newrelic_plugin_agent/plugins/couchbase.py new file mode 100644 index 0000000..35c3f72 --- /dev/null +++ b/newrelic_plugin_agent/plugins/couchbase.py @@ -0,0 +1,60 @@ +""" +couchbase + +""" + +from newrelic_plugin_agent.plugins import base + + +class Couchbase(base.JSONStatsPlugin): + + GUID = 'com.meetme.couchbase' + + def add_datapoints(self, stats): + for bucket_data in stats: + bucket_name = bucket_data['name'] + bucket_stats = bucket_data['basicStats'] + if bucket_stats: + """ Example JSON + "basicStats":{ + "quotaPercentUsed":7.548735046386719, + "opsPerSec":0, + "diskFetches":0, + "itemCount":2222, + "diskUsed":229366539, + "dataUsed":203511808, + "memUsed":79154224 + } + """ + self.add_gauge_bucket_metric( + bucket_name, 'quotaPercentUsed', 'percent', bucket_stats['quotaPercentUsed'] + ) + self.add_gauge_bucket_metric( + bucket_name, 'opsPerSec', 'ops', bucket_stats['opsPerSec'] + ) + self.add_gauge_bucket_metric( + bucket_name, 'diskFetches', 'count', bucket_stats['diskFetches'] + ) + self.add_gauge_bucket_metric( + bucket_name, 'itemCount', 'count', bucket_stats['itemCount'] + ) + self.add_gauge_bucket_metric( + bucket_name, 'diskUsed', 'Byte', bucket_stats['diskUsed'] + ) + self.add_gauge_bucket_metric( + bucket_name, 'dataUsed', 'Byte', bucket_stats['dataUsed'] + ) + self.add_gauge_bucket_metric( + bucket_name, 'memUsed', 'Byte', bucket_stats['memUsed'] + ) + + # Summary metrics + self.add_gauge_value('Summary/%s/quotaPercentUsed' % bucket_name, 'percent', + bucket_stats['quotaPercentUsed'], + min_val=0, max_val=0) + self.add_gauge_value('Summary/%s/diskUsed' % bucket_name, 'byte', + bucket_stats['diskUsed']) + + def add_gauge_bucket_metric(self, bucket_name, metric_name, units, metric_value): + if metric_value: + self.add_gauge_value('%s/%s' % (bucket_name, metric_name), units, metric_value)