本文整理汇总了Java中backtype.storm.metric.api.IMetric类的典型用法代码示例。如果您正苦于以下问题:Java IMetric类的具体用法?Java IMetric怎么用?Java IMetric使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IMetric类属于backtype.storm.metric.api包,在下文中一共展示了IMetric类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRegisteredMetricByName
import backtype.storm.metric.api.IMetric; //导入依赖的package包/类
/**
* Get component's metric from registered metrics by name.
* Notice: Normally, one component can only register one metric name once.
* But now registerMetric has a bug(https://issues.apache.org/jira/browse/STORM-254)
* cause the same metric name can register twice.
* So we just return the first metric we meet.
*/
public IMetric getRegisteredMetricByName(String name) {
IMetric metric = null;
for (Map<Integer, Map<String, IMetric>> taskIdToNameToMetric: _registeredMetrics.values()) {
Map<String, IMetric> nameToMetric = taskIdToNameToMetric.get(_taskId);
if (nameToMetric != null) {
metric = nameToMetric.get(name);
if (metric != null) {
//we just return the first metric we meet
break;
}
}
}
return metric;
}
示例2: registerMetric
import backtype.storm.metric.api.IMetric; //导入依赖的package包/类
public <T extends IMetric> T registerMetric(String name, T metric, int timeBucketSizeInSecs) {
if((Boolean)_openOrPrepareWasCalled.deref() == true) {
throw new RuntimeException("TopologyContext.registerMetric can only be called from within overridden " +
"IBolt::prepare() or ISpout::open() method.");
}
Map m1 = _registeredMetrics;
if(!m1.containsKey(timeBucketSizeInSecs)) {
m1.put(timeBucketSizeInSecs, new HashMap());
}
Map m2 = (Map)m1.get(timeBucketSizeInSecs);
if(!m2.containsKey(_taskId)) {
m2.put(_taskId, new HashMap());
}
Map m3 = (Map)m2.get(_taskId);
if(m3.containsKey(name)) {
throw new RuntimeException("The same metric name `" + name + "` was registered twice." );
} else {
m3.put(name, metric);
}
return metric;
}
示例3: getRegisteredMetricByName
import backtype.storm.metric.api.IMetric; //导入依赖的package包/类
/**
* Get component's metric from registered metrics by name. Notice: Normally,
* one component can only register one metric name once. But now registerMetric
* has a bug(https://issues.apache.org/jira/browse/STORM-254) cause the same metric name can register twice.
* So we just return the first metric we meet.
*/
public IMetric getRegisteredMetricByName(String name) {
IMetric metric = null;
for (Map<Integer, Map<String, IMetric>> taskIdToNameToMetric : _registeredMetrics.values()) {
Map<String, IMetric> nameToMetric = taskIdToNameToMetric.get(_taskId);
if (nameToMetric != null) {
metric = nameToMetric.get(name);
if (metric != null) {
// we just return the first metric we meet
break;
}
}
}
return metric;
}
示例4: handleMetrics
import backtype.storm.metric.api.IMetric; //导入依赖的package包/类
private void handleMetrics(ShellMsg shellMsg) {
//get metric name
String name = shellMsg.getMetricName();
if (name.isEmpty()) {
throw new RuntimeException("Receive Metrics name is empty");
}
//get metric by name
IMetric iMetric = _context.getRegisteredMetricByName(name);
if (iMetric == null) {
throw new RuntimeException("Could not find metric by name["+name+"] ");
}
if ( !(iMetric instanceof IShellMetric)) {
throw new RuntimeException("Metric["+name+"] is not IShellMetric, can not call by RPC");
}
IShellMetric iShellMetric = (IShellMetric)iMetric;
//call updateMetricFromRPC with params
Object paramsObj = shellMsg.getMetricParams();
try {
iShellMetric.updateMetricFromRPC(paramsObj);
} catch (RuntimeException re) {
throw re;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例5: getMockedTopologyContext
import backtype.storm.metric.api.IMetric; //导入依赖的package包/类
public static TopologyContext getMockedTopologyContext() {
TopologyContext context = mock(TopologyContext.class);
when(context.registerMetric(anyString(), any(IMetric.class), anyInt()))
.thenAnswer(new Answer<IMetric>() {
@Override
public IMetric answer(InvocationOnMock invocation)
throws Throwable {
return invocation.getArgumentAt(1, IMetric.class);
}
});
return context;
}
示例6: handleMetrics
import backtype.storm.metric.api.IMetric; //导入依赖的package包/类
private void handleMetrics(ShellMsg shellMsg) {
// get metric name
String name = shellMsg.getMetricName();
if (name.isEmpty()) {
throw new RuntimeException("Receive Metrics name is empty");
}
// get metric by name
IMetric iMetric = _context.getRegisteredMetricByName(name);
if (iMetric == null) {
throw new RuntimeException("Could not find metric by name[" + name + "] ");
}
if (!(iMetric instanceof IShellMetric)) {
throw new RuntimeException("Metric[" + name + "] is not IShellMetric, can not call by RPC");
}
IShellMetric iShellMetric = (IShellMetric) iMetric;
// call updateMetricFromRPC with params
Object paramsObj = shellMsg.getMetricParams();
try {
iShellMetric.updateMetricFromRPC(paramsObj);
} catch (RuntimeException re) {
throw re;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例7: registerMetric
import backtype.storm.metric.api.IMetric; //导入依赖的package包/类
public <T extends IMetric> T registerMetric(String name, T metric,
int timeBucketSizeInSecs) {
if ((Boolean) _openOrPrepareWasCalled.deref() == true) {
throw new RuntimeException(
"TopologyContext.registerMetric can only be called from within overridden "
+ "IBolt::prepare() or ISpout::open() method.");
}
Map m1 = _registeredMetrics;
if (!m1.containsKey(timeBucketSizeInSecs)) {
m1.put(timeBucketSizeInSecs, new HashMap());
}
Map m2 = (Map) m1.get(timeBucketSizeInSecs);
if (!m2.containsKey(_taskId)) {
m2.put(_taskId, new HashMap());
}
Map m3 = (Map) m2.get(_taskId);
if (m3.containsKey(name)) {
throw new RuntimeException("The same metric name `" + name
+ "` was registered twice.");
} else {
m3.put(name, metric);
}
return metric;
}
示例8: registerMetric
import backtype.storm.metric.api.IMetric; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T extends IMetric> T registerMetric(String name, T metric, int timeBucketSizeInSecs) {
if ((Boolean) _openOrPrepareWasCalled.deref()) {
throw new RuntimeException("TopologyContext.registerMetric can only be called from within overridden "
+ "IBolt::prepare() or ISpout::open() method.");
}
if (metric == null) {
throw new IllegalArgumentException("Cannot register a null metric");
}
if (timeBucketSizeInSecs <= 0) {
throw new IllegalArgumentException("TopologyContext.registerMetric can only be called with timeBucketSizeInSecs "
+ "greater than or equal to 1 second.");
}
if (getRegisteredMetricByName(name) != null) {
throw new RuntimeException("The same metric name `" + name + "` was registered twice.");
}
Map m1 = _registeredMetrics;
if (!m1.containsKey(timeBucketSizeInSecs)) {
m1.put(timeBucketSizeInSecs, new HashMap());
}
Map m2 = (Map) m1.get(timeBucketSizeInSecs);
if (!m2.containsKey(_taskId)) {
m2.put(_taskId, new HashMap());
}
Map m3 = (Map) m2.get(_taskId);
if (m3.containsKey(name)) {
throw new RuntimeException("The same metric name `" + name + "` was registered twice.");
} else {
m3.put(name, metric);
}
return metric;
}
示例9: prepare
import backtype.storm.metric.api.IMetric; //导入依赖的package包/类
@Override
public void prepare(Map conf, final TopologyContext context) {
if (context.getThisTaskId() < 0) {
LOG.debug("Skipping installation of metrics hook for negative task id {}", context.getThisTaskId());
} else {
int intervalSecs;
LOG.info("Initializing metrics hook for task {}", context.getThisTaskId());
this.sendgraphRef = new AtomicReference<>();
intervalSecs = getConfiguredSchedulingIntervalSecs(conf);
/*
* We register one metric for each task. The full send graph will then be built up in the metric
* consumer.
*/
context.registerMetric(METRIC_EMITTED_MESSAGES, new IMetric() {
@Override
public Object getValueAndReset() {
Map<Integer, AtomicLong> currentValue;
// don't reset sendgraph! todo: make this configurable
// currentValue = SchedulingMetricsCollectionHook.this.sendgraphRef.getAndSet(createEmptySendgraphMap());
currentValue = SchedulingMetricsCollectionHook.this.sendgraphRef.get();
LOG.trace("Reset values for task {} and returning: {}", context.getThisTaskId(), currentValue.toString());
return currentValue;
}
}, intervalSecs); // call every n seconds
// put an empty send graph object.
this.sendgraphRef.compareAndSet(null, createEmptySendgraphMap());
// put a zero weight for the task at hand, so we have a complete send graph in the metrics. Without this
// step, tasks that don't send or receive anything (for example the metrics-consumers) would not be
// contained in the sendgraph. todo: change the schedule format to contain task=>partition assignements, so
// we could do away with this workaround
this.sendgraphRef.get().get(context.getThisTaskId()).set(0);
}
}
示例10: registerMetric
import backtype.storm.metric.api.IMetric; //导入依赖的package包/类
@Override
public <T extends IMetric> T registerMetric(String name, T metric, int timeBucketSizeInSecs) {
return _topoContext.registerMetric(name, metric, timeBucketSizeInSecs);
}
示例11: prepare
import backtype.storm.metric.api.IMetric; //导入依赖的package包/类
@Override
public void prepare(final Map stormConf, TopologyContext context,
OutputCollector collector) {
if (_prepareWasCalled
&& !"local".equals(stormConf.get(Config.STORM_CLUSTER_MODE))) {
throw new RuntimeException(
"A single worker should have 1 SystemBolt instance.");
}
_prepareWasCalled = true;
int bucketSize = RT.intCast(stormConf
.get(Config.TOPOLOGY_BUILTIN_METRICS_BUCKET_SIZE_SECS));
final RuntimeMXBean jvmRT = ManagementFactory.getRuntimeMXBean();
context.registerMetric("uptimeSecs", new IMetric() {
@Override
public Object getValueAndReset() {
return jvmRT.getUptime() / 1000.0;
}
}, bucketSize);
context.registerMetric("startTimeSecs", new IMetric() {
@Override
public Object getValueAndReset() {
return jvmRT.getStartTime() / 1000.0;
}
}, bucketSize);
context.registerMetric("newWorkerEvent", new IMetric() {
boolean doEvent = true;
@Override
public Object getValueAndReset() {
if (doEvent) {
doEvent = false;
return 1;
} else
return 0;
}
}, bucketSize);
final MemoryMXBean jvmMemRT = ManagementFactory.getMemoryMXBean();
context.registerMetric("memory/heap", new MemoryUsageMetric(new AFn() {
@Override
public Object invoke() {
return jvmMemRT.getHeapMemoryUsage();
}
}), bucketSize);
context.registerMetric("memory/nonHeap", new MemoryUsageMetric(
new AFn() {
@Override
public Object invoke() {
return jvmMemRT.getNonHeapMemoryUsage();
}
}), bucketSize);
for (GarbageCollectorMXBean b : ManagementFactory
.getGarbageCollectorMXBeans()) {
context.registerMetric("GC/" + b.getName().replaceAll("\\W", ""),
new GarbageCollectorMetric(b), bucketSize);
}
}
示例12: registerMetric
import backtype.storm.metric.api.IMetric; //导入依赖的package包/类
@Override
public <T extends IMetric> T registerMetric(String name, T metric,
int timeBucketSizeInSecs) {
if ((Boolean) _openOrPrepareWasCalled.deref() == true) {
throw new RuntimeException(
"TopologyContext.registerMetric can only be called from within overridden "
+ "IBolt::prepare() or ISpout::open() method.");
}
if (metric == null) {
throw new IllegalArgumentException("Cannot register a null metric");
}
if (timeBucketSizeInSecs <= 0) {
throw new IllegalArgumentException("TopologyContext.registerMetric can only be called with timeBucketSizeInSecs " +
"greater than or equal to 1 second.");
}
if (getRegisteredMetricByName(name) != null) {
throw new RuntimeException("The same metric name `" + name + "` was registered twice." );
}
Map m1 = _registeredMetrics;
if (!m1.containsKey(timeBucketSizeInSecs)) {
m1.put(timeBucketSizeInSecs, new HashMap());
}
Map m2 = (Map) m1.get(timeBucketSizeInSecs);
if (!m2.containsKey(_taskId)) {
m2.put(_taskId, new HashMap());
}
Map m3 = (Map) m2.get(_taskId);
if (m3.containsKey(name)) {
throw new RuntimeException("The same metric name `" + name
+ "` was registered twice.");
} else {
m3.put(name, metric);
}
return metric;
}
示例13: registerMetric
import backtype.storm.metric.api.IMetric; //导入依赖的package包/类
<T extends IMetric> T registerMetric(String name, T metric,
int timeBucketSizeInSecs);
示例14: registerMetric
import backtype.storm.metric.api.IMetric; //导入依赖的package包/类
public <T extends IMetric> T registerMetric(String name, T metric, int timeBucketSizeInSecs) {
return _topoContext.registerMetric(name, metric, timeBucketSizeInSecs);
}
示例15: prepare
import backtype.storm.metric.api.IMetric; //导入依赖的package包/类
@Override
public void prepare(final Map stormConf, TopologyContext context,
OutputCollector collector) {
if (_prepareWasCalled
&& !"local".equals(stormConf.get(Config.STORM_CLUSTER_MODE))) {
throw new RuntimeException(
"A single worker should have 1 SystemBolt instance.");
}
_prepareWasCalled = true;
int bucketSize = RT.intCast(stormConf
.get(Config.TOPOLOGY_BUILTIN_METRICS_BUCKET_SIZE_SECS));
final RuntimeMXBean jvmRT = ManagementFactory.getRuntimeMXBean();
context.registerMetric("uptimeSecs", new IMetric() {
@Override
public Object getValueAndReset() {
return jvmRT.getUptime() / 1000.0;
}
}, bucketSize);
context.registerMetric("startTimeSecs", new IMetric() {
@Override
public Object getValueAndReset() {
return jvmRT.getStartTime() / 1000.0;
}
}, bucketSize);
context.registerMetric("newWorkerEvent", new IMetric() {
boolean doEvent = true;
@Override
public Object getValueAndReset() {
if (doEvent) {
doEvent = false;
return 1;
} else
return 0;
}
}, bucketSize);
final MemoryMXBean jvmMemRT = ManagementFactory.getMemoryMXBean();
context.registerMetric("memory/heap", new MemoryUsageMetric(new AFn() {
public Object invoke() {
return jvmMemRT.getHeapMemoryUsage();
}
}), bucketSize);
context.registerMetric("memory/nonHeap", new MemoryUsageMetric(
new AFn() {
public Object invoke() {
return jvmMemRT.getNonHeapMemoryUsage();
}
}), bucketSize);
for (GarbageCollectorMXBean b : ManagementFactory
.getGarbageCollectorMXBeans()) {
context.registerMetric("GC/" + b.getName().replaceAll("\\W", ""),
new GarbageCollectorMetric(b), bucketSize);
}
}