DataStax Developer Blog

Metrics in Apache Cassandra 1.2

By Yuki Morishita -  January 30, 2013 | 1 Comment

Apache Cassandra exposes various kind of internal metrics from client read/write request latencies to ColumnFamily’s Bloom filter false positive ratio through JMX. From version 1.1, Cassandra started using Yammer’s Metrics library to track new client request metrics. Cassandra 1.2 expands use of the library to other metrics that are already available and put them together into org.apache.cassandra.metrics JMX domain. For backward compatibility, metrics are still available through the same JMX location as before (in fact, nodetool is still using old interface), but those implementations are (almost) replaced by new metrics.

Motivation

So what’s good about using Metrics library? Metrics library offers some fundamental tools for tracking metrics such as Counters, Gauges and Timers with ease of use API.

For example, to track client request read/write latency, we use Timer. You just code to start and stop Timer and it calculates all the interesting metrics we need. As you can see in the picture bellow, write latency now shows various percentiles, min, mean, max values and request rates.

jconsole showing write latency metrics

Exporting metrics

One nice feature that Metrics library has is the ability to export metrics to files or other systems periodically.
There are official “metrics reporters” to export metrics to csv files, console, and external systems like Ganglia and Graphite. Also, there are community developed reporters like statsd reporter.

Example: Graphite integration

Let me show you quick example. Metrics reporting feature is not fully integrated into Cassandra yet (there is a ticket for this), so you need to do some coding to configure reporting.
Since we don’t want to add code to Cassandra itself, we use java agent to setup metrics reporting to Graphite.

1. Get Metrics Graphite reporter jar

You need to grab metrics-graphite-2.0.3.jar and place it to $CASSANDRA_HOME/lib directory. When Cassandra starts up, it is added to classpath automatically. We also use it to compile our agent.

2. Write java code to configure GraphiteReporter

You also need MANIFEST.MF to run as a java agent

3. Package into jar

Compile the code and package into jar file. For example:

$ javac -cp $CASSANDRA_HOME/lib/metrics-core-2.0.3.jar:$CASSANDRA_HOME/lib/metrics-graphite-2.0.3.jar com/datastax/example/ReportAgent.java
$ jar -cfM reporter.jar .

4. Edit cassandra-env.sh

You need to add following line at the end of “conf/cassandra-env.sh” to load your jar as java agent.

JVM_OPTS="-javaagent:/path/to/your/reporter.jar $JVM_OPTS"

5. Start Cassandra

And voilà. Eventually you can see your Metrics through Graphite web interface.

Graphite web interface showing Cassandra metrics

Available metrics

There is a large number of metrics available in Cassandra so I cannot list all up in this post. Instead, you can find the list of new metrics and their brief explanations at Apache Cassandra Wiki.

Conclusion

In this article, I showed how cassandra’s metrics are built using Yammer’s Metrics library and example reporting using Graphite. New metrics offer much more information than previous versions, and are easily integrated to other systems.



Comments

  1. sanjay says:

    Can anyone give me a sample Report agent code.

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>