Skip to content
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

[riakcs] support Riak CS 2.1+ stats format #2920

Merged
merged 2 commits into from
Nov 17, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions checks.d/riakcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,21 @@ def process_stats(self, stats, tags):
if not stats:
raise Exception("No stats were collected")

legends = dict([(len(k), k) for k in stats["legend"]])
del stats["legend"]
for key, values in stats.iteritems():
legend = legends[len(values)]
for i, value in enumerate(values):
metric_name = "riakcs.{0}.{1}".format(key, legend[i])
self.gauge(metric_name, value, tags=tags)

if "legend" not in stats:
# riak cs 2.1+ stats format
for key, value in stats.iteritems():
suffix = key.rsplit("_", 1)[-1]
method = STATS_METHODS.get(suffix, "gauge")
getattr(self, method)("riakcs.{}".format(key), value, tags=tags)
else:
# pre 2.1 stats format
legends = dict([(len(k), k) for k in stats["legend"]])
del stats["legend"]
for key, values in stats.iteritems():
legend = legends[len(values)]
for i, value in enumerate(values):
metric_name = "riakcs.{0}.{1}".format(key, legend[i])
self.gauge(metric_name, value, tags=tags)

def _connect(self, instance):
for e in ("access_id", "access_secret"):
Expand Down Expand Up @@ -107,8 +114,16 @@ def _get_stats(self, s3, aggregation_key):

return stats


# We need this as the riak cs stats page returns json with duplicate keys
@classmethod
def load_json(cls, text):
return json.JSONDecoder(object_pairs_hook=multidict).decode(text)
data = json.loads(text)
if "legend" in data:
# riak cs before v2.1 had duplicate keys
data = json.JSONDecoder(object_pairs_hook=multidict).decode(text)
return data


STATS_METHODS = {
"one": "count",
"total": "monotonic_count",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For metrics ending in _one or _total I guessed they would be better tracked as counts than a as simple gauge. It wasn't entirely clear which method was the best for each of these. More info on various types of stats here: https://github.com/basho/riak_cs/wiki/%5BRFC%5D-Riak-CS-and-Stanchion-metrics-2.1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I'm reviewing these again and after reviewing the stats reported in my test, I think total maybe should use gauge rather than monotonic_count. Thoughts?

}