• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java IMetric类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中backtype.storm.metric.api.IMetric的典型用法代码示例。如果您正苦于以下问题:Java IMetric类的具体用法?Java IMetric怎么用?Java IMetric使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IMetric类属于backtype.storm.metric.api包,在下文中一共展示了IMetric类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:24,代码来源:TopologyContext.java


示例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;
}
 
开发者ID:metamx,项目名称:incubator-storm,代码行数:26,代码来源:TopologyContext.java


示例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;
}
 
开发者ID:alibaba,项目名称:jstorm,代码行数:23,代码来源:TopologyContext.java


示例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);
    }       
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:28,代码来源:ShellBolt.java


示例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;
}
 
开发者ID:zaizi,项目名称:alfresco-apache-storm-demo,代码行数:14,代码来源:TestUtil.java


示例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);
    }
}
 
开发者ID:kkllwww007,项目名称:jstrom,代码行数:28,代码来源:ShellBolt.java


示例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;
}
 
开发者ID:greeenSY,项目名称:Tstream,代码行数:29,代码来源:TopologyContext.java


示例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;
}
 
开发者ID:alibaba,项目名称:jstorm,代码行数:40,代码来源:TopologyContext.java


示例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);
    }
}
 
开发者ID:uzh,项目名称:storm-scheduler,代码行数:44,代码来源:SchedulingMetricsCollectionHook.java


示例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);
   }
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:5,代码来源:TridentOperationContext.java


示例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);
	}
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:65,代码来源:SystemBolt.java


示例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;
}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:43,代码来源:TopologyContext.java


示例13: registerMetric

import backtype.storm.metric.api.IMetric; //导入依赖的package包/类
<T extends IMetric> T registerMetric(String name, T metric,
int timeBucketSizeInSecs);
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:3,代码来源:IMetricsContext.java


示例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);
}
 
开发者ID:songtk,项目名称:learn_jstorm,代码行数:4,代码来源:TridentOperationContext.java


示例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);
	}
}
 
开发者ID:songtk,项目名称:learn_jstorm,代码行数:63,代码来源:SystemBolt.java


示例16: 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.");
       }

       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;
}
 
开发者ID:songtk,项目名称:learn_jstorm,代码行数:42,代码来源:TopologyContext.java


示例17: 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);
    }
}
 
开发者ID:kkllwww007,项目名称:jstrom,代码行数:56,代码来源:SystemBolt.java


示例18: registerMetric

import backtype.storm.metric.api.IMetric; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T extends IMetric> T registerMetric(String name, T metric, int timeBucketSizeInSecs) {
  MetricDelegate d = new MetricDelegate(metric);
  delegate.registerMetric(name, d, timeBucketSizeInSecs);
  return metric;
}
 
开发者ID:twitter,项目名称:heron,代码行数:7,代码来源:TopologyContext.java


示例19: 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);
    }
}
 
开发者ID:metamx,项目名称:incubator-storm,代码行数:55,代码来源:SystemBolt.java


示例20: 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);
    }
}
 
开发者ID:troyding,项目名称:storm-resa,代码行数:55,代码来源:SystemBolt.java



注:本文中的backtype.storm.metric.api.IMetric类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Path类代码示例发布时间:2022-05-21
下一篇:
Java PlanarImage类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap