Search in sources :

Example 1 with AsmGauge

use of com.alibaba.jstorm.common.metric.AsmGauge in project jstorm by alibaba.

the class NettyClient method registerMetrics.

public void registerMetrics() {
    if (this.enableNettyMetrics) {
        sendTimer = (AsmHistogram) JStormMetrics.registerNettyMetric(MetricUtils.nettyMetricName(AsmMetric.mkName(MetricDef.NETTY_CLI_SEND_TIME, nettyConnection), MetricType.HISTOGRAM), new AsmHistogram());
        sendSpeed = (AsmMeter) JStormMetrics.registerNettyMetric(MetricUtils.nettyMetricName(AsmMetric.mkName(MetricDef.NETTY_CLI_SEND_SPEED, nettyConnection), MetricType.METER), new AsmMeter());
        CacheGaugeHealthCheck cacheGauge = new CacheGaugeHealthCheck(messageBuffer, MetricDef.NETTY_CLI_CACHE_SIZE + ":" + nettyConnection.toString());
        JStormMetrics.registerNettyMetric(MetricUtils.nettyMetricName(AsmMetric.mkName(MetricDef.NETTY_CLI_CACHE_SIZE, nettyConnection), MetricType.GAUGE), new AsmGauge(cacheGauge));
        JStormMetrics.registerNettyMetric(MetricUtils.nettyMetricName(AsmMetric.mkName(MetricDef.NETTY_CLI_SEND_PENDING, nettyConnection), MetricType.GAUGE), new AsmGauge(new com.codahale.metrics.Gauge<Double>() {

            @Override
            public Double getValue() {
                return ((Long) pendings.get()).doubleValue();
            }
        }));
        JStormHealthCheck.registerWorkerHealthCheck(MetricDef.NETTY_CLI_CACHE_SIZE + ":" + nettyConnection.toString(), cacheGauge);
    }
    JStormHealthCheck.registerWorkerHealthCheck(MetricDef.NETTY_CLI_CONNECTION + ":" + nettyConnection.toString(), new HealthCheck() {

        HealthCheck.Result healthy = HealthCheck.Result.healthy();

        HealthCheck.Result unhealthy = HealthCheck.Result.unhealthy("NettyConnection " + nettyConnection.toString() + " is broken.");

        @Override
        protected Result check() throws Exception {
            if (isChannelReady() == null) {
                return unhealthy;
            } else {
                return healthy;
            }
        }
    });
}
Also used : AsmGauge(com.alibaba.jstorm.common.metric.AsmGauge) AtomicLong(java.util.concurrent.atomic.AtomicLong) JStormHealthCheck(com.alibaba.jstorm.metric.JStormHealthCheck) HealthCheck(com.codahale.metrics.health.HealthCheck) AsmHistogram(com.alibaba.jstorm.common.metric.AsmHistogram) AsmMeter(com.alibaba.jstorm.common.metric.AsmMeter) QueueGauge(com.alibaba.jstorm.common.metric.QueueGauge) AsmGauge(com.alibaba.jstorm.common.metric.AsmGauge)

Example 2 with AsmGauge

use of com.alibaba.jstorm.common.metric.AsmGauge in project jstorm by alibaba.

the class Worker method startDispatchThread.

private AsyncLoopThread startDispatchThread() {
    // send tuple directly from netty server
    // send control tuple to dispatch thread
    // startDispatchDisruptor();
    IContext context = workerData.getContext();
    String topologyId = workerData.getTopologyId();
    // create recv connection
    Map stormConf = workerData.getStormConf();
    long timeout = JStormUtils.parseLong(stormConf.get(Config.TOPOLOGY_DISRUPTOR_WAIT_TIMEOUT), 10);
    WaitStrategy waitStrategy = new TimeoutBlockingWaitStrategy(timeout, TimeUnit.MILLISECONDS);
    int queueSize = JStormUtils.parseInt(stormConf.get(Config.TOPOLOGY_CTRL_BUFFER_SIZE), 256);
    DisruptorQueue recvControlQueue = DisruptorQueue.mkInstance("Dispatch-control", ProducerType.MULTI, queueSize, waitStrategy, false, 0, 0);
    // metric for recvControlQueue
    QueueGauge revCtrlGauge = new QueueGauge(recvControlQueue, MetricDef.RECV_CTRL_QUEUE);
    JStormMetrics.registerWorkerMetric(JStormMetrics.workerMetricName(MetricDef.RECV_CTRL_QUEUE, MetricType.GAUGE), new AsmGauge(revCtrlGauge));
    IConnection recvConnection = context.bind(topologyId, workerData.getPort(), workerData.getDeserializeQueues(), recvControlQueue, false, workerData.getTaskIds());
    workerData.setRecvConnection(recvConnection);
    // create recvice control messages's thread
    RunnableCallback recvControlDispather = new VirtualPortCtrlDispatch(workerData, recvConnection, recvControlQueue, MetricDef.RECV_THREAD);
    return new AsyncLoopThread(recvControlDispather, false, Thread.MAX_PRIORITY, true);
}
Also used : IContext(backtype.storm.messaging.IContext) DisruptorQueue(backtype.storm.utils.DisruptorQueue) IConnection(backtype.storm.messaging.IConnection) RunnableCallback(com.alibaba.jstorm.callback.RunnableCallback) QueueGauge(com.alibaba.jstorm.common.metric.QueueGauge) TimeoutBlockingWaitStrategy(com.lmax.disruptor.TimeoutBlockingWaitStrategy) AsyncLoopThread(com.alibaba.jstorm.callback.AsyncLoopThread) AsmGauge(com.alibaba.jstorm.common.metric.AsmGauge) TimeoutBlockingWaitStrategy(com.lmax.disruptor.TimeoutBlockingWaitStrategy) WaitStrategy(com.lmax.disruptor.WaitStrategy)

