APIMeter: Move out of pull mode
This replaces the APIMeter implementation so it will not pull the API regularly. To by complient with the yammer object registration mechanism, it still inherit from Meter, but all the functionalities are overriden. Now all the data is taken from the API including the rate statistics. Signed-off-by: Amnon Heiman <amnon@scylladb.com>
This commit is contained in:
parent
adf466519f
commit
4d1f8ed7c9
@ -1,34 +1,113 @@
|
|||||||
package com.yammer.metrics.core;
|
package com.yammer.metrics.core;
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 ScyllaDB
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2015 Cloudius Systems
|
* This file is part of Scylla.
|
||||||
*
|
*
|
||||||
* Modified by Cloudius Systems
|
* Scylla is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Scylla is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Modified by ScyllaDB
|
||||||
*/
|
*/
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import javax.json.JsonArray;
|
||||||
|
import javax.json.JsonObject;
|
||||||
|
|
||||||
import com.scylladb.jmx.api.APIClient;
|
import com.scylladb.jmx.api.APIClient;
|
||||||
|
|
||||||
public class APIMeter extends APISettableMeter {
|
public class APIMeter extends Meter {
|
||||||
String url;
|
public final static long CACHE_DURATION = 1000;
|
||||||
private APIClient c = new APIClient();
|
|
||||||
|
|
||||||
public APIMeter(String _url, ScheduledExecutorService tickThread,
|
String url;
|
||||||
String eventType, TimeUnit rateUnit, Clock clock) {
|
String eventType;
|
||||||
super(tickThread, eventType, rateUnit, clock);
|
TimeUnit rateUnit;
|
||||||
// TODO Auto-generated constructor stub
|
APIClient c = new APIClient();
|
||||||
url = _url;
|
long count;
|
||||||
|
double oneMinuteRate;
|
||||||
|
double fiveMinuteRate;
|
||||||
|
double fifteenMinuteRate;
|
||||||
|
double meanRate;
|
||||||
|
|
||||||
|
public APIMeter(String url, ScheduledExecutorService tickThread,
|
||||||
|
String eventType, TimeUnit rateUnit) {
|
||||||
|
super(tickThread, eventType, rateUnit, Clock.defaultClock());
|
||||||
|
super.stop();
|
||||||
|
this.url = url;
|
||||||
|
this.eventType = eventType;
|
||||||
|
this.rateUnit = rateUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long get_value() {
|
public void fromJson(JsonObject obj) {
|
||||||
return c.getLongValue(url);
|
JsonArray rates = obj.getJsonArray("rates");
|
||||||
|
int i = 0;
|
||||||
|
oneMinuteRate = rates.getJsonNumber(i++).doubleValue();
|
||||||
|
fiveMinuteRate = rates.getJsonNumber(i++).doubleValue();
|
||||||
|
fifteenMinuteRate = rates.getJsonNumber(i++).doubleValue();
|
||||||
|
meanRate = obj.getJsonNumber("mean_rate").doubleValue();
|
||||||
|
count = obj.getJsonNumber("count").longValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update_fields() {
|
||||||
|
if (url != null) {
|
||||||
|
fromJson(c.getJsonObj(url, null, CACHE_DURATION));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public TimeUnit rateUnit() {
|
||||||
set(get_value());
|
return rateUnit;
|
||||||
super.tick();
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String eventType() {
|
||||||
|
return eventType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long count() {
|
||||||
|
update_fields();
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double fifteenMinuteRate() {
|
||||||
|
update_fields();
|
||||||
|
return fifteenMinuteRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double fiveMinuteRate() {
|
||||||
|
update_fields();
|
||||||
|
return fiveMinuteRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double meanRate() {
|
||||||
|
update_fields();
|
||||||
|
return meanRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double oneMinuteRate() {
|
||||||
|
update_fields();
|
||||||
|
return oneMinuteRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user