title: Monitoring the size of the Netty event loop queues
body: <p>We've implemented monitoring for the Netty event loop queues in order to understand issues with some of our Netty modules.
  The monitor uses the <code>io.netty.util.concurrent.SingleThreadEventExecutor#pendingTasks</code> method, which works for most modules, but for a module that handle a few thousand HTTP requests per second it seem to be hung, or very slow.
  I now realize that the docs strictly specify this can be an issue, and I feel pretty lame... so I'm looking for another way to implement this monitor.</p>
  
  <p>You can see the old code here:
  <a href="https://github.com/outbrain/ob1k/blob/6364187b30cab5b79d64835131d9168c754f3c09/ob1k-core/src/main/java/com/outbrain/ob1k/common/metrics/NettyQueuesGaugeBuilder.java">https://github.com/outbrain/ob1k/blob/6364187b30cab5b79d64835131d9168c754f3c09/ob1k-core/src/main/java/com/outbrain/ob1k/common/metrics/NettyQueuesGaugeBuilder.java</a></p>
  
  <pre><code>  public static void registerQueueGauges(final MetricFactory factory, final EventLoopGroup elg, final String componentName) {
  
      int index = 0;
      for (final EventExecutor eventExecutor : elg) {
        if (eventExecutor instanceof SingleThreadEventExecutor) {
          final SingleThreadEventExecutor singleExecutor = (SingleThreadEventExecutor) eventExecutor;
          factory.registerGauge("EventLoopGroup-" + componentName, "EventLoop-" + index, new Gauge&lt;Integer&gt;() {
            @Override
            public Integer getValue() {
              return singleExecutor.pendingTasks();
            }
          });
  
          index++;
        }
      }
    }
  </code></pre>
  
  <p><strong>My question is</strong>, is there a better way to monitor the queue sizes?</p>
  
  <p>This can be quite a useful metric, as it can be used to understand latency, and also to be used for applying back-pressure in some cases.</p>