* @param type Type of Cache to identify metrics.
* @param cache Cache to measure metrics
*/
public CacheMetrics(String type, final ICache cache)
{
capacity = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "Capacity", type), new Gauge<Long>()
{
public Long value()
{
return cache.capacity();
}
});
hits = Metrics.newMeter(new MetricName(GROUP_NAME, TYPE_NAME, "Hits", type), "hits", TimeUnit.SECONDS);
requests = Metrics.newMeter(new MetricName(GROUP_NAME, TYPE_NAME, "Requests", type), "requests", TimeUnit.SECONDS);
hitRate = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "HitRate", type), new RatioGauge()
{
protected double getNumerator()
{
return hits.count();
}
protected double getDenominator()
{
return requests.count();
}
});
size = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "Size", type), new Gauge<Long>()
{
public Long value()
{
return cache.weightedSize();
}
});
entries = Metrics.newGauge(new MetricName(GROUP_NAME, TYPE_NAME, "Entries", type), new Gauge<Integer>()
{
public Integer value()
{
return cache.size();
}