Overriden the Metric data collection
Three of the Metric in the yammer library are based on data that is pushed to them: Counter, Histogram and Meter. This patch modify the specific functionality by inherit the original Meter, keeping its functionality and API, and modify the way the data is collected. For Counter: A call to count will be implementing by calling the API to retreive a value. For Meter: A call to count will be implementing by calling the API to retreive a value, similiar to count, but the timer aspect of the Meter remains the same. For histogram: Histogram uses an internal sample container. To mimic the behaviour, a call to any of the historgram get functionality will update the sample container first. A timestamp of the last update limits the number of updates that will be done by the histogram. Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
This commit is contained in:
parent
5eba35e439
commit
dd2d50a45c
29
src/main/java/com/yammer/metrics/core/APICounter.java
Normal file
29
src/main/java/com/yammer/metrics/core/APICounter.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
package com.yammer.metrics.core;
|
||||
/*
|
||||
* Copyright 2015 Cloudius Systems
|
||||
*
|
||||
* Modified by Cloudius Systems
|
||||
*/
|
||||
|
||||
import com.cloudius.urchin.api.APIClient;
|
||||
import com.yammer.metrics.core.Counter;
|
||||
|
||||
public class APICounter extends Counter {
|
||||
String url;
|
||||
private APIClient c = new APIClient();
|
||||
|
||||
public APICounter(String _url) {
|
||||
super();
|
||||
url = _url;
|
||||
}
|
||||
/**
|
||||
* Returns the counter's current value.
|
||||
*
|
||||
* @return the counter's current value
|
||||
*/
|
||||
public long count() {
|
||||
return c.getLongValue(url);
|
||||
}
|
||||
|
||||
|
||||
}
|
112
src/main/java/com/yammer/metrics/core/APIHistogram.java
Normal file
112
src/main/java/com/yammer/metrics/core/APIHistogram.java
Normal file
|
@ -0,0 +1,112 @@
|
|||
package com.yammer.metrics.core;
|
||||
|
||||
/*
|
||||
* Copyright 2015 Cloudius Systems
|
||||
*
|
||||
* Modified by Cloudius Systems
|
||||
*/
|
||||
|
||||
import com.cloudius.urchin.api.APIClient;
|
||||
import com.yammer.metrics.stats.Sample;
|
||||
import com.yammer.metrics.stats.Snapshot;
|
||||
|
||||
public class APIHistogram extends Histogram {
|
||||
long last_update = 0;
|
||||
static final long UPDATE_INTERVAL = 50;
|
||||
String url;
|
||||
private APIClient c = new APIClient();
|
||||
|
||||
public APIHistogram(String _url, Sample sample) {
|
||||
super(sample);
|
||||
url = _url;
|
||||
}
|
||||
|
||||
public APIHistogram(String _url, SampleType type) {
|
||||
super(type);
|
||||
url = _url;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - last_update < UPDATE_INTERVAL) {
|
||||
return;
|
||||
}
|
||||
last_update = now;
|
||||
clear();
|
||||
long[] vals = c.getLongArrValue(url);
|
||||
for (long v : vals) {
|
||||
update(v);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of values recorded.
|
||||
*
|
||||
* @return the number of values recorded
|
||||
*/
|
||||
public long count() {
|
||||
update();
|
||||
return super.count();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.yammer.metrics.core.Summarizable#max()
|
||||
*/
|
||||
@Override
|
||||
public double max() {
|
||||
update();
|
||||
return super.max();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.yammer.metrics.core.Summarizable#min()
|
||||
*/
|
||||
@Override
|
||||
public double min() {
|
||||
update();
|
||||
return super.min();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.yammer.metrics.core.Summarizable#mean()
|
||||
*/
|
||||
@Override
|
||||
public double mean() {
|
||||
update();
|
||||
return super.mean();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.yammer.metrics.core.Summarizable#stdDev()
|
||||
*/
|
||||
@Override
|
||||
public double stdDev() {
|
||||
update();
|
||||
return super.stdDev();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.yammer.metrics.core.Summarizable#sum()
|
||||
*/
|
||||
@Override
|
||||
public double sum() {
|
||||
update();
|
||||
return super.sum();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Snapshot getSnapshot() {
|
||||
update();
|
||||
return super.getSnapshot();
|
||||
}
|
||||
}
|
29
src/main/java/com/yammer/metrics/core/APIMeter.java
Normal file
29
src/main/java/com/yammer/metrics/core/APIMeter.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
package com.yammer.metrics.core;
|
||||
|
||||
/*
|
||||
* Copyright 2015 Cloudius Systems
|
||||
*
|
||||
* Modified by Cloudius Systems
|
||||
*/
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.cloudius.urchin.api.APIClient;
|
||||
|
||||
public class APIMeter extends Meter {
|
||||
String url;
|
||||
private APIClient c = new APIClient();
|
||||
|
||||
public APIMeter(String _url, ScheduledExecutorService tickThread,
|
||||
String eventType, TimeUnit rateUnit, Clock clock) {
|
||||
super(tickThread, eventType, rateUnit, clock);
|
||||
// TODO Auto-generated constructor stub
|
||||
url = _url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count() {
|
||||
return c.getLongValue(url);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user