-
Notifications
You must be signed in to change notification settings - Fork 265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Couchbase plugin #457
Open
oryband
wants to merge
2
commits into
MeetMe:master
Choose a base branch
from
kikinteractive:couchbase-plugin
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Couchbase plugin #457
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
""" | ||
couchbase | ||
|
||
""" | ||
from newrelic_plugin_agent.plugins import base | ||
|
||
|
||
class Couchbase(base.JSONStatsPlugin): | ||
|
||
GUID = 'com.meetme.newrelic_couchbase_agent' | ||
|
||
# metrics are according to api reference v3.0 or v3.1 | ||
METRICS = [ | ||
{'type': 'cluster', 'label': 'storageTotals.ram.total', 'suffix': 'bytes'}, | ||
{'type': 'cluster', 'label': 'storageTotals.ram.used', 'suffix': 'bytes'}, | ||
{'type': 'cluster', 'label': 'storageTotals.ram.usedByData', 'suffix': 'bytes'}, | ||
{'type': 'cluster', 'label': 'storageTotals.ram.quotaTotal', 'suffix': 'bytes'}, | ||
{'type': 'cluster', 'label': 'storageTotals.ram.quotaUsed', 'suffix': 'bytes'}, | ||
|
||
{'type': 'cluster', 'label': 'storageTotals.hdd.total', 'suffix': 'bytes'}, | ||
{'type': 'cluster', 'label': 'storageTotals.hdd.used', 'suffix': 'bytes'}, | ||
{'type': 'cluster', 'label': 'storageTotals.hdd.usedByData', 'suffix': 'bytes'}, | ||
{'type': 'cluster', 'label': 'storageTotals.hdd.quotaTotal', 'suffix': 'bytes'}, | ||
{'type': 'cluster', 'label': 'storageTotals.hdd.free', 'suffix': 'bytes'}, | ||
|
||
{'type': 'cluster', 'label': 'counters.rebalance_success', 'suffix': 'count'}, | ||
{'type': 'cluster', 'label': 'counters.rebalance_start', 'suffix': 'count'}, | ||
{'type': 'cluster', 'label': 'counters.rebalance_fail', 'suffix': 'count'}, | ||
{'type': 'cluster', 'label': 'counters.rebalance_node', 'suffix': 'count'}, | ||
|
||
{'type': 'nodes', 'label': 'systemStats.cpu_utilization_rate', 'suffix': 'count'}, | ||
{'type': 'nodes', 'label': 'systemStats.swap_total', 'suffix': 'byte'}, | ||
{'type': 'nodes', 'label': 'systemStats.swap_used', 'suffix': 'byte'}, | ||
{'type': 'nodes', 'label': 'systemStats.mem_total', 'suffix': 'byte'}, | ||
{'type': 'nodes', 'label': 'systemStats.mem_free', 'suffix': 'byte'}, | ||
|
||
{'type': 'nodes', 'label': 'interestingStats.couch_docs_actual_disk_size', 'suffix': 'byte'}, | ||
{'type': 'nodes', 'label': 'interestingStats.couch_docs_data_size', 'suffix': 'byte'}, | ||
{'type': 'nodes', 'label': 'interestingStats.couch_views_actual_disk_size', 'suffix': 'byte'}, | ||
{'type': 'nodes', 'label': 'interestingStats.couch_views_data_size', 'suffix': 'byte'}, | ||
{'type': 'nodes', 'label': 'interestingStats.mem_used', 'suffix': 'byte'}, | ||
{'type': 'nodes', 'label': 'interestingStats.ops', 'suffix': 'count'}, | ||
{'type': 'nodes', 'label': 'interestingStats.curr_items', 'suffix': 'count'}, | ||
{'type': 'nodes', 'label': 'interestingStats.curr_items_tot', 'suffix': 'count'}, | ||
{'type': 'nodes', 'label': 'interestingStats.vb_replica_curr_items', 'suffix': 'count'}, | ||
|
||
{'type': 'nodes', 'scoreboard': True, 'score_value': 'active', 'label': 'clusterMembership', 'suffix': 'count'}, | ||
{'type': 'nodes', 'scoreboard': True, 'score_value': 'healthy', 'label': 'status', 'suffix': 'count'}, | ||
|
||
{'type': 'buckets', 'label': 'basicStats.quotaPercentUsed', 'suffix': 'percent'}, | ||
{'type': 'buckets', 'label': 'basicStats.opsPerSec', 'suffix': 'ops'}, | ||
{'type': 'buckets', 'label': 'basicStats.diskFetches', 'suffix': 'percent'}, | ||
{'type': 'buckets', 'label': 'basicStats.itemCount', 'suffix': 'percent'}, | ||
{'type': 'buckets', 'label': 'basicStats.diskUsed', 'suffix': 'byte'}, | ||
{'type': 'buckets', 'label': 'basicStats.dataUsed', 'suffix': 'byte'}, | ||
{'type': 'buckets', 'label': 'basicStats.memUsed', 'suffix': 'byte'}, | ||
] | ||
|
||
def add_datapoints(self, data): | ||
"""Add data points for all couchbase nodes. | ||
|
||
:param dict stats: stats for all nodes | ||
|
||
""" | ||
# fetch metrics for each metric type (cluster, nodes, buckets) | ||
for typ, stats in data.iteritems(): | ||
# set items to fetch stats from, | ||
# and set item key name, where the item's name will be fetched from | ||
if typ == 'cluster': | ||
items = stats | ||
name_key = 'name' | ||
elif typ == 'nodes': | ||
items = stats['nodes'] | ||
name_key = 'hostname' | ||
elif typ == 'buckets': | ||
items = stats | ||
name_key = 'name' | ||
|
||
for metric in [m for m in self.METRICS if m['type'] == typ]: | ||
# count score for scoreboard metrics, | ||
# otherwise just add the gauge value from the API repsonse | ||
# | ||
# A "scoreboard" metric is a counter of a specific value for | ||
# a field. E.g How many times the pair {"status": "healthy"} | ||
# is found in a list of objects. | ||
# | ||
# NOTE that scoreboard metrics are meant to be used on lists | ||
# of objects e.g. a list of nodes. | ||
if metric.get('scoreboard', False): | ||
self.add_gauge_value( | ||
'%s/_scoreboard/%s' % (typ, metric['label']), | ||
metric['suffix'], | ||
sum(d[metric['label']] == metric['score_value'] | ||
for d in items)) | ||
else: | ||
# add gauge value for current metric. | ||
# NOTE cluster metrics are not repeated, | ||
# as there is a single cluster. | ||
# nodes and bucket metrics are repeated, | ||
# as there are (usually) several of them | ||
if typ == 'cluster': | ||
self._add_gauge_value( | ||
metric, typ, items[name_key], items) | ||
else: | ||
for item in items: | ||
self._add_gauge_value( | ||
metric, typ, item[name_key], item) | ||
|
||
def _add_gauge_value(self, metric, typ, name, items): | ||
"""Adds a gauge value for a nested metric. | ||
|
||
Some stats are missing from memcached bucket types, | ||
thus we use dict.get() | ||
|
||
:param dict m: metric as defined at the top of this class. | ||
:param str typ: metric type: cluster, nodes, buckets. | ||
:param str name: cluster, node, or bucket name. | ||
:param dict items: stats to lookup the metric in. | ||
|
||
""" | ||
label = metric['label'] | ||
value = items | ||
for key in label.split('.'): | ||
value = value.get(key, 0) | ||
self.add_gauge_value('%s/%s/%s' % (typ, name, label), | ||
metric['suffix'], value) | ||
|
||
def fetch_data(self): | ||
"""Fetch data from multiple couchbase stats URLs. | ||
|
||
Returns a dictionary with three keys: cluster, nodes, buckets. | ||
Each key holds the JSON response from the API request. | ||
|
||
:rtype: dict | ||
|
||
""" | ||
data = {} | ||
for path, typ in [('pools/default', 'cluster'), | ||
('pools/nodes', 'nodes'), | ||
('pools/default/buckets', 'buckets')]: | ||
res = self.http_get(self.stats_url + path) | ||
data[typ] = res and res.json() or {} | ||
|
||
return data |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are quite a few branching in this for loop. maybe it would be cleaner to have a for loop per
typ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there isn't much way around it, currently this is the easiest to grasp imo