This projects is forked from metrics-opentsdb with thanks to Sean Scanlon for initiating it.
CSF is a java library to provide an agent that combines implementations of the following:
git clone https://github.com/nickman/tsdb-csf.git
)mvn clean install
Public maven repo pending.
Note: References herein to "Metrics" (with the upper case M, yeah ?) refer to CodaHale/DropWizard Metrics, while references to "metrics" refer to several things and must be considered in context.
Here's a step-by-step of the current version of KitchenSink which contrives one of each of the main metric types in CodaHale's Metrics.
public static void main(String[] args) {
KitchenSink ks = new KitchenSink();
System.out.println("KitchenSink Started");
}
Here we create a new MetricRegistry and define a set of metrics to register in it. Nothing new to Metrics users here, except the OpenTSDB tag friendly names. (More on this below)
// Create a new MetricRegistry
final MetricRegistry registry = new MetricRegistry();
// Create a new Gauge Metric
final Gauge<Long> cacheSizeGauge = new Gauge<Long>() {
@Override
public Long getValue() {
final Random random = new Random(System.currentTimeMillis());
return new Long(Math.abs(random.nextInt(1000)));
}
};
// Create a new Counter Metric
final Counter evictions = registry.counter(name(getClass().getSimpleName(), "evictions", "cmtype=Counter", "op=cache-evictions", "service=cacheservice"));
// Create a new Histogram Metric
final Histogram resultCounts = registry.histogram(name(getClass().getSimpleName(), "resultCounts", "cmtype=Histogram", "op=cache-lookup", "service=cacheservice"));
// Create a new Meter Metric
final Meter lookupRequests = registry.meter(name(getClass().getSimpleName(), "lookupRequests", "cmtype=Meter", "op=cache-lookup", "service=cacheservice"));
// Create a new Timer Metric
final Timer timer = registry.timer(name(getClass().getSimpleName(), "evictelapsed", "cmtype=Timer", "op=cache-evictions", "service=cacheservice"));
A traditional Metrics metric name for, say the cacheSizeGauge gauge, would look something like this:
KitchenSink.cacheservice.cache-size
OpenTSDB metrics, however, are mapped, or tagged formatted metrics. A fully qualified metric name consists of a metric name which broadly describes what the value is, and one or more tags which are name/value pairs that provide specificity as to the provenance of the metric value. Here's a classic and simple example (slightly modified from a Bosun created metric):
cpu.percpu:host=appserver9,type=idle,cpu=7
From this we divine:
If you're not familiar with this, I would shoot over to OpenTSDB and read their documentation on Understanding Metrics and Time Series
One of the big motivations for starting this project was to provide a means of using Metrics while retaining very granular control of how OpenTSDB metric names are managed. Sensibly defined and implemented OpenTSDB metric names, especially tags, are of paramount importance as concerns the functionality and performance of OpenTSDB. 'nuff said ?
Back at the KitchenSink, we're using the MetricRegistry's static name method to generate what ends up being a fairly detailed (albeit contrived) OpenTSDB metric name (going forward, the OMN). Once again, here's the counter Metric creation:
// Create a new Counter Metric
final Counter evictions =
registry.counter(name(getClass().getSimpleName(),
"evictions",
"op=cache-evictions",
"service=cacheservice"));
KitchenSink.evictions
. The basis for the OMN is now KitchenSink.evictions:op=cache-evictions,service=cacheservice
, but we're not done yet. There's 2 more additions:
After these two additions, the OMN used to report the Counter metric will be: KitchenSink.evictions.count:app=KitchenSink,host=hserval,op=cache-evictions,service=cacheservice
See AllKitchenSinkMetrics for a list of all the OMNs generated by KitchenSink.
For our efforts, here's how OpenTSDB sees it:
TSDB-CSF retains the original license of metrics-opentsdb which is Apache 2.0.
.... and there are a handful of source files that have the wrong header. I will fix them....