Example 3 with AsmGauge

use of com.alibaba.jstorm.common.metric.AsmGauge in project jstorm by alibaba.

the class SupervisorManger method registerSupervisorMetrics.

private void registerSupervisorMetrics() {
    JStormMetrics.registerWorkerMetric(JStormMetrics.workerMetricName(MetricDef.CPU_USED_RATIO, MetricType.GAUGE), new AsmGauge(new Gauge<Double>() {

        @Override
        public Double getValue() {
            return JStormUtils.getTotalCpuUsage();
        }
    }));
    String duHome = ConfigExtension.getDuHome(conf);
    if (duHome != null) {
        LinuxResource.setDuHome(duHome);
    }
    JStormMetrics.registerWorkerMetric(JStormMetrics.workerMetricName(MetricDef.DISK_USAGE, MetricType.GAUGE), new AsmGauge(new Gauge<Double>() {

        @Override
        public Double getValue() {
            return JStormUtils.getDiskUsage();
        }
    }));
    JStormMetrics.registerWorkerMetric(JStormMetrics.workerMetricName(MetricDef.MEMORY_USAGE, MetricType.GAUGE), new AsmGauge(new Gauge<Double>() {

        @Override
        public Double getValue() {
            return JStormUtils.getTotalMemUsage();
        }
    }));
    JStormMetrics.registerWorkerMetric(JStormMetrics.workerMetricName(MetricDef.NETRECVSPEED, MetricType.GAUGE), new AsmGauge(new Gauge<Double>() {

        Long lastRecvCount = LinuxResource.getNetRevSendCount().getFirst();

        Long lastCalTime = System.currentTimeMillis();

        @Override
        public Double getValue() {
            Long nowRecvCount = LinuxResource.getNetRevSendCount().getFirst();
            Long nowCalTime = System.currentTimeMillis();
            long deltaValue = nowRecvCount - lastRecvCount;
            long deltaTime = nowCalTime - lastCalTime;
            lastRecvCount = nowRecvCount;
            lastCalTime = nowCalTime;
            double ret = 0.0;
            if (deltaTime > 0) {
                ret = deltaValue / (double) deltaTime * 1000d;
            }
            return ret;
        }
    }));
    JStormMetrics.registerWorkerMetric(JStormMetrics.workerMetricName(MetricDef.NETSENDSPEED, MetricType.GAUGE), new AsmGauge(new Gauge<Double>() {

        Long lastSendCount = LinuxResource.getNetRevSendCount().getSecond();

        Long lastCalTime = System.currentTimeMillis();

        @Override
        public Double getValue() {
            Long nowSendCount = LinuxResource.getNetRevSendCount().getSecond();
            Long nowCalTime = System.currentTimeMillis();
            long deltaValue = nowSendCount - lastSendCount;
            long deltaTime = nowCalTime - lastCalTime;
            lastSendCount = nowSendCount;
            lastCalTime = nowCalTime;
            double ret = 0.0;
            if (deltaTime > 0) {
                ret = deltaValue / (double) deltaTime * 1000d;
            }
            return ret;
        }
    }));
}
Also used : AsmGauge(com.alibaba.jstorm.common.metric.AsmGauge) AsmGauge(com.alibaba.jstorm.common.metric.AsmGauge) Gauge(com.codahale.metrics.Gauge)

Aggregations

AsmGauge (com.alibaba.jstorm.common.metric.AsmGauge)3 QueueGauge (com.alibaba.jstorm.common.metric.QueueGauge)2 IConnection (backtype.storm.messaging.IConnection)1 IContext (backtype.storm.messaging.IContext)1 DisruptorQueue (backtype.storm.utils.DisruptorQueue)1 AsyncLoopThread (com.alibaba.jstorm.callback.AsyncLoopThread)1 RunnableCallback (com.alibaba.jstorm.callback.RunnableCallback)1 AsmHistogram (com.alibaba.jstorm.common.metric.AsmHistogram)1 AsmMeter (com.alibaba.jstorm.common.metric.AsmMeter)1 JStormHealthCheck (com.alibaba.jstorm.metric.JStormHealthCheck)1 Gauge (com.codahale.metrics.Gauge)1 HealthCheck (com.codahale.metrics.health.HealthCheck)1 TimeoutBlockingWaitStrategy (com.lmax.disruptor.TimeoutBlockingWaitStrategy)1 WaitStrategy (com.lmax.disruptor.WaitStrategy)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1