Skip to content
This repository has been archived by the owner on Dec 14, 2017. It is now read-only.

Commit

Permalink
Refacotring to add the "get" before getter methods for metric informa…
Browse files Browse the repository at this point in the history
…tion.
  • Loading branch information
gorzell committed Mar 23, 2012
1 parent ce8ace2 commit fe9b883
Show file tree
Hide file tree
Showing 34 changed files with 551 additions and 367 deletions.
Expand Up @@ -15,6 +15,8 @@
*/
package com.yammer.metrics.annotation;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
Expand Down Expand Up @@ -43,6 +45,12 @@ public Object getObject() {

/** Returns the attributes with {@link Publish} annotations. */
public List<AnnotatedMetricAttribute> getAttributes() {
Collections.sort(attrs, new Comparator<AnnotatedMetricAttribute>() {
@Override
public int compare(AnnotatedMetricAttribute annotatedMetricAttribute, AnnotatedMetricAttribute annotatedMetricAttribute1) {
return annotatedMetricAttribute.getName().compareTo(annotatedMetricAttribute1.getName());
}
});
return attrs;
}

Expand Down
Expand Up @@ -121,7 +121,7 @@ public static Number getNumber(Object obj, AccessibleObject attr)
*
* @param annotationClass the type of annotation to check for
* @param obj instance to query
* @param maxPerClass max number of annotated attributes that are
* @param maxPerClass getMax number of annotated attributes that are
* permitted for this class
* @return map of name to matching attributes. Note if a field and a method have the same name, the method will win.
*/
Expand Down
98 changes: 79 additions & 19 deletions metrics-core/src/main/java/com/yammer/metrics/core/Histogram.java
Expand Up @@ -132,64 +132,64 @@ public void update(long value) {
* @return the number of values recorded
*/
@Publish
public long count() {
public long getCount() {
return count.get();
}

/* (non-Javadoc)
* @see com.yammer.metrics.core.Summarizable#max()
* @see com.yammer.metrics.core.Summarizable#getMax()
*/
@Override
@Publish
public double max() {
if (count() > 0) {
public double getMax() {
if (getCount() > 0) {
return max.get();
}
return 0.0;
}

/* (non-Javadoc)
* @see com.yammer.metrics.core.Summarizable#min()
* @see com.yammer.metrics.core.Summarizable#getMin()
*/
@Override
@Publish
public double min() {
if (count() > 0) {
public double getMin() {
if (getCount() > 0) {
return min.get();
}
return 0.0;
}

/* (non-Javadoc)
* @see com.yammer.metrics.core.Summarizable#mean()
* @see com.yammer.metrics.core.Summarizable#getMean()
*/
@Override
@Publish
public double mean() {
if (count() > 0) {
return sum.get() / (double) count();
public double getMean() {
if (getCount() > 0) {
return sum.get() / (double) getCount();
}
return 0.0;
}

/* (non-Javadoc)
* @see com.yammer.metrics.core.Summarizable#stdDev()
* @see com.yammer.metrics.core.Summarizable#getStdDev()
*/
@Override
@Publish
public double stdDev() {
if (count() > 0) {
public double getStdDev() {
if (getCount() > 0) {
return sqrt(variance());
}
return 0.0;
}

/* (non-Javadoc)
* @see com.yammer.metrics.core.Summarizable#sum()
* @see com.yammer.metrics.core.Summarizable#getSum()
*/
@Override
@Publish
public double sum() {
public double getSum() {
return (double) sum.get();
}

Expand All @@ -198,11 +198,71 @@ public Snapshot getSnapshot() {
return sample.getSnapshot();
}

/**
* Returns the median value in the distribution.
*
* @return the median value in the distribution
*/
@Publish
public double getMedian() {
return getSnapshot().getMedian();
}

/**
* Returns the value at the 75th percentile in the distribution.
*
* @return the value at the 75th percentile in the distribution
*/
@Publish
public double get75thPercentile() {
return getSnapshot().get75thPercentile();
}

/**
* Returns the value at the 95th percentile in the distribution.
*
* @return the value at the 95th percentile in the distribution
*/
@Publish
public double get95thPercentile() {
return getSnapshot().get95thPercentile();
}

/**
* Returns the value at the 98th percentile in the distribution.
*
* @return the value at the 98th percentile in the distribution
*/
@Publish
public double get98thPercentile() {
return getSnapshot().get98thPercentile();
}

/**
* Returns the value at the 99th percentile in the distribution.
*
* @return the value at the 99th percentile in the distribution
*/
@Publish
public double get99thPercentile() {
return getSnapshot().get99thPercentile();
}

/**
* Returns the value at the 99.9th percentile in the distribution.
*
* @return the value at the 99.9th percentile in the distribution
*/
@Publish
public double get999thPercentile() {
return getSnapshot().get999thPercentile();
}

private double variance() {
if (count() <= 1) {
if (getCount() <= 1) {
return 0.0;
}
return variance.get()[1] / (count() - 1);
return variance.get()[1] / (getCount() - 1);
}

private void setMax(long potentialMax) {
Expand Down Expand Up @@ -233,7 +293,7 @@ private void updateVariance(long value) {
final double oldM = oldValues[0];
final double oldS = oldValues[1];

final double newM = oldM + ((value - oldM) / count());
final double newM = oldM + ((value - oldM) / getCount());
final double newS = oldS + ((value - oldM) * (value - newM));

newValues[0] = newM;
Expand Down
16 changes: 8 additions & 8 deletions metrics-core/src/main/java/com/yammer/metrics/core/Meter.java
Expand Up @@ -9,7 +9,7 @@
import java.util.concurrent.atomic.AtomicLong;

/**
* A meter metric which measures mean throughput and one-, five-, and fifteen-minute
* A meter metric which measures getMean throughput and one-, five-, and fifteen-minute
* exponentially-weighted moving average throughputs.
*
* @see <a href="http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average">EMA</a>
Expand Down Expand Up @@ -90,36 +90,36 @@ public void mark(long n) {

@Override
@Publish
public long count() {
public long getCount() {
return count.get();
}

@Override
@Publish
public double fifteenMinuteRate() {
public double getFifteenMinuteRate() {
return m15Rate.rate(rateUnit);
}

@Override
@Publish
public double fiveMinuteRate() {
public double getFiveMinuteRate() {
return m5Rate.rate(rateUnit);
}

@Override
@Publish
public double meanRate() {
if (count() == 0) {
public double getMeanRate() {
if (getCount() == 0) {
return 0.0;
} else {
final long elapsed = (clock.tick() - startTime);
return convertNsRate(count() / (double) elapsed);
return convertNsRate(getCount() / (double) elapsed);
}
}

@Override
@Publish
public double oneMinuteRate() {
public double getOneMinuteRate() {
return m1Rate.rate(rateUnit);
}

Expand Down
16 changes: 8 additions & 8 deletions metrics-core/src/main/java/com/yammer/metrics/core/Metered.java
Expand Up @@ -3,7 +3,7 @@
import java.util.concurrent.TimeUnit;

/**
* An object which maintains mean and exponentially-weighted rate.
* An object which maintains getMean and exponentially-weighted rate.
*/
public interface Metered extends Metric {
/**
Expand All @@ -25,7 +25,7 @@ public interface Metered extends Metric {
*
* @return the number of events which have been marked
*/
long count();
long getCount();

/**
* Returns the fifteen-minute exponentially-weighted moving average rate at which events have
Expand All @@ -37,7 +37,7 @@ public interface Metered extends Metric {
* @return the fifteen-minute exponentially-weighted moving average rate at which events have
* occurred since the meter was created
*/
double fifteenMinuteRate();
double getFifteenMinuteRate();

/**
* Returns the five-minute exponentially-weighted moving average rate at which events have
Expand All @@ -49,14 +49,14 @@ public interface Metered extends Metric {
* @return the five-minute exponentially-weighted moving average rate at which events have
* occurred since the meter was created
*/
double fiveMinuteRate();
double getFiveMinuteRate();

/**
* Returns the mean rate at which events have occurred since the meter was created.
* Returns the getMean rate at which events have occurred since the meter was created.
*
* @return the mean rate at which events have occurred since the meter was created
* @return the getMean rate at which events have occurred since the meter was created
*/
double meanRate();
double getMeanRate();

/**
* Returns the one-minute exponentially-weighted moving average rate at which events have
Expand All @@ -68,5 +68,5 @@ public interface Metered extends Metric {
* @return the one-minute exponentially-weighted moving average rate at which events have
* occurred since the meter was created
*/
double oneMinuteRate();
double getOneMinuteRate();
}
43 changes: 43 additions & 0 deletions metrics-core/src/main/java/com/yammer/metrics/core/Sampling.java
@@ -1,5 +1,6 @@
package com.yammer.metrics.core;

import com.yammer.metrics.annotation.Publish;
import com.yammer.metrics.stats.Snapshot;

/**
Expand All @@ -12,4 +13,46 @@ public interface Sampling {
* @return a snapshot of the values
*/
Snapshot getSnapshot();

/**
* Returns the median value in the distribution.
*
* @return the median value in the distribution
*/
double getMedian();

/**
* Returns the value at the 75th percentile in the distribution.
*
* @return the value at the 75th percentile in the distribution
*/
double get75thPercentile();

/**
* Returns the value at the 95th percentile in the distribution.
*
* @return the value at the 95th percentile in the distribution
*/
double get95thPercentile();

/**
* Returns the value at the 98th percentile in the distribution.
*
* @return the value at the 98th percentile in the distribution
*/
double get98thPercentile();

/**
* Returns the value at the 99th percentile in the distribution.
*
* @return the value at the 99th percentile in the distribution
*/
double get99thPercentile();

/**
* Returns the value at the 99.9th percentile in the distribution.
*
* @return the value at the 99.9th percentile in the distribution
*/
double get999thPercentile();
}
Expand Up @@ -9,34 +9,34 @@ public interface Summarizable {
*
* @return the largest recorded value
*/
double max();
double getMax();

/**
* Returns the smallest recorded value.
*
* @return the smallest recorded value
*/
double min();
double getMin();

/**
* Returns the arithmetic mean of all recorded values.
* Returns the arithmetic getMean of all recorded values.
*
* @return the arithmetic mean of all recorded values
* @return the arithmetic getMean of all recorded values
*/
double mean();
double getMean();

/**
* Returns the standard deviation of all recorded values.
*
* @return the standard deviation of all recorded values
*/
double stdDev();
double getStdDev();

/**
* Returns the sum of all recorded values.
* Returns the getSum of all recorded values.
*
* @return the sum of all recorded values
* @return the getSum of all recorded values
*/
double sum();
double getSum();

}

0 comments on commit fe9b883

Please sign in to comment.