Search in sources :

Example 1 with IMetric

use of backtype.storm.metric.api.IMetric in project jstorm by alibaba.

the class ShellBolt method handleMetrics.

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);
    }
}
Also used : IMetric(backtype.storm.metric.api.IMetric) IShellMetric(backtype.storm.metric.api.rpc.IShellMetric) ReportedFailedException(backtype.storm.topology.ReportedFailedException)

Example 2 with IMetric

use of backtype.storm.metric.api.IMetric in project jstorm by alibaba.

the class SystemBolt method prepare.

@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);
    }
}
Also used : IMetric(backtype.storm.metric.api.IMetric) AFn(clojure.lang.AFn)

Example 3 with IMetric

use of backtype.storm.metric.api.IMetric in project jstorm by alibaba.

the class ShellSpout method handleMetrics.

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);
    }
}
Also used : IMetric(backtype.storm.metric.api.IMetric) IShellMetric(backtype.storm.metric.api.rpc.IShellMetric) IOException(java.io.IOException)

Example 4 with IMetric

use of backtype.storm.metric.api.IMetric in project storm by nathanmarz.

the class SystemBolt method prepare.

@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);
    }
}
Also used : IMetric(backtype.storm.metric.api.IMetric) AFn(clojure.lang.AFn)

Aggregations

IMetric (backtype.storm.metric.api.IMetric)4 IShellMetric (backtype.storm.metric.api.rpc.IShellMetric)2 AFn (clojure.lang.AFn)2 ReportedFailedException (backtype.storm.topology.ReportedFailedException)1 IOException (java.io.IOException)1