Contributor
封仲淹(@longdafeng)
陈昱(@cycyyy)
刘键(@bastiliu)
方孝健(@hustfxj)
李鑫(@tumen)
母延年(@muyannian)
周鑫(@@zhouxinxust)
罗实(@luoshi0801)
Getting help
Google Groups: jstorm-user
QQ群:228374502
JStorm is a distributed realtime computation system. It is very similar to Storm, but provide a lot of advanced features, at the same time, it is more stable than Storm.
Chinese Documentation and tutorials can be found on the 中文文档.
English Document and tutorials can be found on the English JStorm Documentation
封仲淹(@longdafeng)
陈昱(@cycyyy)
刘键(@bastiliu)
方孝健(@hustfxj)
李鑫(@tumen)
母延年(@muyannian)
周鑫(@@zhouxinxust)
罗实(@luoshi0801)
Google Groups: jstorm-user
QQ群:228374502
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.alibaba.jstorm.client.metric; | ||
|
||
import com.codahale.metrics.Metric; | ||
|
||
public interface MetricCallback<T extends Metric> { | ||
void callback(T metric); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.alibaba.jstorm.client.metric; | ||
|
||
import backtype.storm.task.TopologyContext; | ||
|
||
import com.alibaba.jstorm.metric.Metrics; | ||
import com.codahale.metrics.Counter; | ||
import com.codahale.metrics.Gauge; | ||
import com.codahale.metrics.Histogram; | ||
import com.codahale.metrics.Meter; | ||
import com.codahale.metrics.Timer; | ||
import com.alibaba.jstorm.metric.JStormTimer; | ||
import com.alibaba.jstorm.metric.JStormHistogram; | ||
|
||
public class MetricClient { | ||
|
||
private final int taskid; | ||
|
||
public MetricClient(TopologyContext context) { | ||
taskid = context.getThisTaskId(); | ||
} | ||
|
||
private String getMetricName(Integer taskid, String name) { | ||
return "task-" + String.valueOf(taskid) + ":" + name; | ||
} | ||
|
||
public Gauge<?> registerGauge(String name, Gauge<?> gauge, MetricCallback<Gauge<?>> callback) { | ||
String userMetricName = getMetricName(taskid, name); | ||
Gauge<?> ret = Metrics.registerGauge(userMetricName, gauge); | ||
Metrics.registerUserDefine(userMetricName, gauge, callback); | ||
return ret; | ||
} | ||
|
||
public Counter registerCounter(String name, MetricCallback<Counter> callback) { | ||
String userMetricName = getMetricName(taskid, name); | ||
Counter ret = Metrics.registerCounter(userMetricName); | ||
Metrics.registerUserDefine(userMetricName, ret, callback); | ||
return ret; | ||
} | ||
|
||
public Meter registerMeter(String name, MetricCallback<Meter> callback) { | ||
String userMetricName = getMetricName(taskid, name); | ||
Meter ret = Metrics.registerMeter(userMetricName); | ||
Metrics.registerUserDefine(userMetricName, ret, callback); | ||
return ret; | ||
} | ||
|
||
public JStormTimer registerTimer(String name, MetricCallback<Timer> callback) { | ||
String userMetricName = getMetricName(taskid, name); | ||
JStormTimer ret = Metrics.registerTimer(userMetricName); | ||
Metrics.registerUserDefine(userMetricName, ret, callback); | ||
return ret; | ||
} | ||
|
||
public JStormHistogram registerHistogram(String name, MetricCallback<Histogram> callback) { | ||
String userMetricName = getMetricName(taskid, name); | ||
JStormHistogram ret = Metrics.registerHistograms(userMetricName); | ||
Metrics.registerUserDefine(userMetricName, ret, callback); | ||
return ret; | ||
} | ||
|
||
public boolean unregister(String name, Integer taskid) { | ||
String userMetricName = getMetricName(taskid, name); | ||
return Metrics.unregisterUserDefine(userMetricName); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,39 @@ | ||
package com.alibaba.jstorm.daemon.worker.metrics; | ||
|
||
import com.codahale.metrics.Histogram; | ||
|
||
public class JStormHistogram { | ||
private static boolean isEnable = true; | ||
|
||
public static boolean isEnable() { | ||
return isEnable; | ||
} | ||
|
||
public static void setEnable(boolean isEnable) { | ||
JStormHistogram.isEnable = isEnable; | ||
} | ||
|
||
private Histogram instance; | ||
private String name; | ||
|
||
public JStormHistogram(String name, Histogram instance) { | ||
this.name = name; | ||
this.instance = instance; | ||
} | ||
|
||
public void update(int value) { | ||
if (isEnable == true) { | ||
instance.update(value); | ||
} | ||
} | ||
|
||
public void update(long value) { | ||
if (isEnable == true) { | ||
instance.update(value); | ||
} | ||
} | ||
} | ||
package com.alibaba.jstorm.metric; | ||
|
||
import com.codahale.metrics.Histogram; | ||
|
||
public class JStormHistogram { | ||
private static boolean isEnable = true; | ||
|
||
public static boolean isEnable() { | ||
return isEnable; | ||
} | ||
|
||
public static void setEnable(boolean isEnable) { | ||
JStormHistogram.isEnable = isEnable; | ||
} | ||
|
||
private Histogram instance; | ||
private String name; | ||
|
||
public JStormHistogram(String name, Histogram instance) { | ||
this.name = name; | ||
this.instance = instance; | ||
} | ||
|
||
public void update(int value) { | ||
if (isEnable == true) { | ||
instance.update(value); | ||
} | ||
} | ||
|
||
public void update(long value) { | ||
if (isEnable == true) { | ||
instance.update(value); | ||
} | ||
} | ||
|
||
public Histogram getInstance() { | ||
return instance; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,64 @@ | ||
package com.alibaba.jstorm.daemon.worker.metrics; | ||
|
||
|
||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import org.apache.log4j.Logger; | ||
|
||
import com.codahale.metrics.Timer; | ||
|
||
public class JStormTimer { | ||
private static final Logger LOG = Logger.getLogger(JStormTimer.class); | ||
private static boolean isEnable = true; | ||
|
||
public static boolean isEnable() { | ||
return isEnable; | ||
} | ||
|
||
public static void setEnable(boolean isEnable) { | ||
JStormTimer.isEnable = isEnable; | ||
} | ||
|
||
|
||
private Timer instance; | ||
private String name; | ||
public JStormTimer(String name, Timer instance) { | ||
this.name = name; | ||
this.instance = instance; | ||
this.timerContext = new AtomicReference<Timer.Context>(); | ||
} | ||
|
||
/** | ||
* This logic isn't perfect, it will miss metrics when it is called | ||
* in the same time. But this method performance is better than | ||
* create a new instance wrapper Timer.Context | ||
*/ | ||
private AtomicReference<Timer.Context> timerContext = null; | ||
public void start() { | ||
if (JStormTimer.isEnable == false) { | ||
return ; | ||
} | ||
|
||
if (timerContext.get() != null) { | ||
LOG.warn("Already start timer " + name); | ||
return ; | ||
} | ||
|
||
|
||
timerContext.set(instance.time()); | ||
|
||
} | ||
|
||
public void stop() { | ||
Timer.Context context = timerContext.getAndSet(null); | ||
if (context != null) { | ||
context.stop(); | ||
} | ||
} | ||
|
||
public Timer getInstance() { | ||
return instance; | ||
} | ||
|
||
|
||
} | ||
package com.alibaba.jstorm.metric; | ||
|
||
|
||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import org.apache.log4j.Logger; | ||
|
||
import com.codahale.metrics.Timer; | ||
|
||
public class JStormTimer { | ||
private static final Logger LOG = Logger.getLogger(JStormTimer.class); | ||
private static boolean isEnable = true; | ||
|
||
public static boolean isEnable() { | ||
return isEnable; | ||
} | ||
|
||
public static void setEnable(boolean isEnable) { | ||
JStormTimer.isEnable = isEnable; | ||
} | ||
|
||
|
||
private Timer instance; | ||
private String name; | ||
public JStormTimer(String name, Timer instance) { | ||
this.name = name; | ||
this.instance = instance; | ||
this.timerContext = new AtomicReference<Timer.Context>(); | ||
} | ||
|
||
/** | ||
* This logic isn't perfect, it will miss metrics when it is called | ||
* in the same time. But this method performance is better than | ||
* create a new instance wrapper Timer.Context | ||
*/ | ||
private AtomicReference<Timer.Context> timerContext = null; | ||
public void start() { | ||
if (JStormTimer.isEnable == false) { | ||
return ; | ||
} | ||
|
||
if (timerContext.get() != null) { | ||
LOG.warn("Already start timer " + name); | ||
return ; | ||
} | ||
|
||
|
||
timerContext.set(instance.time()); | ||
|
||
} | ||
|
||
public void stop() { | ||
Timer.Context context = timerContext.getAndSet(null); | ||
if (context != null) { | ||
context.stop(); | ||
} | ||
} | ||
|
||
public Timer getInstance() { | ||
return instance; | ||
} | ||
|
||
|
||
} |